You are here

function og_CrumbsMultiPlugin_group_post::findParent__node_x in Crumbs, the Breadcrumbs suite 7

Same name in this branch
  1. 7 plugins/crumbs.og.inc \og_CrumbsMultiPlugin_group_post::findParent__node_x()
  2. 7 plugins/crumbs.og.2.inc \og_CrumbsMultiPlugin_group_post::findParent__node_x()
Same name and namespace in other branches
  1. 7.2 plugins/crumbs.og.inc \og_CrumbsMultiPlugin_group_post::findParent__node_x()
  2. 7.2 plugins/crumbs.og.2.inc \og_CrumbsMultiPlugin_group_post::findParent__node_x()

Attempts to find a breadcrumb parent path for node/%. If that node is in a group, it will return the group page as a parent.

Parameters

string $path: The path, e.g. node/123

array $item: The router item, as returned by crumbs_get_router_item()

File

plugins/crumbs.og.2.inc, line 42

Class

og_CrumbsMultiPlugin_group_post
Use the group node as a parent for group posts. The priorities can be configured per group content type.

Code

function findParent__node_x($path, $item) {
  $node = $item['map'][1];

  // Load the node if it hasn't been loaded due to a missing wildcard loader.
  $node = is_numeric($node) ? node_load($node) : $node;

  // field_get_items() performs a lot faster than og_get_entity_groups().
  // See http://drupal.org/node/1819300#comment-6633494
  // TODO:
  //   We cannot rely on the field name to always be og_group_ref.
  //   Instead, we could provide a separate plugin for each such field.
  //   This way, fields in disabled plugins get never triggered.
  $items = field_get_items('node', $node, 'og_group_ref');
  if (!empty($items)) {
    foreach ($items as $item) {
      $parent_path = $this
        ->getParentPath($item['target_id'], $node);
      return array(
        $node->type => $parent_path,
      );
    }
  }
}