You are here

function _nat_save_term in Node Auto Term [NAT] 7.2

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

Sync fields and save the NAT term. There are pros and cons to perhaps doing this with a form submission rather than field assignments.

Parameters

Object $node: The NAT node.

Array $hierarchy: Parent terms as per any taxonomy reference fields on the node form.

Object $term: The term object to be populated and saved.

Array $entities: An array of taxonomy term field entitites.

Array $fields: The fields to synchronize: an associative array of term=>node fields.

2 calls to _nat_save_term()
_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 628
NAT - node auto term - is a helper module that automatically creates a term using the same title as a node.

Code

function _nat_save_term($node, $hierarchy, $term, $entities, $fields) {
  $term->parent = isset($hierarchy[$term->vid]) ? $hierarchy[$term->vid] : array(
    0,
  );
  foreach ($fields as $term_field => $node_field) {
    $resolved_fields = _nat_field_associate($node, $entities, $term_field, $node_field);
    foreach ($resolved_fields as $term_field_resolved => $node_field_resolved) {
      $term->{$term_field_resolved} = $node_field_resolved;
    }
  }
  taxonomy_term_save($term);
  return $term;
}