You are here

jammer.module in Jammer 6

Same filename and directory in other branches
  1. 5 jammer.module
  2. 7 jammer.module
  3. 1.0.x jammer.module

Modify forms.

File

jammer.module
View source
<?php

/**
 * @file
 * Modify forms.
 */

/**
 * Implementation of hook_perm().
 */
function jammer_perm() {
  return array(
    'view body options',
    'view menu options',
    'view author options',
    'view path options',
    'view comment settings',
    'view revision information',
    'view revision log textarea',
    'view teaser controls',
    'view workflow tabs',
    'view user delete button',
    'view preview button',
    'view comment preview button',
    'view submit button',
    'view delete button',
  );
}

/**
 * Implementation of hook_help().
 */
function jammer_help($path, $arg) {
  switch ($path) {
    case 'admin/settings/jammer':
      return t('By default, no form items are removed until one or more content types are selected to act on. If you need to override a Jammed element, to allow a specific user role to view the option, you may do so under user permissions.');
  }
}

/**
 * Implementation of hook_menu().
 */
function jammer_menu() {
  $items['admin/settings/jammer'] = array(
    'title' => 'Jammer',
    'description' => 'Remove items from node editing forms.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'jammer_admin_settings',
    ),
    'access arguments' => array(
      'administer site configuration',
    ),
  );
  return $items;
}

/**
 * Implementation of hook_form_alter().
 */
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;
    }
  }
}
function jammer_admin_settings() {
  $options = array();
  $types = node_get_types();
  foreach ($types as $type) {
    $options[$type->type] = $type->name;
  }
  asort($options);
  array_unshift($options, "none");
  $form = array();

  // Remove the menu settings
  $form['jammer_menu_options'] = array(
    '#type' => 'select',
    '#title' => t('Remove the menu options on content types'),
    '#options' => $options,
    '#size' => count($options) < 6 ? count($options) : 6,
    '#multiple' => TRUE,
    '#default_value' => variable_get('jammer_menu_options', array()),
    '#description' => t('The selected node types will no longer have a menu options listed when creating or editing a node of that type.'),
  );

  // Remove the authoring settings
  $form['jammer_author_options'] = array(
    '#type' => 'select',
    '#title' => t('Remove the author options on content types'),
    '#options' => $options,
    '#size' => count($options) < 6 ? count($options) : 6,
    '#multiple' => TRUE,
    '#default_value' => variable_get('jammer_author_options', array()),
    '#description' => t('The selected node types will no longer have an author details options listed when creating or editing a node of that type.'),
  );

  // Remove the path settings.
  $form['jammer_path_options'] = array(
    '#type' => 'select',
    '#title' => t('Remove the path options on content types'),
    '#options' => $options,
    '#size' => count($options) < 6 ? count($options) : 6,
    '#multiple' => TRUE,
    '#default_value' => variable_get('jammer_path_options', array()),
    '#description' => t('The selected node types will no longer have the url options listed when creating or editing a node of that type.'),
  );

  // Remove the body field.
  $form['jammer_bodyfield_form_unset_node_types'] = array(
    '#type' => 'select',
    '#title' => t('Remove body field on content types'),
    '#options' => $options,
    '#size' => count($options) < 6 ? count($options) : 6,
    '#multiple' => TRUE,
    '#default_value' => variable_get('jammer_bodyfield_form_unset_node_types', array()),
    '#description' => t('The selected node types will no longer have a body field when creating or editing a node of that type.'),
  );

  // Remove the comment settings.
  $form['jammer_comment_settings'] = array(
    '#type' => 'select',
    '#title' => t('Remove the comment options on content types'),
    '#options' => $options,
    '#size' => count($options) < 6 ? count($options) : 6,
    '#multiple' => TRUE,
    '#default_value' => variable_get('jammer_comment_settings', array()),
    '#description' => t('The selected node types will no longer have the comment options listed when creating or editing a node of that type.'),
  );

  // Remove the revision settings.
  $form['jammer_revision_information'] = array(
    '#type' => 'select',
    '#title' => t('Remove the revision options on content types'),
    '#options' => $options,
    '#size' => count($options) < 6 ? count($options) : 6,
    '#multiple' => TRUE,
    '#default_value' => variable_get('jammer_revision_information', array()),
    '#description' => t('The selected node types will no longer have the revision options listed when creating or editing a node of that type.'),
  );

  // Remove teaser controls.
  $form['jammer_teaser_controls_unset_node_types'] = array(
    '#type' => 'select',
    '#title' => t('Remove teaser controls on content types'),
    '#options' => $options,
    '#size' => count($options) < 6 ? count($options) : 6,
    '#multiple' => TRUE,
    '#default_value' => variable_get('jammer_teaser_controls_unset_node_types', array()),
    '#description' => t("The selected node types will no longer have the 'split summary at cursor' and/or 'include summary in full view' controls when creating or editing a node of that type - except for existing nodes that already have 'include summary in full view' turned off."),
  );
  $form['jammer_revision_log_textarea_unset_node_types'] = array(
    '#type' => 'select',
    '#title' => t('Remove revision log textarea on content types'),
    '#options' => $options,
    '#size' => count($options) < 6 ? count($options) : 6,
    '#multiple' => TRUE,
    '#default_value' => variable_get('jammer_revision_log_textarea_unset_node_types', array()),
    '#description' => t('The selected node types will no longer have a log textarea listed when creating or editing a node of that type.'),
  );
  $form['jammer_workflow_form_unset_node_types'] = array(
    '#type' => 'select',
    '#title' => t('Remove workflow form from workflow tab on content types'),
    '#options' => $options,
    '#size' => count($options) < 6 ? count($options) : 6,
    '#multiple' => TRUE,
    '#default_value' => variable_get('jammer_workflow_form_unset_node_types', array()),
    '#description' => t('The selected node types will no longer have a workflow form on the workflow tab which will require workflow transitions to occur from the node edit screen.'),
  );
  $form['user_buttons'] = array(
    '#type' => 'fieldset',
    '#title' => t('User buttons'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $form['user_buttons']['jammer_user_delete_hide_button'] = array(
    '#type' => 'checkbox',
    '#title' => t('Remove delete button on user profile pages'),
    '#description' => t('Selecting this will remove the delete button from all user profile pages'),
    '#default_value' => variable_get('jammer_user_delete_hide_button', 0),
  );
  $form['content_buttons'] = array(
    '#type' => 'fieldset',
    '#title' => t('Content buttons'),
    '#collapsed' => FALSE,
    '#collapsible' => TRUE,
  );
  $form['content_buttons']['jammer_preview_button_unset_node_types'] = array(
    '#type' => 'select',
    '#title' => t('Remove preview button on content types'),
    '#options' => $options,
    '#size' => count($options) < 6 ? count($options) : 6,
    '#multiple' => TRUE,
    '#default_value' => variable_get('jammer_preview_button_unset_node_types', array()),
    '#description' => t('The selected node types will no longer have a preview button listed when creating or editing a node of that type.'),
  );
  $form['content_buttons']['jammer_submit_button_unset_node_types'] = array(
    '#type' => 'select',
    '#title' => t('Remove submit button on content types'),
    '#options' => $options,
    '#size' => count($options) < 6 ? count($options) : 6,
    '#multiple' => TRUE,
    '#default_value' => variable_get('jammer_submit_button_unset_node_types', array()),
    '#description' => t('The selected node types will no longer have a submit button listed when creating or editing a node of that type.'),
  );
  $form['content_buttons']['jammer_delete_button_unset_node_types'] = array(
    '#type' => 'select',
    '#title' => t('Remove delete button on content types'),
    '#options' => $options,
    '#size' => count($options) < 6 ? count($options) : 6,
    '#multiple' => TRUE,
    '#default_value' => variable_get('jammer_delete_button_unset_node_types', array()),
    '#description' => t('The selected node types will no longer have a delete button listed when creating or editing a node of that type.'),
  );
  return system_settings_form($form);
}

Functions

Namesort descending Description
jammer_admin_settings
jammer_form_alter Implementation of hook_form_alter().
jammer_help Implementation of hook_help().
jammer_menu Implementation of hook_menu().
jammer_perm Implementation of hook_perm().