You are here

function page_title_form_alter in Page Title 7

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.2 page_title.module \page_title_form_alter()

Implement hook_form_alter().

File

./page_title.module, line 134
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;
  }

  // Check we're editing a node and also check that the node type's 'show field' is enabled
  if ($form['#id'] == 'node-form') {
    $key = 'page_title_type_' . $form['type']['#value'] . '_showfield';
    if (variable_get($key, 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('Optionally specify a different title to appear in the <title> tag of the page.'),
        '#default_value' => $page_title,
        '#size' => 60,
        '#maxlength' => 255,
      );
    }
  }
  elseif ($form_id == 'taxonomy_form_term') {
    $key = 'page_title_vocab_' . $form['vid']['#value'] . '_showfield';
    if (variable_get($key, 0)) {
      $form['advanced']['page_title'] = array(
        '#type' => 'textfield',
        '#title' => t('Page title'),
        '#description' => t('Optionally specify a different title to appear in the <title> tag of the page.'),
        '#default_value' => isset($form['tid']) ? page_title_load_title($form['tid']['#value'], 'term') : '',
        '#size' => 60,
        '#maxlength' => 255,
        '#weight' => -20,
      );
    }
  }
  elseif ($form_id == 'user_profile_form') {
    if (variable_get('page_title_user_showfield', 0)) {
      $form['account']['page_title'] = array(
        '#type' => 'textfield',
        '#title' => t('Page title'),
        '#description' => t('Optionally specify a different title to appear in the <title> tag of the page.'),
        '#default_value' => page_title_load_title($form['_account']['#value']->uid, 'user'),
        '#size' => 60,
        '#maxlength' => 255,
        '#weight' => 20,
      );
    }
  }
  elseif ($form_id == 'node_type_form') {
    $form['page_title'] = array(
      '#type' => 'fieldset',
      '#title' => t('Page Title Settings'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
      '#tree' => TRUE,
    );
    $form['page_title']['show_field'] = array(
      '#type' => 'checkboxes',
      '#title' => t('Page Title Field'),
      '#description' => t('If checked, the <em>Page Title</em> field will appear on the node edit form for those who have permission to set the title.'),
      '#options' => array(
        'show_field' => t('Show field'),
      ),
      '#default_value' => array(
        'show_field' => variable_get('page_title_type_' . $form['#node_type']->type . '_showfield', 0) ? 'show_field' : 0,
      ),
    );
    $form['page_title']['pattern'] = array(
      '#type' => 'textfield',
      '#title' => t('Page Title Pattern'),
      '#default_value' => variable_get('page_title_type_' . $form['#node_type']->type, ''),
      '#description' => t('Enter the <em>Page Title</em> pattern you want to use for this node type. For more information, please use the !link settings page', array(
        '!link' => l('Page Title', 'admin/content/page_title'),
      )),
    );
    $form['#submit'][] = 'page_title_node_type_form_submit';
  }
}