You are here

function page_title_form_alter in Page Title 7.2

Same name and namespace in other branches
  1. 8.2 page_title.module \page_title_form_alter()
  2. 5.2 page_title.module \page_title_form_alter()
  3. 5 page_title.module \page_title_form_alter()
  4. 6.2 page_title.module \page_title_form_alter()
  5. 6 page_title.module \page_title_form_alter()
  6. 7 page_title.module \page_title_form_alter()

Implement hook_form_alter(). (cant use hook_form_FORM_ID_alter(). here as the form ID changes from node to node)

File

./page_title.module, line 190
Enhanced control over the page title (in the head tag).

Code

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

  // If we dont have permission to set the title then we need to abort this alter now!
  if (!user_access('set page title')) {
    return;
  }

  // If we're editing a node...
  if (!empty($form['#node_edit_form'])) {

    // ... and the show field is enabled for this node type
    if (variable_get('page_title_type_' . $form['type']['#value'] . '_showfield', 0)) {
      $page_title = isset($form['#node']->page_title) ? $form['#node']->page_title : NULL;
      $form['page_title'] = array(
        '#type' => 'fieldset',
        '#title' => t('Page title settings'),
        '#collapsible' => TRUE,
        '#collapsed' => empty($page_title),
        '#group' => 'additional_settings',
        '#weight' => 35,
        '#attached' => array(
          'js' => array(
            drupal_get_path('module', 'page_title') . '/page_title.js',
          ),
        ),
      );
      $form['page_title']['page_title'] = array(
        '#type' => 'textfield',
        '#title' => t('Page title'),
        '#description' => t('Provide a description of this node to appear in the <title> tag which search engines can use in search result listings (optional). It is generally accepted this field should be less than 70 characters.'),
        '#default_value' => $page_title,
        '#size' => 60,
        '#maxlength' => 255,
      );
    }
  }
}