You are here

function path_breadcrumbs_tokens in Path Breadcrumbs 7.3

Implements hook_tokens().

File

./path_breadcrumbs.tokens.inc, line 11
Provides useful tokens for Path Breadcrumbs. Also see path_breadcrumbs.info.inc file.

Code

function path_breadcrumbs_tokens($type, $tokens, array $data = array(), array $options = array()) {
  $replacements = array();
  if ($type == 'menu-link') {
    $replacements += _path_breadcrumbs_menu_token_generate($tokens, $data, $options);
  }

  // Fallback support for all 'menu-link' tokens if Token module disabled.
  if (!module_exists('token') && $type != 'site') {
    if ($menu_tokens = token_find_with_prefix($tokens, 'menu-link')) {
      if (empty($data['menu-link']) && isset($data['node'])) {
        $data['menu-link'] = menu_link_get_preferred('node/' . $data['node']->nid);
      }
      $replacements += _path_breadcrumbs_menu_token_generate($menu_tokens, $data, $options);
    }
  }

  // Support 'current-page:menu-link:*' and 'current-page:path-menu-trail:*'
  // tokens.
  if ($type == 'site') {

    // We have to unprefix 'current-page:*' tokens manually.
    if ($site_tokens = token_find_with_prefix($tokens, 'current-page')) {
      if ($menu_tokens = token_find_with_prefix($site_tokens, 'menu-link')) {
        $data['menu-link'] = menu_link_get_preferred();
        $replacements += _path_breadcrumbs_menu_token_generate($menu_tokens, $data, $options);

        // Also replace common menu-link tokens.
        foreach ($menu_tokens as $name => $original) {
          switch ($name) {
            case 'mlid':
              $replacements[$original] = $data['menu-link']['mlid'];
              break;
            case 'title':
              $replacements[$original] = check_plain($data['menu-link']['link_title']);
              break;
            case 'url':
              $replacements[$original] = $data['menu-link']['href'];
              break;
          }
        }
      }
      elseif ($path_tokens = token_find_with_prefix($site_tokens, 'path-menu-trail')) {
        $replacements += _path_breadcrumbs_path_menu_trail_token_generate($path_tokens);
      }
    }
  }
  return $replacements;
}