commit daef68e94e5ad40fb7fb395f818822ee1ff3c5ee
Author: Andreas Kohlbecker <a.kohlbecker@bgbm.org>
Date:   Thu Dec 15 15:10:49 2016 +0100

    fix #6260 fixing display of rights on image page

diff --git a/modules/cdm_dataportal/includes/media.inc b/modules/cdm_dataportal/includes/media.inc
index 11800ccf..3ad0b166 100644
--- a/modules/cdm_dataportal/includes/media.inc
+++ b/modules/cdm_dataportal/includes/media.inc
@@ -28,8 +28,8 @@
  *   the render array of the groups for the HTML description list
  */
 function cdm_rights_as_dl_groups($rights_list) {
-
   $copyrights = array();
+
   $licenses = array();
   $access_rights = array();
   $unknown = array();
@@ -42,13 +42,15 @@ function cdm_rights_as_dl_groups($rights_list) {
     switch ($type_uuid) {
 
       case UUID_RIGHTS_COPYRIGHT:
-        if (isset($right->agent[0]) ){
-          $agent_names = array();
-          foreach ($right->agent as $agent) {
-            $agent_names[] = $agent->titleCache;
-          }
-          $copyrights[] = implode(', ', $agent_names);
+        $text = '';
+        if (isset($right->text) ){
+          // sanitize potential '(c)' away
+          $text  = preg_replace('/^\(c\)/', '', $right->text);
+        } if (isset($right->agent) ){
+          $text  .= (strlen($text) > 0 ? ', ' : '') . $right->agent;
         }
+
+        $copyrights[] = array('#markup' => '&copy; ' . $text);
         break;
 
       case UUID_RIGHTS_LICENCE:
@@ -67,30 +69,30 @@ function cdm_rights_as_dl_groups($rights_list) {
         if (strlen($license_str) > 0 && isset($right->text)) {
           $license_str .= ': ' . $right->text;
         }
-        $licenses[] = $license_str;
+        $licenses[] = array('#markup' => $license_str);
         break;
 
       case UUID_RIGHTS_ACCESS_RIGHTS:
-        $access_rights[] = $right->text . $right->uuid;
+        $access_rights[] = array('#markup' => $right->text);
         break;
 
       default:
-        $unknown_groups[] = $right->text . $right->uuid; // TODO !
+        $unknown_groups[] = array('#markup' => $right->text);
     }
   }
 
   $groups = array();
   if (count($copyrights) > 0) {
-    _description_list_group_add($groups, t('Copyright'), $copyrights);
+    _description_list_group_add($groups, t('Copyright') . ':', $copyrights);
   }
   if (count($licenses) > 0) {
-    _description_list_group_add($groups, t('Licenses'), $licenses);
+    _description_list_group_add($groups, t('Licenses') . ':', $licenses);
   }
   if (count($access_rights) > 0) {
-    _description_list_group_add($groups, t('Access rights'), $access_rights);
+    _description_list_group_add($groups, t('Access rights') . ':', $access_rights);
   }
   if (count($unknown) > 0) {
-    _description_list_group_add($groups, t('Rights (untyped)'), $unknown);
+    _description_list_group_add($groups, t('Rights') . ':', $unknown);
   }
 
   return $groups;
@@ -178,38 +180,19 @@ function read_media_metadata($media) {
     $metadata_caption['artist'] = $media->artist->titleCache;
   }
 
-  // Copyright.
-  $metadata_caption['rights'] = array(
-    'copyright' => array('agentNames' => array()),
-    'license' => array(
-      'agentNames' => array(),
-      'types' => array(),
-      'abbreviatedTexts' => array(),
-      'uris' => array(),
-    ),
-  );
+  // Rights
+  $metadata_caption['rights'] = array();
   if (!empty($media_metadata->Copyright)) {
-    $metadata_caption['rights']['copyright']['agentNames'][] = $media_metadata->Copyright;
-  }
-  elseif (isset($media->rights) && is_array($media->rights)) {
-    foreach ($media->rights as $right) {
-      if(isset($right->term)){
-        switch ($right->type->uuid) {
-          case UUID_RIGHTS_LICENCE:
-            $metadata_caption['rights']['license']['agentNames'][] = ($right->agent ? '' . $right->agent->firstname . ' ' . $right->agent->lastname : '');
-            $metadata_caption['rights']['license']['types'][] = ($right->representation_L10n ? '' . $right->representation_L10n : '');
-            $metadata_caption['rights']['license']['abbreviatedTexts'][] = ($right->abbreviatedText ? '' . $right->abbreviatedText : '');
-            $metadata_caption['rights']['license']['uris'][] = ($right->uri ? '' . $right->uri : '');
-            break;
-          case UUID_RIGHTS_COPYRIGHT:
-            $metadata_caption['rights']['copyright']['agentNames'][] = $right->agent->firstname . ' ' . $right->agent->lastname;
-            break;
-        }
-      }
-    }
-  }
-  else {
-    $metadata_caption['rights']['agentNames'][] = '';
+    $rightsObj =  new stdClass();
+    $rightsObj->type = new stdClass();
+    $rightsObj->type->uuid = UUID_RIGHTS_COPYRIGHT;
+    $rightsObj->type->titleCache = 'copyright';
+    $rightsObj->type->representation_L10n = 'copyright';
+    $rightsObj->type->text = $media_metadata->Copyright;
+    $metadata_caption['rights'][] = $rightsObj;
+  }
+  if(isset($media->rights) && is_array($media->rights)) {
+    $metadata_caption['rights'] = array_merge($metadata_caption['rights'], $media->rights);
   }
 
   // Filling the description (though there is no description in the db???).
diff --git a/modules/cdm_dataportal/includes/occurrences.inc b/modules/cdm_dataportal/includes/occurrences.inc
index b9090498..27a519d5 100644
--- a/modules/cdm_dataportal/includes/occurrences.inc
+++ b/modules/cdm_dataportal/includes/occurrences.inc
@@ -707,10 +707,11 @@ function compose_cdm_sequence($sequence) {
             NULL,
             7
           );
+          break;
 
         case 'rights':
           array_merge($groups, cdm_rights_as_dl_groups($value));
-        break;
+          break;
 
         case 'annotations':
           $dd_elements = array();
diff --git a/modules/cdm_dataportal/theme/cdm_dataportal.media.theme b/modules/cdm_dataportal/theme/cdm_dataportal.media.theme
index 27dc9819..c17cd192 100644
--- a/modules/cdm_dataportal/theme/cdm_dataportal.media.theme
+++ b/modules/cdm_dataportal/theme/cdm_dataportal.media.theme
@@ -198,6 +198,8 @@ function theme_cdm_media_mime_text($variables) {
  *
  * @return string
  *   the themed html output
+ *
+ * TODO turn into compose method
  */
 function theme_cdm_media_caption($variables) {
   $media = $variables['media'];
@@ -216,7 +218,7 @@ function theme_cdm_media_caption($variables) {
   // Title.
   if ($doTitle) {
     if ($media_metadata['title']) {
-      $out .= '<dt class = "title">' . t('Title') . '</dt> <dd class = "title">' . $media_metadata['title'] . '</dd>';
+      $out .= '<dt class = "title">' . t('Title')  . ':'. '</dt> <dd class = "title">' . $media_metadata['title'] . '</dd>';
       $descriptionPrefix = "- ";
     }
     elseif (!($doDescription && $media_metadata['description'])) {
@@ -227,11 +229,11 @@ function theme_cdm_media_caption($variables) {
   }
   // Description.
   if ($media_metadata['description'] && $doDescription) {
-    $out .= '<dt class = "description">' . t('Description') . '</dt> <dd class = "description">' . $descriptionPrefix . $media_metadata['description'] . '</dd>';
+    $out .= '<dt class = "description">' . t('Description')  . ':'. '</dt> <dd class = "description">' . $descriptionPrefix . $media_metadata['description'] . '</dd>';
   }
   // Artist.
   if ($media_metadata['artist'] && $doArtist) {
-    $out .= '<dt class = "artist">' . t('Artist') . '</dt> <dd class = "astist">' . $media_metadata['artist'] . '</dd>';
+    $out .= '<dt class = "artist">' . t('Artist')  . ':' . '</dt> <dd class = "artist">' . $media_metadata['artist'] . '</dd>';
   }
   // Location.
   if ($doLocation) {
@@ -252,41 +254,16 @@ function theme_cdm_media_caption($variables) {
       $location .= $media_metadata['location']['country'];
     }
     if ($location) {
-      $out .= '<dt class = "location">' . t('Location') . '</dt> <dd class = "location">' . $location . '</dd>';
+      $out .= '<dt class = "location">' . t('Location') . ':' . '</dt> <dd class = "location">' . $location . '</dd>';
     }
   }
   // Rights.
   if ($doRights) {
-    $rights = '';
-    // TODO use cdm_rights_as_dl_groups() to create dl entries
-
-    // Copyrights.
-    $cnt = count($media_metadata['rights']['copyright']['agentNames']);
-    if ($cnt > 0) {
-      $rights .= '<dt class="rights">&copy;</dt> <dd class="rights"> ';
-      for ($i = 0; $i < $cnt; $i++) {
-        $rights .= $media_metadata['rights']['copyright']['agentNames'][$i];
-        if ($i + 1 < $cnt) {
-          $rights .= ' / ';
-        }
-      }
-      $rights .= '</dd>';
-    }
-    // License.
-    $cnt = count($media_metadata['rights']['license']['agentNames']);
-    if ($cnt > 0) {
-      $rights .= '<dt class ="license">' . t('License') . '</dt> <dd class = "license">';
-      for ($i = 0; $i < $cnt; $i++) {
-        $rights .= $media_metadata['rights']['license']['agentNames'][$i];
-        if ($i + 1 < $cnt) {
-          $rights .= ' / ';
-        }
-      }
-      $rights .= '</dd>';
-    }
-    if ($rights) {
-      $out .= $rights . '</dt>';
-    }
+    $rights_render_item = array(
+      '#theme' => 'description_list',
+      '#groups' => cdm_rights_as_dl_groups($media_metadata['rights'])
+    );
+   $out .= drupal_render($rights_render_item);
   }
   // TODO add all other metadata elements generically.
   $out .= '</dl>';
