crumbs.nodereference.inc in Crumbs, the Breadcrumbs suite 6.2
File
plugins/crumbs.nodereference.inc
View source
<?php
function nodereference_crumbs_plugins() {
$plugins = array();
foreach (content_fields() as $key => $info) {
if ($info['type'] === 'nodereference' && $info['multiple'] === 0) {
$plugins[$key] = new _nodereference_CrumbsPlugin($key, $info);
}
}
return $plugins;
}
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;
}
function define($h) {
$h
->enabledByDefault(FALSE);
foreach ($this
->_getReferenceableTypes() as $type_name) {
$h
->addRule($type_name);
}
}
function disabledByDefault() {
return array(
'*',
);
}
function findParent__node_x($path, $item) {
$node = $item['map'][0];
$result = array();
if ($ref_nid = $this
->_readParentNodeReference($node)) {
$result[$node->type] = 'node/' . $ref_nid;
}
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'];
}
}
}