You are here

function page_title_form_alter in Page Title 5.2

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

Implementation of hook_form_alter().

File

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

Code

function page_title_form_alter($form_id, &$form) {

  // 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)) {
      $form['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' => $form['#node']->page_title,
        '#size' => 60,
        '#maxlength' => 255,
        '#weight' => -4,
      );
    }
  }
  elseif ($form_id == 'taxonomy_form_term') {
    $key = 'page_title_vocab_' . $form['vid']['#value'] . '_showfield';
    if (variable_get($key, 0)) {
      $form['page_title'] = array(
        '#type' => 'textfield',
        '#title' => t('Page title'),
        '#description' => t('Provide a description of this term 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_load_title($form['tid']['#value'], 'term'),
        '#size' => 60,
        '#maxlength' => 255,
        '#weight' => -1,
      );
    }
  }
  elseif ($form_id == 'forum_form_forum' || $form_id == 'forum_form_container') {
    $key = 'page_title_vocab_' . $form['vid']['#value'] . '_showfield';
    if (variable_get($key, 0)) {
      $form['page_title'] = array(
        '#type' => 'textfield',
        '#title' => t('Page title'),
        '#description' => t('Provide a description of this forum 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_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('Provide a description of this user 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_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' => variable_get('page_title_type_' . $form['#node_type']->type . '_showfield', 0) ? array(
        'show_field',
      ) : array(),
    );
    $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'] = array();
  }
  elseif ($form_id == 'forum_admin_settings') {
    $form['page_title_forum_root_title'] = array(
      '#type' => 'textfield',
      '#title' => t('Page title'),
      '#description' => t('Provide a description of this forum overview page to appear in the &lt;title&gt; 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' => variable_get('page_title_forum_root_title', ''),
      '#size' => 60,
      '#maxlength' => 255,
      '#weight' => -1,
    );
  }
}