You are here

class crumbs_ParentFinder in Crumbs, the Breadcrumbs suite 6.2

Same name and namespace in other branches
  1. 7.2 lib/ParentFinder.php \crumbs_ParentFinder
  2. 7 lib/ParentFinder.php \crumbs_ParentFinder

Can find a parent path for a given path. Contains a cache.

Hierarchy

Expanded class hierarchy of crumbs_ParentFinder

File

./crumbs.trail.inc, line 128

View source
class crumbs_ParentFinder {
  protected $_pluginEngine;

  // cached parent paths
  protected $_parents = array();
  protected $_log = array();
  function __construct($pluginEngine) {
    $this->_pluginEngine = $pluginEngine;
  }
  function getParentPath($path, &$item) {
    if (!isset($this->_parents[$path])) {
      $parent_path = $this
        ->_findParentPath($path, $item);
      $this->_parents[$path] = drupal_get_normal_path($parent_path);
    }
    return $this->_parents[$path];
  }
  function getLoggedCandidates($path) {
    if (is_array($this->_log[$path])) {
      return $this->_log[$path];
    }
    else {
      return array();
    }
  }
  protected function _findParentPath($path, &$item) {
    if ($item) {
      $invoke_action = new _crumbs_InvokeAction_findParent($path, $item);
      $this->_pluginEngine
        ->invokeAll_find($invoke_action);
      $parent_path = $invoke_action
        ->getValue();
      $this->_log[$path] = $invoke_action
        ->getLoggedCandidates();
      if (isset($parent_path)) {
        $item['crumbs_candidate_key'] = $invoke_action
          ->getCandidateKey();
        return $parent_path;
      }
    }

    // fallback: chop off the last fragment of the system path.
    $parent_path = crumbs_reduce_path($path);
    return isset($parent_path) ? $parent_path : FALSE;
  }

}

Members