You are here

class _nodereference_CrumbsPlugin in Crumbs, the Breadcrumbs suite 6

Same name and namespace in other branches
  1. 6.2 plugins/crumbs.nodereference.inc \_nodereference_CrumbsPlugin

Implementation of class hook CrumbsPlugin on the behalf of menu module.

Hierarchy

Expanded class hierarchy of _nodereference_CrumbsPlugin

File

plugins/crumbs.nodereference.inc, line 19

View source
class _nodereference_CrumbsPlugin {
  protected $_field_key;
  protected $_field_info;
  function __construct($field_key, $field_info) {
    $this->_field_key = $field_key;
    $this->_field_info = $field_info;
  }

  /**
   * Tell crumbs that this object defines more than one rule.
   * Each returned rule will be shown in the config form to move up and down.
   */
  function define($h) {
    $h
      ->enabledByDefault(FALSE);
    foreach ($this
      ->_getReferenceableTypes() as $type_name) {
      $h
        ->addRule($type_name);
    }
  }

  /**
   * Match "node/%" router path
   */
  function findParent__node__($path, $item) {
    $node = $item['map'][0];
    $result = array();
    if ($ref_nid = $this
      ->_readParentNodeReference($node)) {
      $result[$node->type] = 'node/' . $ref_nid;
    }

    // return all candidates, so crumbs can sort them according to priority settings.
    return $result;
  }
  protected function _getReferenceableTypes() {
    $types = $this->_field_info['referenceable_types'];
    return is_array($types) ? $types : array();
  }
  protected function _readParentNodeReference($node) {
    $values = array();
    $field_key = $this->_field_key;
    $field = $node->{$field_key};
    if (is_array($field) && !empty($field[0]['nid'])) {
      return (int) $field[0]['nid'];
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
_nodereference_CrumbsPlugin::$_field_info protected property
_nodereference_CrumbsPlugin::$_field_key protected property
_nodereference_CrumbsPlugin::define function Tell crumbs that this object defines more than one rule. Each returned rule will be shown in the config form to move up and down.
_nodereference_CrumbsPlugin::findParent__node__ function Match "node/%" router path
_nodereference_CrumbsPlugin::_getReferenceableTypes protected function
_nodereference_CrumbsPlugin::_readParentNodeReference protected function
_nodereference_CrumbsPlugin::__construct function