diff --git a/sites/all/modules/content_profile/content_profile.module b/sites/all/modules/content_profile/content_profile.module index 48bc9d2..75bd48b 100644 --- a/sites/all/modules/content_profile/content_profile.module +++ b/sites/all/modules/content_profile/content_profile.module @@ -162,6 +162,16 @@ function content_profile_admin_settings(&$form_state, $type) { '#default_value' => content_profile_get_settings($type, 'add_link'), '#description' => t("If selected and the user has no profile of this type yet, a link to add one is shown on the user page."), ); + $form['display']['hide_preview'] = array( + '#type' => 'checkbox', + '#title' => t("Hide the node editor form's Preview button"), + '#default_value' => content_profile_get_settings($type, 'hide_preview'), + ); + $form['display']['hide_delete'] = array( + '#type' => 'checkbox', + '#title' => t("Hide the node editor form's Delete button"), + '#default_value' => content_profile_get_settings($type, 'hide_delete'), + ); $form['display']['edit_tab'] = array( '#type' => 'radios', '#title' => t("Profile edit tab"), @@ -274,9 +284,13 @@ function content_profile_form_alter(&$form, $form_state, $form_id) { elseif (isset($form['#node']) && $form['#node']->type .'_node_form' == $form_id && is_content_profile($form['#node'])) { // Customize the redirect target and buttons of our own node forms. if (arg(0) == 'user' && is_numeric(arg(1)) && arg(2) == 'edit' || arg(2) == 'profile') { - $form['buttons']['preview']['#access'] = FALSE; - $form['buttons']['delete']['#access'] = FALSE; - $form['#redirect'] = arg(2) == 'profile' ? 'user/'. $form['#node']->uid : $_GET['q']; + if (content_profile_get_settings($form['#node']->type, 'hide_preview')) { + $form['buttons']['preview']['#access'] = FALSE; + } + if (content_profile_get_settings($form['#node']->type, 'hide_delete')) { + $form['buttons']['delete']['#access'] = FALSE; + } + $form['buttons']['submit']['#submit'][] = 'content_profile_node_form_submit'; } // Set the author value - note that this works only for admins. if (!empty($_GET['uid']) && ($uid = intval($_GET['uid'])) && ($user = user_load($uid))) { @@ -286,6 +300,13 @@ function content_profile_form_alter(&$form, $form_state, $form_id) { } /** + * Button sumit function: handle the redirect action + */ +function content_profile_node_form_submit($form, &$form_state) { + $form_state['redirect'] = arg(2) == 'profile' ? 'user/'. $form['#node']->uid : $_GET['q']; +} + +/** * Implementation of hook_user(). */ function content_profile_user($op, &$edit, &$account, $category = NULL) { @@ -463,6 +484,8 @@ function content_profile_content_profile_settings() { 'edit_link' => 0, 'edit_tab' => 'sub', 'add_link' => 1, + 'hide_preview' => TRUE, + 'hide_delete' => TRUE, ); }