function tripal_stock_node_presave

2.x tripal_stock.chado_node.inc tripal_stock_node_presave($node)
3.x tripal_stock.chado_node.inc tripal_stock_node_presave($node)

Implements hook_node_presave(). Acts on all content types.

Related topics

File

legacy/tripal_stock/includes/tripal_stock.chado_node.inc, line 744
Stock Node Functionality

Code

function tripal_stock_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_stock':
      // 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.
      $organism_id = null;
      $sname = '';
      $uniquename = '';
      $type = '';
      if (property_exists($node, 'organism_id')) {
        $organism_id = $node->organism_id;
        $sname = $node->sname;
        $uniquename = $node->uniquename;
        $type_id = $node->type_id;
        $values = array('cvterm_id' => $node->type_id);
        $cvterm = chado_select_record('cvterm', array('name'), $values);
        $type = $cvterm[0]->name;
      }
      else if (property_exists($node, 'stock')) {
        $organism_id = $node->stock->organism_id;
        $sname = $node->stock->name;
        $uniquename = $node->stock->uniquename;
        $type = $node->stock->type_id->name;
      }
      $values = array('organism_id' => $organism_id);
      $organism = chado_select_record('organism', array('genus', 'species'), $values);
      $node->title = "$sname, $uniquename ($type) " . $organism[0]->genus . ' ' . $organism[0]->species;

      break;
  }
}