You are here

function node_noindex_form_alter in Node Noindex 7

Same name and namespace in other branches
  1. 6 node_noindex.module \node_noindex_form_alter()

Implements hook_form_alter().

Adds custom fieldset to the node form, and attach ajax behaviour for vertical panels to update the settings description.

See also

node_noindex.js

File

./node_noindex.module, line 100

Code

function node_noindex_form_alter(&$form, $form_state, $form_id) {
  if (!empty($form['#node_edit_form'])) {
    if (user_access('administer node_noindex') && variable_get('node_noindex_' . $form['type']['#value'], 0)) {
      $node = $form['#node'];

      // Create a fieldset named 'node_noindex' that will be included in the vertical tab.
      $form['node_noindex'] = array(
        '#type' => 'fieldset',
        '#title' => t('Search engine settings'),
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
        '#tree' => TRUE,
        '#access' => user_access('administer node_noindex'),
        '#weight' => 40,
        '#group' => 'additional_settings',
        '#attached' => array(
          'js' => array(
            'vertical-tabs' => drupal_get_path('module', 'node_noindex') . '/node_noindex.js',
          ),
        ),
      );
      $form['node_noindex']['noindex'] = array(
        '#type' => 'checkbox',
        '#title' => t('Set <code>noindex</code> in HTML head'),
        '#description' => t('If enabled the “robots” meta tag will be set to “noindex” for this node.'),
        '#default_value' => isset($node->noindex) ? $node->noindex : variable_get('node_noindex_default_' . $form['type']['#value'], 0),
        '#weight' => 5,
      );
    }
  }
}