You are here

function rabbit_hole_form_node_type_form_alter in Rabbit Hole 7

Same name and namespace in other branches
  1. 6 rabbit_hole.module \rabbit_hole_form_node_type_form_alter()

Implements hook_form_FORM_ID_alter().

This will add Rabbit Hole options to the node type form. These settings will be used as default for every node of this node type.

File

./rabbit_hole.module, line 40
Main module file for Rabbit Hole.

Code

function rabbit_hole_form_node_type_form_alter(&$form, $form_state) {
  if (!user_access('administer rabbit hole')) {

    // The user doesn't have access.
    return;
  }
  if (isset($form['type'])) {
    $form['rabbit_hole'] = array(
      '#type' => 'fieldset',
      '#title' => t('Rabbit Hole settings'),
      '#collapsed' => TRUE,
      '#collapsible' => TRUE,
      '#group' => 'additional_settings',
      '#attributes' => array(
        'class' => array(
          'rabbit-hole-settings-form',
        ),
      ),
      '#attached' => array(
        'js' => array(
          drupal_get_path('module', 'rabbit_hole') . '/rabbit-hole.js',
          array(
            'data' => array(
              'rabbitHole' => array(
                'redirectValue' => RABBIT_HOLE_PAGE_REDIRECT,
              ),
            ),
            'type' => 'setting',
          ),
        ),
      ),
    );
    $form['rabbit_hole']['rabbit_hole_action'] = array(
      '#type' => 'radios',
      '#title' => t('Behavior'),
      '#options' => array(
        RABBIT_HOLE_DISPLAY_CONTENT => t('Display the content (regular behavior)'),
        RABBIT_HOLE_ACCESS_DENIED => t('Access denied'),
        RABBIT_HOLE_PAGE_NOT_FOUND => t('Page not found'),
        RABBIT_HOLE_PAGE_REDIRECT => t('Page redirect'),
      ),
      '#default_value' => variable_get('rabbit_hole_action_' . $form['#node_type']->type, RABBIT_HOLE_DISPLAY_CONTENT),
      '#description' => t('What should happen when someone tries to visit the node page?'),
    );
    $form['rabbit_hole']['redirect'] = array(
      '#type' => 'fieldset',
      '#title' => t('Redirect settings'),
      '#attributes' => array(
        'class' => array(
          'rabbit-hole-redirect-options',
        ),
      ),
    );
    $form['rabbit_hole']['redirect']['rabbit_hole_redirect'] = array(
      '#type' => 'textfield',
      '#title' => t('Redirect path'),
      '#size' => 40,
      '#default_value' => variable_get('rabbit_hole_redirect_' . $form['#node_type']->type, ''),
      '#description' => t('The relative path to were the user should be redirected. Leave this empty, or use %front to redirect to the front page. You may enter tokens in this field.', array(
        '%front' => '<front>',
      )),
    );

    // Display a list of tokens if the Token module is enabled.
    if (module_exists('token')) {
      $form['rabbit_hole']['redirect']['token_info'] = array(
        '#theme' => 'token_tree',
        '#token_types' => array(
          'node',
        ),
      );
    }
    $form['rabbit_hole']['redirect']['rabbit_hole_redirect_response'] = array(
      '#type' => 'select',
      '#title' => t('Response code'),
      '#options' => array(
        301 => t('301 (Moved Permanently)'),
        302 => t('302 (Found)'),
        303 => t('303 (See other)'),
        304 => t('304 (Not modified)'),
        305 => t('305 (Use proxy)'),
        307 => t('307 (Temporary redirect)'),
      ),
      '#default_value' => variable_get('rabbit_hole_redirect_response_' . $form['#node_type']->type, RABBIT_HOLE_PAGE_REDIRECT_RESPONSE_DEFAULT),
      '#description' => t('The response code that should be sent to the users browser. Follow !link for more information on response codes.', array(
        '!link' => l(t('this link'), 'http://api.drupal.org/api/drupal/includes--common.inc/function/drupal_goto/7'),
      )),
    );
  }
}