You are here

function jammer_form_alter in Jammer 7

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

Implements hook_form_alter().

File

./jammer.module, line 100
Modify forms.

Code

function jammer_form_alter(&$form, &$form_state, $form_id) {

  // There is no current version of Workflow for D7.
  //  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 (strpos($form['#id'], 'node-form') !== FALSE) {

    // jammer_publishing_options
    if (variable_get('jammer_node_promoted', 0) == 1) {
      $form['options']['promote']['#access'] = FALSE;
    }
    if (variable_get('jammer_node_sticky', 0) == 1) {
      $form['options']['sticky']['#access'] = FALSE;
    }
    if (isset($form['type']['#value'])) {
      if (in_array($form['type']['#value'], variable_get('jammer_body_options', array())) && !user_access('view body options')) {
        $form['body']['#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['actions']['preview']) && !user_access('view preview button')) {
        $form['actions']['preview']['#access'] = FALSE;
      }
      if (in_array($form['type']['#value'], variable_get('jammer_submit_button_unset_node_types', array())) && isset($form['actions']['submit']) && !user_access('view submit button')) {
        $form['actions']['submit']['#access'] = FALSE;
      }
      if (in_array($form['type']['#value'], variable_get('jammer_delete_button_unset_node_types', array())) && isset($form['actions']['delete']) && !user_access('view delete button')) {
        $form['actions']['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. Else we risk zapping the default value.
      if (in_array($form['type']['#value'], variable_get('jammer_teaser_controls_unset_node_types', array())) && isset($form['body'][LANGUAGE_NONE][0]['summary']) && empty($form['body'][LANGUAGE_NONE][0]['summary']['#default_value']) && !user_access('view teaser controls')) {
        $form['body'][LANGUAGE_NONE][0]['summary']['#access'] = FALSE;
      }
    }
  }
  if (strpos($form_id, 'comment_node_') !== FALSE && !user_access('view comment preview button')) {
    $form['actions']['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['actions']['cancel']['#access'] = FALSE;
    }
  }
}