You are here

function node_page_title_pattern_alter in Page Title 8.2

Same name and namespace in other branches
  1. 6.2 modules/node.page_title.inc \node_page_title_pattern_alter()
  2. 7.2 modules/node.page_title.inc \node_page_title_pattern_alter()

Implements hook_page_title_pattern_alter().

File

modules/node.page_title.inc, line 30
Node implementations of the page title hooks

Code

function node_page_title_pattern_alter(&$pattern, &$types) {
  $menu_item = menu_get_item();

  // Test if this is a node page.
  if (!strncmp($menu_item['path'], 'node/%', 6) && ($node = menu_get_object())) {
    $types['node'] = $node;

    // If the node has any taxonomy, grab the first term for use in tokens.
    // TODO: Handle multiple terms? Only pass specific terms per content type?
    // In Drupal 7, terms are no longer in $node->taxomomy. We need to grab all
    // taxonomy_term_reference fields for this bundle and attach them.
    // TODO: Should this be in page_title.taxonomy.inc?!
    $fields = field_info_fields();
    foreach ($fields as $field_name => $field) {
      if ($field['type'] == 'taxonomy_term_reference' && !empty($field['bundles']['node']) && in_array($node->type, $field['bundles']['node']) && isset($node->{$field_name}[$node->language][0])) {

        // Get the term instance.
        $instance = $node->{$field_name}[$node->language][0];
        if (isset($instance['taxonomy_term'])) {
          $types['term'] = $instance['taxonomy_term'];
          break;
        }
        elseif (isset($instance['tid'])) {
          $types['term'] = taxonomy_term_load($instance['tid']);
          break;
        }
      }
    }
    $pattern = variable_get('page_title_type_' . $types['node']->type, '');
  }
}