function tripal_pub_node_presave

2.x tripal_pub.chado_node.inc tripal_pub_node_presave($node)
3.x tripal_pub.chado_node.inc tripal_pub_node_presave($node)

Implements hook_node_presave(). Acts on all content types.

Related topics

File

legacy/tripal_pub/includes/tripal_pub.chado_node.inc, line 1239
Implements Drupal Node hooks to create the chado_analysis node content type.

Code

function tripal_pub_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_pub':
      // 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, 'title')) {
        // do nothing, the title is set
      }
      else if (property_exists($node, 'pub')) {
        // in Drupal a node title can only be 255 characters so we truncate
        // it just in case
        $node->title = substr($node->pub->title, 0, 255);
      }
      break;
  }
}