function tripal_example_node_presave

2.x tripal_example.chado_node.inc tripal_example_node_presave($node)

Implementation of hook_node_presave().

Performs actions on a node object prior to it being saved

File

tripal_example/includes/tripal_example.chado_node.inc, line 634
This file should contain all Drupal hooks for interacting with nodes.

Code

function tripal_example_node_presave($node) {

  // EXPLANATION: This node is useful for making changes to the node prior to it
  // being saved to the database.
  // One useful case for this is to set the title of a node using values
  // supplied by the user.
  //
  // This function is not required. You probably won't need it if you don't
  // define a custom node type in the hook_node_info() function. But it is node
  // type agnostic, so you can use this function to change the contents of any
  // node regardless of it's type.

  // set the node title
  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_example':
      // for a form submission the 'uniquename' field will be set,
      // for a sync, we must pull from the example object
      if (property_exists($node, 'uniquename')) {
        // set the title
        $node->title = $node->uniquename;
      }
      else if (property_exists($node, 'example')) {
        $node->title = $node->example->uniquename;
      }
      break;
  }
}