You are here

protected function _taxonomy_CrumbsMultiPlugin_termReference::_findParentPath in Crumbs, the Breadcrumbs suite 7

3 calls to _taxonomy_CrumbsMultiPlugin_termReference::_findParentPath()
_taxonomy_CrumbsMultiPlugin_termReference_commerce_product::findParent__product_x in plugins/crumbs.taxonomy.inc
Match "product/%" router path. This works only in combination with commerce_product_page module.
_taxonomy_CrumbsMultiPlugin_termReference_node::findParent__node_x in plugins/crumbs.taxonomy.inc
Match "node/%" router path
_taxonomy_CrumbsMultiPlugin_termReference_user::findParent__user_x in plugins/crumbs.taxonomy.inc
Match "user/%" router path

File

plugins/crumbs.taxonomy.inc, line 49

Class

_taxonomy_CrumbsMultiPlugin_termReference

Code

protected function _findParentPath($entity) {
  $terms = array();
  $items = field_get_items($this->entityType, $entity, $this->fieldKey);
  if ($items) {
    foreach ($items as $item) {
      $terms[$item['tid']] = TRUE;
    }
  }
  if (count($terms) > 1) {
    $walk = $terms;
    $visited = array();
    while (!empty($walk)) {
      $visited += $walk;
      foreach ($walk as $tid => $true) {
        $parents = taxonomy_get_parents($tid);
        unset($walk[$tid]);
        foreach ($parents as $tid => $parent) {
          unset($terms[$tid]);
          if (!isset($visited[$tid])) {
            $walk[$tid] = $parent;
          }
        }
      }
    }
  }

  // Return the path of the first found term, if any.
  foreach ($terms as $tid => $term_info) {
    $term = taxonomy_term_load($tid);
    if (!empty($term)) {
      $uri = entity_uri('taxonomy_term', $term);
      if (!empty($uri)) {
        return $uri['path'];
      }
    }
  }
}