|
@@ -552,47 +552,82 @@ function tripal_core_views_api() {
|
|
|
*/
|
|
|
function tripal_core_node_view_alter(&$build) {
|
|
|
global $theme;
|
|
|
+
|
|
|
+ // if the $build['tripal_toc'] element is not present, then this is not
|
|
|
+ // a full node view so we do not want to alter
|
|
|
+ if (!array_key_exists('tripal_toc', $build)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
$cache = cache_get("theme_registry:$theme", 'cache');
|
|
|
$node = $build['#node'];
|
|
|
$toc = array();
|
|
|
$toc_html = '';
|
|
|
|
|
|
- //dpm($build);
|
|
|
-
|
|
|
// if we are looking at a Tripal node template then we want to
|
|
|
// make some changes to each block of content so that we can associate
|
|
|
// a table of contents and add administrator and curator messages
|
|
|
if (preg_match('/chado_/', $node->type)) {
|
|
|
|
|
|
// iterate through all the elements of the $build array and for those
|
|
|
- // with a '#value' add some extra <div> tags
|
|
|
+ // that are wanting to provide content for this node
|
|
|
+ $markup_list = array();
|
|
|
foreach ($build as $key => $value) {
|
|
|
|
|
|
- // only examine elements without a '#' prefix and that are not the
|
|
|
- // tripal table of contents and that have a #value element
|
|
|
- if (!preg_match('/^#/', $key) and $key != 'tripal_toc' and
|
|
|
- array_key_exists('#value', $build[$key]) and trim($build[$key]['#value'])) {
|
|
|
+ // examine elements without a '#' prefix as these should be adding
|
|
|
+ // contents to the page. Skip the table of contents and any teasers
|
|
|
+ if (!preg_match('/^#/', $key) and $key != 'tripal_toc') {
|
|
|
|
|
|
+ // find the markup. Some fields will have a '#markup' and others, such
|
|
|
+ // as CCK elements may have a set of '#markup' elements organized by
|
|
|
+ // numerical keys.
|
|
|
+ if (array_key_exists('#markup', $build[$key]) and trim($build[$key]['#markup'])) {
|
|
|
+ $markup_list[$key][] = $build[$key]['#markup'];
|
|
|
+ }
|
|
|
+ // For backwards copmatibility we should support the '#value' element as well.
|
|
|
+ elseif (array_key_exists('#value', $build[$key]) and trim($build[$key]['#value'])) {
|
|
|
+ $markup_list[$key][] = $build[$key]['#markup'];
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ // we don't have a '#markup' field so look to see if this is a CCK
|
|
|
+ // element with numerical fields and a '#markup' inside
|
|
|
+ foreach ($value as $subkey => $subvalue) {
|
|
|
+ if (is_array($subvalue) and array_key_exists('#markup', $value[$subkey]) and trim($value[$subkey]['#markup'])) {
|
|
|
+ $markup_list[$key][] = $value[$subkey]['#markup'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // if we have markup for this node then format it for display with Tripal
|
|
|
+ // basically, we just wrap it with a container, give it a title, and
|
|
|
+ // build the table of contents for the page. The user theme can handle
|
|
|
+ // how to display it. The default tripal node template will handle it
|
|
|
+ // by default.
|
|
|
+ foreach ($markup_list as $key => $markup) {
|
|
|
+ foreach ($markup as $i => $html_text) {
|
|
|
+ $is_teaser = FALSE;
|
|
|
+
|
|
|
// intialize the item title, key and id
|
|
|
$toc_item_title = $key;
|
|
|
$toc_item_id = $key;
|
|
|
$toc_item_link = '';
|
|
|
|
|
|
-
|
|
|
// BUILD THE TEMPLATE PATH
|
|
|
// get the template path so we can put it in an admin message box
|
|
|
$path = '';
|
|
|
if (array_key_exists($key, $cache->data) and array_key_exists('path', $cache->data[$key])) {
|
|
|
|
|
|
$path = $cache->data[$key]['path'] . '/' . $key . '.tpl.php';
|
|
|
+
|
|
|
$path = theme('tripal_admin_message', array('message' => "Administrators, you can
|
|
|
- customize the way the content above is presented. Tripal provides a template
|
|
|
- file for each block of content. To customize, copy the template file to your
|
|
|
- site's default theme, edit then " .
|
|
|
+ customize the way the content above is presented. Tripal provides a template
|
|
|
+ file for each block of content. To customize, copy the template file to your
|
|
|
+ site's default theme, edit then " .
|
|
|
l('clear the Drupal cache', 'admin/config/development/performance', array('attributes' => array('target' => '_blank'))) . ".
|
|
|
- Currently, the content above is provided by this template: <br><br>$path
|
|
|
- "));
|
|
|
+ Currently, the content above is provided by this template: <br><br>$path")
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
// BUILD THE TOC LINKS
|
|
@@ -604,6 +639,14 @@ function tripal_core_node_view_alter(&$build) {
|
|
|
if (array_key_exists('#tripal_toc_id', $build[$key])) {
|
|
|
$toc_item_id = $build[$key]['#tripal_toc_id'];
|
|
|
}
|
|
|
+
|
|
|
+ // for any content items that have more than one entry (such
|
|
|
+ // as CCK fields with unlimited values, we want to add the index to the
|
|
|
+ // id
|
|
|
+ if($i > 0) {
|
|
|
+ $toc_item_id .= '-' . $i;
|
|
|
+ $toc_item_title .= '-' . $i;
|
|
|
+ }
|
|
|
$toc_item_link = "<div class=\"tripal_toc_list_item\"><a id=\"$toc_item_id\" class=\"tripal_toc_list_item_link\" href=\"?block=$toc_item_id\">$toc_item_title</a></div>";
|
|
|
|
|
|
// next check the database. If the title has been overridden then
|
|
@@ -613,31 +656,39 @@ function tripal_core_node_view_alter(&$build) {
|
|
|
$weight = $build[$key]['#weight'];
|
|
|
}
|
|
|
$toc[$weight][] = $toc_item_link;
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
// CREATE THE DATA BLOCK
|
|
|
// add a surrounding <div> box around the content
|
|
|
- $build[$key]['#value'] = "
|
|
|
+ $updated_markup = "
|
|
|
<div id=\"$toc_item_id-tripal-data-block\" class=\"tripal-data-block\">
|
|
|
- <div class=\"$toc_item_id-tripal-data-block-title tripal-data-block-title\">$toc_item_title</div> " .
|
|
|
- $build[$key]['#value'] . "
|
|
|
+ <div class=\"$toc_item_id-tripal-data-block-title tripal-data-block-title\">$toc_item_title</div>
|
|
|
+ $html_text
|
|
|
$path
|
|
|
</div>
|
|
|
</div>
|
|
|
";
|
|
|
+
|
|
|
+ // subtitute back in the #markup into the correct field.
|
|
|
+ if (array_key_exists($i, $build[$key])) {
|
|
|
+ $build[$key][$i]['#markup'] = $updated_markup;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ $build[$key]['#markup'] = $updated_markup;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- // BUILD THE TABLE OF CONTENTS LINKS
|
|
|
- $toc_html = '';
|
|
|
- ksort($toc, SORT_NUMERIC);
|
|
|
- foreach ($toc as $weight => $links) {
|
|
|
- foreach ($links as $index => $toc_item_link) {
|
|
|
- $toc_html .= $toc_item_link;
|
|
|
- }
|
|
|
+ }
|
|
|
+
|
|
|
+ // BUILD THE TABLE OF CONTENTS LINKS
|
|
|
+ $toc_html = '';
|
|
|
+ ksort($toc, SORT_NUMERIC);
|
|
|
+ foreach ($toc as $weight => $links) {
|
|
|
+ foreach ($links as $index => $toc_item_link) {
|
|
|
+ $toc_html .= $toc_item_link;
|
|
|
}
|
|
|
- $build['tripal_toc']['#value'] = "<div id=\"$node->type-tripal-toc-block\" class=\"tripal-toc-block\">$toc_html</div>";
|
|
|
}
|
|
|
+ $build['tripal_toc']['#markup'] = "<div id=\"$node->type-tripal-toc-block\" class=\"tripal-toc-block\">$toc_html</div>";
|
|
|
+
|
|
|
//dpm($cache);
|
|
|
//dpm($build);
|
|
|
}
|
|
@@ -655,7 +706,7 @@ function tripal_core_node_view($node, $view_mode, $langcode) {
|
|
|
// Show feature browser and counts
|
|
|
if ($view_mode == 'full') {
|
|
|
$node->content['tripal_toc'] = array(
|
|
|
- '#value' => "<div id=\"$node->type-tripal-toc-block\" class=\"tripal-toc-block\"></div>",
|
|
|
+ '#markup' => "<div id=\"$node->type-tripal-toc-block\" class=\"tripal-toc-block\"></div>",
|
|
|
);
|
|
|
}
|
|
|
}
|