You are here

function jammer_form_alter in Jammer 6

Same name and namespace in other branches
  1. 5 jammer.module \jammer_form_alter()
  2. 7 jammer.module \jammer_form_alter()
  3. 1.0.x jammer.module \jammer_form_alter()

Implementation of hook_form_alter().

File

./jammer.module, line 57
Modify forms.

Code

function jammer_form_alter(&$form, $form_state, $form_id) {
  if ($form['#id'] == 'workflow-tab-form' && !user_access('view workflow tabs')) {
    if (in_array($form['node']['#value']->type, variable_get('jammer_workflow_form_unset_node_types', array()))) {
      $form = array();
      $form['jammer_markup'] = array(
        '#type' => 'markup',
        '#value' => t("In order to change this node's workflow state, please use the Edit tab."),
      );
    }
  }
  if ($form['#id'] == 'node-form') {
    if (in_array($form['type']['#value'], variable_get('jammer_bodyfield_form_unset_node_types', array())) && isset($form['body_field']) && !user_access('view body options')) {
      $form['body_field']['#access'] = FALSE;
    }
    if (in_array($form['type']['#value'], variable_get('jammer_menu_options', array())) && !user_access('view menu options')) {
      $form['menu']['#access'] = FALSE;
    }
    if (in_array($form['type']['#value'], variable_get('jammer_author_options', array())) && !user_access('view author options')) {
      $form['author']['#access'] = FALSE;
    }
    if (in_array($form['type']['#value'], variable_get('jammer_path_options', array())) && !user_access('view path options')) {
      $form['path']['#access'] = FALSE;
    }
    if (in_array($form['type']['#value'], variable_get('jammer_comment_settings', array())) && !user_access('view comment settings')) {
      $form['comment_settings']['#access'] = FALSE;
    }
    if (in_array($form['type']['#value'], variable_get('jammer_revision_information', array())) && !user_access('view revision information')) {
      $form['revision_information']['#access'] = FALSE;
    }
    if (in_array($form['type']['#value'], variable_get('jammer_revision_log_textarea_unset_node_types', array())) && isset($form['revision_information']['log']) && !user_access('view revision log textarea')) {
      $form['revision_information']['log']['#access'] = FALSE;
      if (isset($form['revision_information']['revision']['#access']) && $form['revision_information']['revision']['#access'] == FALSE && !user_access('view revision information')) {
        $form['revision_information']['#access'] = FALSE;
      }
    }
    if (in_array($form['type']['#value'], variable_get('jammer_preview_button_unset_node_types', array())) && isset($form['buttons']['preview']) && !user_access('view preview button')) {
      $form['buttons']['preview']['#access'] = FALSE;
    }
    if (in_array($form['type']['#value'], variable_get('jammer_submit_button_unset_node_types', array())) && isset($form['buttons']['submit']) && !user_access('view submit button')) {
      $form['buttons']['submit']['#access'] = FALSE;
    }
    if (in_array($form['type']['#value'], variable_get('jammer_delete_button_unset_node_types', array())) && isset($form['buttons']['delete']) && !user_access('view delete button')) {
      $form['buttons']['delete']['#access'] = FALSE;
    }

    // We can only safely remove the 'teaser_js' textarea for a separate teaser, and the 'teaser_include' checkbox,
    // IF the teaser is not in fact already different.
    // (i.e. if someone did not turn the 'teaser_include' checkbox off already for an existing node.)
    if (in_array($form['type']['#value'], variable_get('jammer_teaser_controls_unset_node_types', array())) && isset($form['body_field']['teaser_include']) && $form['body_field']['teaser_include']['#default_value'] && !user_access('view teaser controls')) {
      $form['body_field']['teaser_js']['#access'] = FALSE;

      // this will also prevent teaser.js to be loaded (so the 'split summary at cursor' button won't appear)
      $form['body_field']['teaser_include']['#access'] = FALSE;

      // Also remove after_build processing routines - these are actually unset given that the controls to set values to be processed are disabled.
      if (isset($form['body_field']['#after_build']) && is_array($form['body_field']['#after_build'])) {
        $i = count($form['body_field']['#after_build']);
        while ($i > 0) {
          $i--;
          if ($form['body_field']['#after_build'][$i] == 'node_teaser_js' || $form['body_field']['#after_build'][$i] == 'node_teaser_include_verify') {
            unset($form['body_field']['#after_build'][$i]);
          }
        }
        if (count($form['body_field']['#after_build']) == 0) {
          unset($form['body_field']['#after_build']);
        }
      }
    }
  }
  if ($form_id == 'comment_form' && !user_access('view comment preview button')) {
    $form['preview']['#access'] = FALSE;
  }
  if ($form_id == 'user_profile_form' && !user_access('view user delete button')) {
    if (variable_get('jammer_user_delete_hide_button', 0) == 1) {
      $form['delete']['#access'] = FALSE;
    }
  }
}