function tripal_organism_node_presave
2.x tripal_organism.chado_node.inc | tripal_organism_node_presave($node) |
3.x tripal_organism.chado_node.inc | tripal_organism_node_presave($node) |
Implements hook_node_presave(). Acts on all content types.
Parameters
$node: The node to be saved
Related topics
File
- tripal_organism/
includes/ tripal_organism.chado_node.inc, line 654 - Implements the organims node content type
Code
function tripal_organism_node_presave($node) {
switch ($node->type) {
// This step is for setting the title for the Drupal node. This title
// is permanent and thus is created to be unique. Title changes provided
// by tokens are generated on the fly dynamically, but the node title
// seen in the content listing needs to be set here. Do not call
// the chado_get_node_title() function here to set the title as the node
// object isn't properly filled out and the function will fail.
case 'chado_organism':
// when syncing the details are not present in the $node object
// as they are when submitted via the form. Therefore, if we do
// not see any field values from the form, we assume this fucntion
// is being called for syncing, so we must set the title accordingly
if (property_exists($node, 'genus')) {
$node->title = $node->genus . " " . $node->species;
if (property_exists($node, 'type_id')) {
$cvterm = tripal_get_cvterm(array('cvterm_id' => $node->type_id));
if ($cvterm) {
$node->title .= $cvterm->name . " " . $node->infraspecific_name;
}
}
}
elseif (property_exists($node, 'organism')) {
$node->title = $node->organism->genus . " " . $node->organism->species;
if (property_exists($node, 'type_id')) {
$node->title .= $node->organism->type_id->name . " " . $node->organism->infraspecific_name;
}
}
break;
}
}