You are here

crumbs.crumbs.inc in Crumbs, the Breadcrumbs suite 6.2

File

plugins/crumbs.crumbs.inc
View source
<?php

/**
 * Implementation of hook_crumbs_plugins()
 */
function crumbs_crumbs_plugins() {
  return array(
    'home_title' => new _crumbs_CrumbsPlugin__home_title(),
  );
}
class _crumbs_CrumbsPlugin__home_title {
  protected $_front_normal_path;
  function __construct() {
    $this->_front_normal_path = drupal_get_normal_path(variable_get('site_frontpage', 'node'));
  }
  function define($h) {
    return $h
      ->setTitle(t('Set "Home" as the title for the root item.'));
  }
  function findTitle($path, array $item) {
    if ($path === $this->_front_normal_path) {
      return t('Home');
    }
  }

}

/**
 * This plugin allows to put information about the crumbs parent into the
 * router item, via hook_menu() or hook_menu_alter().
 *
 * Syntax in the router item:
 *   $router_item['crumbs_parent_callback'],
 *     giving a callback which takes $path and $item as arguments, and has to
 *     return the parent path.
 *   $router_item['crumbs_parent'],
 *     with $0, $1 etc being replaced with fragments from the original path.
 *
 * TODO: Does this actually work? Will menu_rebuild store the information,
 *   if there is no respective table column?
 *   See http://drupal.org/node/1002116
 */
class _crumbs_CrumbsPlugin__menu_router {
  function define($h) {
    $h
      ->setTitle('Follow the hint in the router item');
  }
  function findParent($path, $item) {
    if (is_string($item['crumbs_parent_callback'])) {
      $function = $item['crumbs_parent_callback'];
      if (function_exists($function)) {
        return $function($path, $item);
      }
    }
    else {
      if (is_string($item['crumbs_parent'])) {
        $replace = array();
        foreach (explode('/', $path) as $i => $fragment) {
          $replace['$' . $i] = $fragment;
        }
        return strtr($item['crumbs_parent'], $replace);
      }
    }
  }

}

Functions

Namesort descending Description
crumbs_crumbs_plugins Implementation of hook_crumbs_plugins()

Classes

Namesort descending Description
_crumbs_CrumbsPlugin__home_title
_crumbs_CrumbsPlugin__menu_router This plugin allows to put information about the crumbs parent into the router item, via hook_menu() or hook_menu_alter().