You are here

class _taxonomy_CrumbsMultiPlugin_termReference in Crumbs, the Breadcrumbs suite 7

Hierarchy

Expanded class hierarchy of _taxonomy_CrumbsMultiPlugin_termReference

File

plugins/crumbs.taxonomy.inc, line 30

View source
class _taxonomy_CrumbsMultiPlugin_termReference implements crumbs_MultiPlugin {
  protected $fieldKey;
  protected $bundles;

  // To be defined by the child class
  protected $entityType;
  function __construct($field_key, $bundles) {
    $this->fieldKey = $field_key;
    $this->bundles = $bundles;
  }
  function describe($api) {
    foreach ($this->bundles as $bundle) {
      $api
        ->addRule($bundle, $bundle);
    }
  }
  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'];
        }
      }
    }
  }
  protected function _getPath_node($nid) {
    return 'node/' . $nid;
  }
  protected function _getPath_user($uid) {
    return 'user/' . $uid;
  }

}

Members