function tripal_feature_node_presave

2.x tripal_feature.chado_node.inc tripal_feature_node_presave($node)
3.x tripal_feature.chado_node.inc tripal_feature_node_presave($node)

Implements hook_node_presave(). Acts on all content types.

Related topics

File

tripal_feature/includes/tripal_feature.chado_node.inc, line 747
Implementation of hooks to create a feature content type

Code

function tripal_feature_node_presave($node) {

  // set the title to ensure it is always unique
  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_feature':
      // for a form submission the fields are part of the node object
      // but for a sync the fields are in an object of the node
      $name = '';
      $uname = '';
      $type = '';
      $organism_id = null;
      if (property_exists($node, 'uniquename')) {
        $organism_id = $node->organism_id;
        $name = $node->name;
        $uname = $node->uniquename;
        $type = $node->feature_type;
      }
      else if (property_exists($node, 'feature')) {
        $organism_id = $node->feature->organism_id;
        $name = $node->feature->name;
        $uname = $node->feature->uniquename;
        $type = $node->feature->cvtname;
      }

      $values = array('organism_id' => $organism_id);
      $organism = chado_select_record('organism', array('genus', 'species'), $values);
      $node->title = "$name, $uname ($type) " . $organism[0]->genus . ' ' . $organism[0]->species;

      break;
  }
}