You are here

function taxonomy_title_process_page in Taxonomy Title 7

Implements hook_preprocess_page().

Overrides variables sent to template_preprocess.

File

./taxonomy_title.module, line 62
Enhanced control over the heading tag for the taxonomy term list pages.

Code

function taxonomy_title_process_page(&$variables) {
  if (arg(0) == 'taxonomy' && arg(1) == 'term' && is_numeric(arg(2)) && arg(2) > 0 && !arg(3)) {
    $tid = arg(2);
  }
  elseif (module_exists('uc_catalog') && arg(0) == 'catalog') {
    $tids = explode(' ', arg(1));
    if (is_numeric($tids[0]) && $tids[0] > 0) {
      $tid = $tids[0];
    }
  }
  if (!empty($tid)) {

    // Retrieve the title based on tid.
    $title = taxonomy_title_get($tid);
    if (!empty($title)) {
      $term = taxonomy_term_load($tid);
      $heading_settings = variable_get('taxonomy_title_headings', array());
      $page_title_settings = variable_get('taxonomy_title_page_titles', array());

      // If there no setting, assume setting is ON.
      $affect_heading = !isset($heading_settings[$term->vid]) || $heading_settings[$term->vid] != 0;
      $affect_title = !isset($page_title_settings[$term->vid]) || $page_title_settings[$term->vid] != 0;

      // Set the page heading.
      if ($affect_heading) {
        $variables['title'] = $title;
      }

      // Set the HTML title tag.
      $site_name = variable_get('site_name', 'Drupal');
      if ($affect_title && !module_exists('page_title') && !module_exists('metatag')) {
        $head_title = array(
          $title,
          $site_name,
        );
        $variables['head_title'] = implode(' | ', $head_title);
      }
      else {

        // Unset things, just to be safe.
        $title = check_plain($term->name);
        $head_title = array(
          $title,
          $site_name,
        );
        $variables['head_title'] = implode(' | ', $head_title);
      }
      drupal_set_title($title);
    }
  }
}