function chado_example_load

2.x chado_example_load($nodes)

Implementation of hook_load(). This function is necessary to load into the $node object the fields of the table form Chado. For example for the example table, the chado_example_load() function adds in a example object which contains all of the fields and sub objects for data in tables with foreign key relationships.

This function is not required if the hook_node_info() does not define any custom node types.


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


function chado_example_load($nodes) {

  // EXPLANATION: when displaying or node or accessing the node in a template
  // we need the data from Chado. This function finds the record in Chado that
  // this node belongs to and adds the record.

  // there may be multiple nodes that get passed in so we have to iterate
  // through them all
  foreach ($nodes as $nid => $node) {
    // find the example and add in the details
    $example_id = chado_get_id_from_nid('example', $nid);

    // if the nid does not have a matching record then skip this node.
    // this can happen with orphaned nodes.
    if (!$example_id) {

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

    // for fields in the table that are of type 'text' you may want to include
    // those by default, the chado_generate_var does not include text fields as
    // they may be very large and including a large text field can slow the page
    // load.
    // If you know a text field will never be large and it is important for the
    // other functions that will see the node to have access to a field you can
    // include it here using the chado_expand_var() function. In most
    // cases it is probably best to let the end-user decide if text fields
    // should be included by using this function in the templates.
    $example = chado_expand_var($example, 'field', 'example.description');

    // add the new example object to this node.
    $nodes[$nid]->example = $example;

    // If your module is using the Chado Node: Title & Path API to allow custom
    // titles for your node type. Every time you want the title of the node, you
    // need to use the following API function:
    $node->title = chado_get_node_title($node);