You are here

function _nat_get_term_hierarchies in Node Auto Term [NAT] 7.2

Same name and namespace in other branches
  1. 7 nat.module \_nat_get_term_hierarchies()

Retrieve any parent terms for the NAT term from the node object.

Parameters

Object $node: The node to parse.

Return value

Array $hierarchy An array containing the parent terms for the NAT term.

2 calls to _nat_get_term_hierarchies()
_nat_add_terms in ./nat.module
Add node titles as terms into the taxonomy system. @todo Ideas are welcome to allow retaining the hierarchy for vocabularies not present in the node form.
_nat_update_terms in ./nat.module
Update saved node-terms.

File

./nat.module, line 825
NAT - node auto term - is a helper module that automatically creates a term using the same title as a node.

Code

function _nat_get_term_hierarchies($node) {

  // Collate taxonomy reference fields by their vocabulary IDs.
  $instances = field_info_instances('node', $node->type);
  $hierarchy = array();
  foreach ($instances as $name => $instance) {
    if (isset($node->{$name})) {
      $field = field_info_field($name);
      if ($field['type'] == 'taxonomy_term_reference' && !empty($node->{$name})) {
        $vocabulary = taxonomy_vocabulary_machine_name_load($field['settings']['allowed_values'][0]['vocabulary']);
        $terms = field_get_items('node', $node, $name, $node->language);
        foreach ($terms as $term) {
          $hierarchy[$vocabulary->vid][] = $term['tid'];
        }
      }
    }
  }
  return $hierarchy;
}