function tripal_example_node_view
2.x tripal_example.chado_node.inc | tripal_example_node_view($node, $view_mode, $langcode) |
Implementation of hook_node_view().
File
- tripal_example/
includes/ tripal_example.chado_node.inc, line 770 - This file should contain all Drupal hooks for interacting with nodes.
Code
function tripal_example_node_view($node, $view_mode, $langcode) {
// EXPLANATION: This function defines the content "blocks" that appear when
// the node is displayed. It is node type agnostic so we can add content to
// any node type. So, we use this function to add the content from all of our
// theme templates onto our new node type. We will also use this function to
// add content to other node types.
switch ($node->type) {
case 'chado_example':
// there are different ways a node can be viewed. Primarily Tripal
// supports full page view and teaser view.
if ($view_mode == 'full') {
// If you want to use the default Tripal node template then you need to
// tell Tripal to generate the Table of Contents. This is done by
// setting the following to TRUE. If your content type follows the
// chado_<base table> convention then this is the default. In this case
// if you don't want to use the default template then you need to set
// the following to FALSE.
$node->content['#tripal_generic_node_template'] = TRUE;
// There is always a base template. This is the template that is first
// shown when the example node type is first displayed.
// If you are using the default Tripal node template, then you should
// also set two additional items in each array: tripal_toc_id and
// tripal_toc_title. The tripal_tock_id should be a single unique
// world that is used to reference the template. This ID is used for
// constructing URLs for the content. The tripal_toc_title contains
// the title that should appear in the table of contents for this
// content. You should only set the '#weight' element for the base
// template (or Overview) to ensure that it appears at the top of the
// list. Otherwise items are sorted alphabetically.
$node->content['tripal_example_base'] = array(
'#theme' => 'tripal_example_base',
'#node' => $node,
'#tripal_toc_id' => 'base',
'#tripal_toc_title' => 'Overview',
'#weight' => -100,
);
// we can add other templates as well for properties, publications,
// dbxrefs, etc...
$node->content['tripal_example_properties'] = array(
'#theme' => 'tripal_example_properties',
'#node' => $node,
'#tripal_toc_id' => 'properties',
'#tripal_toc_title' => 'Properties',
);
$node->content['tripal_example_references'] = array(
'#theme' => 'tripal_example_references',
'#node' => $node,
'#tripal_toc_id' => 'references',
'#tripal_toc_title' => 'Cross References',
);
$node->content['tripal_example_relationships'] = array(
'#theme' => 'tripal_example_relationships',
'#node' => $node,
'#tripal_toc_id' => 'relationships',
'#tripal_toc_title' => 'Relationships',
);
// Note: if you create a template that you do not want a user to know
// where it is (discourage editing of it), you can add the following
// key: '#tripal_template_show' => FALSE. If this key/value is set the
// administrator message that Tripal provides indicating where the
// template is housed will not be shown.
}
// set the content for the teaser view
if ($view_mode == 'teaser') {
// The teaser is also a required template
$node->content['tripal_example_teaser'] = array(
'#theme' => 'tripal_example_teaser',
'#node' => $node,
);
}
break;
// you can add custom content to any node type by adding content to the node
// in the same way as above.
case 'chado_organism':
if ($view_mode == 'full') {
$node->content['tripal_organism_examples'] = array(
'#theme' => 'tripal_organism_examples',
'#node' => $node,
'#tripal_toc_id' => 'examples',
'#tripal_toc_title' => 'Examples',
);
}
break;
// ... etc
}
}