From 256a9013033f9d387ac2844753bf379b3c9e2ed0 Mon Sep 17 00:00:00 2001 From: Paul Pound Date: Thu, 24 May 2012 12:27:12 -0300 Subject: [PATCH] added formatted array output to dublin core class --- includes/islandora_dublin_core.inc | 19 +++++++++++++++++++ .../islandora_basic_image.module | 19 +------------------ 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/includes/islandora_dublin_core.inc b/includes/islandora_dublin_core.inc index 9ea4aa35..6d3326e5 100644 --- a/includes/islandora_dublin_core.inc +++ b/includes/islandora_dublin_core.inc @@ -99,6 +99,25 @@ class Dublin_Core { } + function as_formatted_array() { + $dc_array = array(); + foreach ($this->dc as $element) { + if (!empty($element)) { + foreach ($element as $field => $value) { + // split value if the result value is an array + if (is_array($value)) { + $value = implode(", ", $value); + } + $dc_label = explode(':', $field); + $element_label = ucfirst($dc_label[1]); + $dc_array[$field]['label'] = $element_label; + $dc_array[$field]['value'] = strip_tags($value); + $dc_array[$field]['class'] = strtolower(preg_replace('/[^A-Za-z0-9]/', '-', $field)); + } + } + } + return $dc_array; + } /** diff --git a/islandora_basic_image/islandora_basic_image.module b/islandora_basic_image/islandora_basic_image.module index 372d80dd..ec3e9cd1 100644 --- a/islandora_basic_image/islandora_basic_image.module +++ b/islandora_basic_image/islandora_basic_image.module @@ -101,24 +101,7 @@ function islandora_basic_image_preprocess_islandora_basic_image(&$variables) { $variables['islandora_dublin_core'] = $dc_object; //create a nicer array for themers //TODO: give this a better home - - $dc_array = array(); - foreach ($dc_object as $element) { - if (!empty($element)) { - foreach ($element as $field => $value) { - // split value if the result value is an array - if (is_array($value)) { - $value = implode(", ", $value); - } - $dc_label = explode(':', $field); - $element_label = ucfirst($dc_label[1]); - $dc_array[$field]['label'] = $element_label; - $dc_array[$field]['value'] = strip_tags($value); - $dc_array[$field]['class'] = strtolower( preg_replace('/[^A-Za-z0-9]/', '-', $field)); - } - } - } - $variables['dc_array'] = $dc_array; + $variables['dc_array'] = $dc_object->as_formatted_array(); $variables['islandora_object_label'] = $islandora_object->label; $variables['theme_hook_suggestions'][] = 'islandora_basic_image__' . str_replace(':', '_', $islandora_object->id); global $base_url;