home | career | drupal | java | mac | mysql | perl | php | scala | uml | unix

Drupal example source code file (node.page_title.inc)

This example Drupal source code file (node.page_title.inc) is included in the DevDaily.com "Drupal Source Code Warehouse" project. The intent of this project is to help you "Learn Drupal by Example".

PHP - Drupal tags/keywords

_showfield, arg, args, array, current, empty, function, if, is_numeric, node, pattern, php, title, types

The node.page_title.inc Drupal example source code

<?php
// $Id: node.page_title.inc,v 1.1.4.2 2010/08/25 14:33:30 njt1982 Exp $

/**
 * @file
 * Node implementations of the page title hooks
 */


/**
 * Implementation of hook_page_title_alter().
 */
function node_page_title_alter(&$title) {
  if (arg(0) == 'node' && is_numeric(arg(1))) {
    // Get the node
    $node = menu_get_object('node');

    // If the node has a custom page title and the node type is configured to have a custom page title (ie, it's not a leftover from a previous setting), then use it.
    if (!empty($node->page_title) && variable_get('page_title_type_'. $node->type .'_showfield', 0)) {
      $title = $node->page_title;
    }
  }
}


/**
 * Implementation of hook_page_title_pattern_alter().
 */
function node_page_title_pattern_alter(&$pattern, &$types) {
  if ((arg(0) == 'node' && is_numeric(arg(1)))) {
    $types['node'] = menu_get_object();

    // If the node has any taxonomy, grab the first time and pass it over to be passed as a token.
    // TODO: Handle multiple terms? Only pass specific terms per content type?
    if (!empty($types['node']->taxonomy)) {
      $types['taxonomy'] = current($types['node']->taxonomy);
    }

    $pattern = variable_get('page_title_type_'. $types['node']->type, '');
  }
}

Other Drupal examples (source code examples)

Here is a short list of links related to this Drupal node.page_title.inc source code file:

new blog posts

"Drupal" is a registered trademark of Dries Buytaert.

my drupal tutorials and examples  

Copyright 1998-2016 Alvin Alexander, alvinalexander.com
All Rights Reserved.

Beginning in 2016, a portion of the proceeds from pages under the '/drupal-code-examples/' URI will be donated to charity.