function tripal_example_node_insert

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

Implementation of hook node_insert().

Performs actions after any node has been inserted.

File

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

Code

function tripal_example_node_insert($node) {

  // EXPLANATION: This function is used after any a node is inserted into the
  // database. It is different from the hook_insert() function above in that it
  // is called after any node is saved, regardless of it's type. This function
  // is useful for making changes to the database after a node is inserted.
  // An example comes from the tripal_feature module where the URL alias of a
  // node cannot be set in the hook_insert() function. Therefore the
  // tripal_feature module uses this function to set the URL path of a newly
  // inserted example node.
  //
  // 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 do any activity after insert
  // of any node.

  // the Example code below will set the URL path after inserting. We do it here
  // because we do not know the example_id in the pre-save and cannot do it in
  // the hook_insert()
  switch ($node->type) {
    case 'chado_example':

      // find the example and add in the details
      $example_id = chado_get_id_from_nid('example', $nid);

      // build the example variable by using the chado_generate_var() function
      $values = array('example_id' => $example_id);
      $example = chado_generate_var('example', $values);
      $node->example = $example;


      // EXPLANATION: You can allow the site admin to customize the
      // title and URL of your node.  The 'Chado Node: Title & Path API'
      // contains two functions that can be called to generate the title and
      // URL based a schema provided by the site admin. These functions are
      // named chado_get_node_title() and chado_set_node_url().  These
      // functions use a string of tokens to build the URL and titles and the
      // site admin has the ability to set these tokens.  There are
      // form elements made available in the tripal_example_admin() function
      // that allow the admin to set these tokens.  The default token string
      // is provided to Tripal using two hook functions, and are found below.
      // These are: chado_exmaple_chado_node_default_title() and
      // chado_example_chdo_node_default_url().

      // Set the Title and URL for this node.
      $example->title = chado_get_node_title($node);
      chado_set_node_url($node);
      break;
  }
}