You are here

function page_title_page_get_title in Page Title 8.2

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

Determines what title should be sent to the page template.

This function gets called from the implementation of hook_preprocess_html

Parameters

$raw: Optionally get the result without cleaning it with filter_xss. This should be used with caution.

Return value

string The page's title.

1 call to page_title_page_get_title()
page_title_preprocess_html in ./page_title.module
Implement hook_preprocess_html().

File

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

Code

function page_title_page_get_title($raw = FALSE) {
  $title =& drupal_static(__FUNCTION__);
  if (is_null($title)) {
    $types = array(
      'global' => NULL,
    );

    // Allow hook_page_title_pattern_alter() to modify the pattern and tokens
    drupal_alter('page_title_pattern', $page_title_pattern, $types);

    // If pattern is empty (either if the type is not overridable or simply not set) fallback to the default pattern
    if (empty($page_title_pattern)) {
      $settings = page_title_get_settings();
      $page_title_pattern = variable_get('page_title_default', $settings['page_title_default']['default']);
    }

    // Append the pattern for pages with a pager on them
    $page_title_pattern .= isset($_REQUEST['page']) ? variable_get('page_title_pager_pattern', '') : '';

    // Apply token patterns using token_replace
    $title = token_replace($page_title_pattern, $types, array(
      'sanitize' => FALSE,
    ));

    // If some tokens failed to be replaced, fallback to the default pattern.
    $remaining_tokens = token_scan($title);
    if (count($remaining_tokens)) {
      $settings = page_title_get_settings();
      $page_title_pattern = variable_get('page_title_default', $settings['page_title_default']['default']);

      // Append the pattern for pages with a pager on them
      $page_title_pattern .= isset($_REQUEST['page']) ? variable_get('page_title_pager_pattern', '') : '';

      // Apply token patterns using token_replace
      $title = token_replace($page_title_pattern, $types, array(
        'sanitize' => FALSE,
        'clean' => TRUE,
      ));
    }
  }

  // Trim trailing whitespace from the title
  $title = trim($title);
  return $raw ? $title : filter_xss($title);
}