You are here

jammer.module in Jammer 5

Same filename and directory in other branches
  1. 6 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_help().
 */
function jammer_help($section) {
  switch ($section) {
    case 'admin/settings/jammer':
      return t('By default, no form items are removed until one or more content types are selected to act on.');
  }
}

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

/**
 * Implementation of hook_form_alter().
 */
function jammer_form_alter($form_id, &$form) {
  if ($form['#id'] == 'node-form') {
    if (in_array($form['type']['#value'], variable_get('jammer_revision_log_textarea_unset_node_types', array())) && isset($form['log'])) {
      unset($form['log']);
    }
    if (in_array($form['type']['#value'], variable_get('jammer_preview_button_unset_node_types', array())) && isset($form['preview'])) {
      unset($form['preview']);
    }
    if (in_array($form['type']['#value'], variable_get('jammer_submit_button_unset_node_types', array())) && isset($form['submit'])) {
      unset($form['submit']);
    }
    if (in_array($form['type']['#value'], variable_get('jammer_delete_button_unset_node_types', array())) && isset($form['delete'])) {
      unset($form['delete']);
    }
  }
}
function jammer_admin_settings() {
  $types = node_get_types();
  foreach ($types as $type) {

    // don't bother listing a content type in the configuration list if
    // it doesn't have a corresponding form since modules like usernode
    // sometimes manage nodes automatically in the background
    if (function_exists($type->module . '_form')) {
      $options[$type->type] = $type->name;
    }
  }
  asort($options);
  $form = array();
  $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['buttons'] = array(
    '#type' => 'fieldset',
    '#title' => t('Buttons'),
    '#collapsed' => FALSE,
    '#collapsible' => TRUE,
  );
  $form['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['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['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);
}

/**
 * Implementation of hook_simpletest().
 */
function jammer_simpletest() {

  // Scan through mymodule/tests directory for any .test files to tell SimpleTest module.
  $tests = file_scan_directory(drupal_get_path('module', '') . '/tests', '\\.test');
  return array_keys($tests);
}

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_simpletest Implementation of hook_simpletest().