function tripal_analysis_node_presave

2.x tripal_analysis.chado_node.inc tripal_analysis_node_presave($node)
3.x tripal_analysis.chado_node.inc tripal_analysis_node_presave($node)

Implements hook_node_presave(). Called for all node types.

Related topics

File

tripal_analysis/includes/tripal_analysis.chado_node.inc, line 695
Implements Drupal Node hooks to create the chado_analysis node content type.

Code

function tripal_analysis_node_presave($node) {
  $name = '';
  $program = '';
  $programversion = '';
  $sourcename = '';

  // 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.

  // If this is an analysis of some type it will should have three required
  // fields for the Chado analysis table: program, programversion and sourcename.
  // So we will set the title for any node that has these three fields. Some extension
  // modules will use this module as a type of "inherited" class, so we don't know
  // for sure when type of analysis we have.  If this is a sync then
  if (property_exists($node, 'program') and 
    property_exists($node, 'programversion') and 
    property_exists($node, 'sourcename')) {
    $name = $node->analysisname;
    $program = $node->program;
    $programversion = $node->programversion;
    $sourcename = $node->sourcename;
    // now construct the title
    $node->title = "$program ($programversion) $sourcename";
    if ($name) {
      $node->title = $name;
    }
    // reset the type
    //$node->type = $node->analysis_type;
  }
  else if (property_exists($node, 'analysis')) {
    $name = $node->analysis->name;
    $program = $node->analysis->program;
    $programversion = $node->analysis->programversion;
    $sourcename = $node->analysis->sourcename;
    // now construct the title
    $node->title = "$program ($programversion) $sourcename";
    if ($name) {
      $node->title = $name;
    }
    //$node->type = $node->analysis_type;
  }
}