commit 7272d19c9b15272fdf58a5b406646d4c97ab5c20
Author: Andreas Kohlbecker <a.kohlbecker@bgbm.org>
Date:   Mon Apr 18 14:30:06 2016 +0200

    refactoring: reducing amount of theme functions, functions moved into includes

diff --git a/modules/cdm_dataportal/cdm_dataportal.module b/modules/cdm_dataportal/cdm_dataportal.module
index 4ce02e07..f1cc37fb 100644
--- a/modules/cdm_dataportal/cdm_dataportal.module
+++ b/modules/cdm_dataportal/cdm_dataportal.module
@@ -1585,11 +1585,7 @@ function cdm_dataportal_name_view($taxon_name_uuid, $taxon_to_hide_uuid, $highli
     $taxon_name_page = new stdClass();
     $taxon_name_page->title = theme('cdm_name_page_title', array('taxon_name' => $taxon_name));
     if ($taxon_pager->records) {
-      $taxon_name_page->content = theme('cdm_list_of_taxa',
-        array(
-          'records'=> $taxon_pager->records
-        )
-      );
+      $taxon_name_page->content = compose_list_of_taxa($taxon_pager->records);
     }
     else {
       $taxon_name_page->content = 'This name has no taxa';
diff --git a/modules/cdm_dataportal/includes/pages.inc b/modules/cdm_dataportal/includes/pages.inc
index 254a7731..c7bad06f 100644
--- a/modules/cdm_dataportal/includes/pages.inc
+++ b/modules/cdm_dataportal/includes/pages.inc
@@ -486,7 +486,7 @@ function compose_cdm_taxon_page($taxon, $page_part = 'description') {
   $render_array['back_to_search'] = markup_to_render_array(theme('cdm_back_to_search_result_button'), -103);
 
   if (variable_get('cdm_dataportal_display_is_accepted_for', CDM_DATAPORTAL_DISPLAY_IS_ACCEPTED_FOR) && isset($_REQUEST['acceptedFor'])) {
-    $render_array['accepted_for'] = markup_to_render_array(theme('cdm_acceptedFor', array('acceptedFor' => $_REQUEST['acceptedFor'])), $weight++);
+    $render_array['accepted_for'] = markup_to_render_array(cdm_accepted_for($_REQUEST['acceptedFor']), $weight++);
   }
 
   // --- PAGE PART: DESCRIPTION --- //
diff --git a/modules/cdm_dataportal/theme/cdm_dataportal.page.theme b/modules/cdm_dataportal/theme/cdm_dataportal.page.theme
index cd55fb78..362759d4 100644
--- a/modules/cdm_dataportal/theme/cdm_dataportal.page.theme
+++ b/modules/cdm_dataportal/theme/cdm_dataportal.page.theme
@@ -272,13 +272,7 @@ function theme_cdm_search_results($variables)
   // List results.
   if (isset($pager->records) && count($pager->records) > 0) {
     $out .= '<div id="search_results">';
-    $out .= theme('cdm_list_of_taxa',
-        array(
-          'records' => $pager->records,
-          'freetextSearchResults' => $freetextSearchResults,
-          'show_classification' => $classification === NULL
-        )
-      );
+    $out .= drupal_render(compose_list_of_taxa($pager->records, $freetextSearchResults, $classification === NULL));
     $out .= '</div>';
     $out .= theme('cdm_pager', array(
         'pager' => $pager,
diff --git a/modules/cdm_dataportal/theme/cdm_dataportal.taxon.theme b/modules/cdm_dataportal/theme/cdm_dataportal.taxon.theme
index d1727716..6e40aad7 100644
--- a/modules/cdm_dataportal/theme/cdm_dataportal.taxon.theme
+++ b/modules/cdm_dataportal/theme/cdm_dataportal.taxon.theme
@@ -14,11 +14,12 @@
  */
 
 /**
- * @todo Please document this function.
- * @see http://drupal.org/node/1354
+ * Creates markup for a taxon which is the accepted of another one
+ *
+ * @param $accepted_for_uuid
+ *   The uuid of the accepted taxon
  */
-function theme_cdm_acceptedFor($variables) {
-  $accepted_for_uuid = $variables['acceptedFor'];
+function cdm_accepted_for($accepted_for_uuid) {
 
   if(!is_uuid($accepted_for_uuid)){
     return '';
@@ -43,29 +44,28 @@ function theme_cdm_acceptedFor($variables) {
 }
 
 /**
- * @todo document this function.
+ * Compose function for a list of taxa.
+ *
+ * This function is for example used toi display search results or the taxa for a taxon name in the name page.
+ *
+ * @param $taxon_list array
+ *   The list of CDM Taxon entities. e.g. The records array as contained in a pager object.
+ * @param $freetext_search_results array
+ * @param $show_classification boolean
+ *
+ * @ingroup compose
+ *
  */
-function theme_cdm_list_of_taxa($variables) {
+function compose_list_of_taxa($taxon_list, $freetext_search_results = array(), $show_classification = false) {
 
   $unclassified_snippet = '<span class="unclassified">' . t('unclassified') . '</span>';
 
-  $records = $variables['records'];
-  $freetextSearchResults = $variables['freetextSearchResults'];
-  $show_classification = $variables['show_classification'];
-
   RenderHints::pushToRenderStack('list_of_taxa');
 
-  $form_name = 'search_gallery';
-  // $default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
-  // $gallery_settings = variable_get($form_name, $default_values);
   $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SEARCH_GALLERY_NAME);
 
   $showMedia_taxa = $gallery_settings['cdm_dataportal_show_taxon_thumbnails'];
   $showMedia_synonyms = $gallery_settings['cdm_dataportal_show_synonym_thumbnails'];
-  // $showMedia_taxa =
-  // variable_get('cdm_dataportal_findtaxa_show_taxon_thumbnails', 1);
-  // $showMedia_synonyms =
-  // variable_get('cdm_dataportal_findtaxa_show_synonym_thumbnails', 0);
   $searched_in_classification = cdm_dataportal_searched_in_classification();
   $searched_in_classification_uuid = null;
   if(isset($searched_in_classification->uuid)){
@@ -75,7 +75,7 @@ function theme_cdm_list_of_taxa($variables) {
   // .. Well, for sure not as performant as before, but better than nothing.
   $synonym_uuids = array();
   $misappied_uuids = array();
-  foreach ($records as $taxon) {
+  foreach ($taxon_list as $taxon) {
     if ($taxon->class == "Synonym") {
       if (!array_key_exists($taxon->uuid, $synonym_uuids)) {
         $synonym_uuids[$taxon->uuid] = $taxon->uuid;
@@ -113,7 +113,7 @@ function theme_cdm_list_of_taxa($variables) {
 
   $out = '<ul class="cdm_names" style="background-image: none;">';
   $itemCnt = -1;
-  foreach ($records as $taxon) {
+  foreach ($taxon_list as $taxon) {
     $itemCnt++;
     if (isset($table_of_accepted[$taxon->uuid])) {
       // Its a synonym or misapplied name.
@@ -205,16 +205,16 @@ function theme_cdm_list_of_taxa($variables) {
      * WildcardQueries, since these are  constant score by default
      * since Lucene 2.9
      */
-    if(isset($freetextSearchResults[$itemCnt]) && $freetextSearchResults[$itemCnt]->score && $freetextSearchResults[$itemCnt]->maxScore){
-      $percentage =  ( $freetextSearchResults[$itemCnt]->score / $freetextSearchResults[$itemCnt]->maxScore ) * 100;
+    if(isset($freetext_search_results[$itemCnt]) && $freetext_search_results[$itemCnt]->score && $freetext_search_results[$itemCnt]->maxScore){
+      $percentage =  ( $freetext_search_results[$itemCnt]->score / $freetext_search_results[$itemCnt]->maxScore ) * 100;
       $out .= '<div class="score-bar"><div class="score-bar-indicator" style="width:' . $percentage .'% "></div></div>';
       $out .= '<div class="score-bar-value">' . number_format($percentage, 2) .'%</div>';
     }
 
     // Render highlighted fragments, these are made available by free text
     // searches.
-    if (isset($freetextSearchResults[$itemCnt]->fieldHighlightMap)) {
-      $field_fragments = (array) $freetextSearchResults[$itemCnt]->fieldHighlightMap;
+    if (isset($freetext_search_results[$itemCnt]->fieldHighlightMap)) {
+      $field_fragments = (array) $freetext_search_results[$itemCnt]->fieldHighlightMap;
       if (count($field_fragments) > 0) {
         $fragments_out = '';
         foreach ($field_fragments as $fieldName => $fragments) {
@@ -230,7 +230,7 @@ function theme_cdm_list_of_taxa($variables) {
   $out .= '</ul>';
   RenderHints::popFromRenderStack();
 
-  return $out;
+  return markup_to_render_array($out); // TODO create render array of all list items in function
 }
 
   /**
diff --git a/modules/cdm_dataportal/theme/theme_registry.inc b/modules/cdm_dataportal/theme/theme_registry.inc
index bc859631..7faf59b8 100644
--- a/modules/cdm_dataportal/theme/theme_registry.inc
+++ b/modules/cdm_dataportal/theme/theme_registry.inc
@@ -173,8 +173,6 @@ function cdm_dataportal_theme() {
         'pager' => NULL,
         'path' => NULL
     )),
-    'cdm_acceptedFor' => array('variables' => array('acceptedFor' => NULL)),
-    'cdm_list_of_taxa' => array('variables' => array('records' => NULL, 'freetextSearchResults' => array(), 'show_classification' => FALSE)),
     'cdm_taxon_list_thumbnails' => array('variables' => array('taxon' => NULL)),
 
     // Themes in includes/pre-drupal8.inc
diff --git a/themes/palmweb_2/template.php b/themes/palmweb_2/template.php
index f711139c..5708de3e 100755
--- a/themes/palmweb_2/template.php
+++ b/themes/palmweb_2/template.php
@@ -123,7 +123,7 @@ function palmweb_2_cdm_search_results($variables){
   $out .= '> ' . t('Show Image Thumbnails') . '</form></div>';
   if (!empty($pager) && count($pager->records) > 0) {
       $out .= '<div id="search_results">';
-    $out .= theme('cdm_list_of_taxa', array('records' => $pager->records));
+    $out .= drupal_render(compose_list_of_taxa($pager->records));
     $out .= '</div>';
     $out .= theme('cdm_pager', array(
       'pager' => $pager,
