commit 4feafea8403142f30c31c0a612b0b2a2de1f76bf
Author: Andreas Kohlbecker <a.kohlbecker@bgbm.org>
Date:   Tue Jan 31 14:02:54 2017 +0100

    fix #6374 fixing messed up UUIDs and harmonizing use descriptions block creation

diff --git a/modules/cdm_dataportal/cdm_api/uuids.php b/modules/cdm_dataportal/cdm_api/uuids.php
index a9eafc81..3e56ef01 100644
--- a/modules/cdm_dataportal/cdm_api/uuids.php
+++ b/modules/cdm_dataportal/cdm_api/uuids.php
@@ -89,6 +89,10 @@
   define('UUID_CITATION', '99b2842f-9aa7-42fa-bd5f-7285311e0101');
   define('UUID_ADDITIONAL_PUBLICATION', 'cb2eab09-6d9d-4e43-8ad2-873f23400930');
   define('UUID_USES', 'e5374d39-b210-47c7-bec1-bee05b5f1cb6');
+  define('UUID_USE_SUMMARY', 'e6bd0bb0-7b1a-11e0-819a-0800200c9a66');
+  define('UUID_USE', '6acb0348-c070-4512-a37c-67bcac016279');
+  define('UUID_USE_RECORD', '8125a59d-b4d5-4485-89ea-67306297b599');
+
   define('UUID_CONSERVATION', '4518fc20-2492-47de-b345-777d2b83c9cf');
   define('UUID_CULTIVATION', 'e28965b2-a367-48c5-b954-8afc8ac2c69b');
   define('UUID_INTRODUCTION', 'e75255ca-8ff4-4905-baad-f842927fe1d3');
@@ -101,8 +105,6 @@
   define('UUID_CHROMOSOMES', 'c4a60319-4978-4692-9545-58d60cf8379e');
   define('UUID_CHROMOSOMES_NUMBERS', '6f677e98-d8d5-4bc5-80bf-affdb7e3945a');
 
-  define('UUID_USE_RECORD', 'e5374d39-b210-47c7-bec1-bee05b5f1cb6');
-  define('UUID_USE', '6acb0348-c070-4512-a37c-67bcac016279');
 
   // SpecimenTypeDesignationStatus.
   define('UUID_STD_HOLOTYPE', 'a407dbc7-e60c-46ff-be11-eddf4c5a970d');
diff --git a/modules/cdm_dataportal/includes/descriptions.inc b/modules/cdm_dataportal/includes/descriptions.inc
index 4edfd6c3..a54fd07f 100644
--- a/modules/cdm_dataportal/includes/descriptions.inc
+++ b/modules/cdm_dataportal/includes/descriptions.inc
@@ -685,6 +685,8 @@ function handle_annotations_and_sources_config($feature_block_settings){
 
     $gallery_settings = getGallerySettings(CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME);
 
+    $use_description_features = array(UUID_USE);
+
 
     RenderHints::pushToRenderStack('feature_block');
     // Create a drupal block for each feature
@@ -703,6 +705,14 @@ function handle_annotations_and_sources_config($feature_block_settings){
         $block->content = array();
         $block_content_is_empty = TRUE;
 
+        if(array_search($node->feature->uuid, $use_description_features) !== false) {
+          // do not show features which belong to the UseDescriptions, these are
+          // handled by theme_cdm_block_Uses where the according descriptions are
+          // fetched again separately.
+          // UseDescriptions are a feature special to palmweb
+          continue;
+        }
+
         /*
          * Content/DISTRIBUTION.
          */
@@ -710,6 +720,7 @@ function handle_annotations_and_sources_config($feature_block_settings){
           $block = compose_feature_block_distribution($taxon, $node->descriptionElements, $node->feature);
           $block_content_is_empty = FALSE;
         }
+
         /*
          * Content/COMMON_NAME.
          */
@@ -719,9 +730,11 @@ function handle_annotations_and_sources_config($feature_block_settings){
           $block_content_is_empty = FALSE;
         }
 
+        /*
+         * Contend/Use Description (Use + UseRecord)
+         */
         else if ($node->feature->uuid == UUID_USE_RECORD) {
-          $block_uses_content_html = theme('cdm_block_Uses', array('taxonUuid' => $taxon->uuid));
-          $block->content[] = markup_to_render_array($block_uses_content_html);
+          $block->content[] = cdm_block_use_description_content($taxon->uuid);
           $block_content_is_empty = FALSE;
         }
 
@@ -1752,11 +1765,11 @@ function compose_description_elements_distribution($description_elements){
   /**
    * Provides the merged feature tree for a taxon profile page.
    *
-   * The merging of the profile feature tree is actully done in
+   * The merging of the profile feature tree is actually done in
    * _mergeFeatureTreeDescriptions(). See this method  for details
    * on the structure of the merged tree.
    *
-   * This method provides t hook which can be used to modify the
+   * This method provides a hook which can be used to modify the
    * merged feature tree after it has been created, see
    * hook_merged_taxon_feature_tree_alter()
    *
diff --git a/modules/cdm_dataportal/theme/cdm_dataportal.descriptions.theme b/modules/cdm_dataportal/theme/cdm_dataportal.descriptions.theme
index abd0528f..3b02c669 100644
--- a/modules/cdm_dataportal/theme/cdm_dataportal.descriptions.theme
+++ b/modules/cdm_dataportal/theme/cdm_dataportal.descriptions.theme
@@ -363,14 +363,18 @@ function theme_cdm_block_IdentificationKeys($variables) {
  * @see http://drupal.org/node/1354
  */
 function theme_cdm_UseDescription($variables) {
+
+
+  RenderHints::pushToRenderStack('block_Uses');
+
   $descriptions = $variables['description'];
   $taxonUuid = $variables['taxonUuid'];
-  $out = '<div id="content"><ul id="Description" class ="description">';
+  $out = '<ul id="Description" class ="description">';
   if ($descriptions == NULL) {
-    return;
+    return '';
   }
 
-  $feature_block_settings = get_feature_block_settings(UUID_DISTRIBUTION);
+  $feature_block_settings = get_feature_block_settings(UUID_DISTRIBUTION); //FIXME wrong UUID here
 
   $descriptionSynonyms = '';
   $descriptionOut = '';
@@ -478,36 +482,37 @@ function theme_cdm_UseDescription($variables) {
   }
   $out .= $descriptionOut . $synonymOut;
   $out .= "</ul></div>";
+
+  RenderHints::popFromRenderStack();
+
   return $out;
 }
 
 
 /**
- * The theming function for a block of Uses Descriptions for a given taxon.
+ * Provides the content for a block of Uses Descriptions for a given taxon.
+ *
+ * Fetches the list of TaxonDescriptions tagged with the MARKERTYPE_USE
+ * and passes them to the theme function theme_cdm_UseDescription().
  *
- * The Uses block has been removed from the code but the according theme function
- * is kept for compatibility reasons with existing code regarding palmweb.
+ * @param string $taxon_uuid
+ *   The uuid of the Taxon
  *
+ * @return array
+ *   A drupal render array
  */
-function theme_cdm_block_Uses($variables) {
-  $taxonUuid = $variables['taxonUuid'];
-  RenderHints::pushToRenderStack('block_Uses');
+function cdm_block_use_description_content($taxon_uuid) {
 
-  if ($taxonUuid == NULL) {
-    return;
-  }
-  $out = '';
-  $markerTypes = array();
-  $markerTypes['markerTypes'] = UUID_MARKERTYPE_USE;
-  $useDescriptions = cdm_ws_fetch_all(CDM_WS_PORTAL_TAXON . '/' . $taxonUuid . '/descriptions', $markerTypes);
-  if (!empty($useDescriptions)) {
-    // FIXME use theme_block instaed of hardcoding the block html here !!!!
-    $out .= '<div id="block-cdm_dataportal-feature-description" class="clear-block block block-cdm_dataportal-feature"><H2><a name="userecords"> </a> Uses </H2>';
-    $formatUseDescriptions = theme('cdm_UseDescription', array('description' => $useDescriptions, 'taxonUuid' => $taxonUuid));
-
-    $out .= $formatUseDescriptions;
-    $out .= "</div>";
+  $use_description_content = '';
+
+  if (is_uuid($taxon_uuid )) {
+    $markerTypes = array();
+    $markerTypes['markerTypes'] = UUID_MARKERTYPE_USE;
+    $useDescriptions = cdm_ws_fetch_all(CDM_WS_PORTAL_TAXON . '/' . $taxon_uuid . '/descriptions', $markerTypes);
+    if (!empty($useDescriptions)) {
+      $use_description_content = theme('cdm_UseDescription', array('description' => $useDescriptions, 'taxonUuid' => $taxon_uuid));
+    }
   }
 
-  return $out;
+  return markup_to_render_array($use_description_content);
 }
diff --git a/modules/cdm_dataportal/theme/theme_registry.inc b/modules/cdm_dataportal/theme/theme_registry.inc
index 87f27b4c..305e7de7 100644
--- a/modules/cdm_dataportal/theme/theme_registry.inc
+++ b/modules/cdm_dataportal/theme/theme_registry.inc
@@ -81,7 +81,6 @@ function cdm_dataportal_theme() {
     'cdm_list_IdentificationKeys' => array('variables' => array('type' => NULL, 'taxonUuid' => NULL)),
     'cdm_block_IdentificationKeys' => array('variables' => array('taxonUuid' => NULL)),
     'cdm_UseDescription' => array('variables' => array('description' => NULL, 'taxonUuid' => NULL)),
-    'cdm_block_Uses' => array('variables' => array('taxonUuid' => NULL)),
 
     // Themes in cdm_dataportal.media.theme.
     'cdm_media_mime_application' => array('variables' => array('mediaRepresentation' => NULL, 'feature' => NULL)),
