function _nat_field_associate in Node Auto Term [NAT] 7.2
Same name and namespace in other branches
- 7 nat.module \_nat_field_associate()
Synchronize term and node fields. @todo All the entity handling feels hacky. Needs investigation.
Parameters
$node: The node object.
$entities: Field entities for the taxonomy term object.
$term_field: The name of the term field to synchronize to.
$node_field: The name of the node field to synchronize from.
1 call to _nat_field_associate()
- _nat_save_term in ./
nat.module - Sync fields and save the NAT term. There are pros and cons to perhaps doing this with a form submission rather than field assignments.
File
- ./
nat.module, line 697 - NAT - node auto term - is a helper module that automatically creates a term using the same title as a node.
Code
function _nat_field_associate($node, $entities, $term_field, $node_field) {
$field = array();
// $node->language sometimes does not work very well with term fields.
$language_node = $node->language;
// PHP dodginess requires an interim field.
$node_field1 = $node->{$node_field};
switch ($term_field) {
case 'name':
$field['name'] = $node_field == 'title' ? $node->title : $node_field1[$language_node][0]['value'];
break;
case 'description':
if ($node_field == 'title') {
$field['description'] = $node->{$node_field};
$field['format'] = NULL;
}
else {
if (!empty($node_field1[$language_node])) {
$field['description'] = $node_field1[$language_node][0]['value'];
$field['format'] = $node_field1[$language_node][0]['format'];
}
}
break;
default:
if ($node_field == 'title') {
$entities[$term_field][$language_node][0]['value'] = $node->title;
$field[$term_field] = $entities[$term_field];
}
else {
$field[$term_field] = $node->{$node_field};
}
break;
}
return $field;
}