You are here

function taxonomy_tools_preprocess_page in Taxonomy Tools 8

Same name and namespace in other branches
  1. 7 taxonomy_tools.module \taxonomy_tools_preprocess_page()

Implements hook_preprocess_HOOK().

File

./taxonomy_tools.module, line 502
Drupal hooks and functions to work with taxonomy terms.

Code

function taxonomy_tools_preprocess_page(&$variables) {
  if (arg(4) == 'overview' && arg(5) != 'add' && arg(6) != 'add') {

    // Proper breadcrumb for vocabulary overview page.
    $breadcrumb = array();
    $options = array(
      'html' => TRUE,
    );
    $step = l(t('Home'), '<front>', $options);
    array_push($breadcrumb, $step);
    $step = l(t('Administration'), 'admin', $options);
    array_push($breadcrumb, $step);
    $step = l(t('Structure'), 'admin/structure', $options);
    array_push($breadcrumb, $step);
    $step = l(t('Taxonomy'), 'admin/structure/taxonomy', $options);
    array_push($breadcrumb, $step);
    if (is_numeric(arg(5))) {
      $query = db_select('taxonomy_vocabulary', 'foo');
      $query
        ->addField('foo', 'name');
      $query
        ->condition('foo.machine_name', arg(3));
      $vocabulary_name = $query
        ->execute()
        ->fetchField();
      $step = l($vocabulary_name, 'admin/structure/taxonomy/' . arg(3) . '/overview', $options);
      array_push($breadcrumb, $step);
      $path = array_reverse(taxonomy_tools_term_path(arg(5), FALSE));
      if (!empty($path)) {
        foreach ($path as $term) {
          $step = l($term['name'], 'admin/structure/taxonomy/' . arg(3) . '/overview/' . $term['tid'], $options);
          array_push($breadcrumb, $step);
        }
      }
    }
    drupal_set_breadcrumb($breadcrumb);
  }
  if (arg(4) == 'overview' && (arg(5) == 'add' || arg(6) == 'add')) {

    // Proper breadcrumb when adding new term through vocabulary
    // overview page.
    $breadcrumb = array();
    $options = array(
      'html' => TRUE,
    );
    $step = l(t('Home'), '<front>', $options);
    array_push($breadcrumb, $step);
    $step = l(t('Administration'), 'admin', $options);
    array_push($breadcrumb, $step);
    $step = l(t('Structure'), 'admin/structure', $options);
    array_push($breadcrumb, $step);
    $step = l(t('Taxonomy'), 'admin/structure/taxonomy', $options);
    array_push($breadcrumb, $step);
    $query = db_select('taxonomy_vocabulary', 'foo');
    $query
      ->addField('foo', 'name');
    $query
      ->condition('foo.machine_name', arg(3));
    $vocabulary_name = $query
      ->execute()
      ->fetchField();
    $step = l($vocabulary_name, 'admin/structure/taxonomy/' . arg(3) . '/overview', $options);
    array_push($breadcrumb, $step);
    if (is_numeric(arg(5))) {
      $path = array_reverse(taxonomy_tools_term_path(arg(5)));
      if (!empty($path)) {
        foreach ($path as $term) {
          $step = l($term['name'], 'admin/structure/taxonomy/' . arg(3) . '/overview/' . $term['tid'], $options);
          array_push($breadcrumb, $step);
        }
      }
    }
    drupal_set_breadcrumb($breadcrumb);
  }
  if (arg(3) == 'overview' && arg(4) == 'add' && is_numeric(arg(2))) {

    // Proper breadcrumb when adding new term through vocabulary
    // overview page which is opened through term page.
    $breadcrumb = array();
    $options = array(
      'html' => TRUE,
    );
    $step = l(t('Home'), '<front>', $options);
    array_push($breadcrumb, $step);
    $path = array_reverse(taxonomy_tools_term_path(arg(2)));
    if (!empty($path)) {
      foreach ($path as $term) {
        $step = l($term['name'], 'taxonomy/term/' . $term['tid'] . '/overview', $options);
        array_push($breadcrumb, $step);
      }
    }
    drupal_set_breadcrumb($breadcrumb);
  }
}