Browse Source

Merge pull request #360 from adam-vessey/7.x-renderable-arrays

Use renderable arrays instead of the array of strings we used to.
pull/361/merge
Jordan Dukart 11 years ago
parent
commit
8496a01987
  1. 45
      includes/utilities.inc
  2. 30
      islandora.module

45
includes/utilities.inc

@ -865,3 +865,48 @@ function islandora_deprecated($release, $solution = NULL) {
}
return $message;
}
/**
* Transform recursively-merged array of strings to renderable arrays.
*
* Renderable arrays are passed-through as-is.
*
* Previously, functions/hooks like islandora_view_object would return an
* associative array with string values containing markup. These values were
* then imploded into one large piece of markup. Here, we transform this older
* structure which was generated into a renderable array, because renderable
* arrays are awesome!
*
* @param array $markup_array
* An associative array of which the values are either a string or an array
* of strings, which we transform to renderable markup elements (by
* reference).
*/
function islandora_as_renderable_array(&$markup_array) {
foreach ($markup_array as &$value) {
if (!is_array($value)) {
// Not a renderable array, just a string. Let's convert it to a
// renderable '#markup' element.
$value = array(
'#markup' => $value,
);
}
elseif (!isset($value['#type']) && !isset($value['#markup'])) {
// A simple array--possibly the result of a recursive merge? Let's
// look at each, to possibly convert them to a renderable '#markup'
// elements.
foreach ($value as &$inner) {
if (!is_array($inner)) {
// If it is an array at this level, we can assume that it is a
// renderable array. If it is not an array, convert to a renderable
// '#markup' element.
$inner = array(
'#markup' => $inner,
);
}
}
unset($inner);
}
}
unset($value);
}

30
islandora.module

@ -624,6 +624,7 @@ function islandora_manage_overview_object(AbstractObject $object) {
$output = array();
foreach (islandora_build_hook_list(ISLANDORA_OVERVIEW_HOOK, $object->models) as $hook) {
$temp = module_invoke_all($hook, $object);
islandora_as_renderable_array($temp);
if (!empty($temp)) {
$output = array_merge_recursive($output, $temp);
}
@ -634,7 +635,8 @@ function islandora_manage_overview_object(AbstractObject $object) {
}
arsort($output);
drupal_alter(ISLANDORA_OVERVIEW_HOOK, $object, $output);
return implode('', $output);
islandora_as_renderable_array($output);
return $output;
}
/**
@ -649,7 +651,11 @@ function islandora_manage_overview_object(AbstractObject $object) {
*/
function islandora_default_islandora_manage_overview_object(AbstractObject $object) {
$output = theme('islandora_default_overview', array('islandora_object' => $object));
return array('Default overview output' => $output);
return array(
'Default overview output' => array(
'#markup' => $output,
),
);
}
/**
@ -675,6 +681,7 @@ function islandora_edit_object(AbstractObject $object) {
$output = array();
foreach (islandora_build_hook_list(ISLANDORA_EDIT_HOOK, $object->models) as $hook) {
$temp = module_invoke_all($hook, $object);
islandora_as_renderable_array($temp);
if (!empty($temp)) {
$output = array_merge_recursive($output, $temp);
}
@ -685,7 +692,8 @@ function islandora_edit_object(AbstractObject $object) {
}
arsort($output);
drupal_alter(ISLANDORA_EDIT_HOOK, $object, $output);
return implode('', $output);
islandora_as_renderable_array($output);
return $output;
}
/**
@ -700,7 +708,11 @@ function islandora_edit_object(AbstractObject $object) {
*/
function islandora_default_islandora_edit_object(AbstractObject $object) {
$output = theme('islandora_default_edit', array('islandora_object' => $object));
return array('Default Edit output' => $output);
return array(
'Default Edit output' => array(
'#markup' => $output,
),
);
}
/**
@ -743,6 +755,7 @@ function islandora_view_object(AbstractObject $object) {
// @todo Remove page number and size from this hook, implementers of the
// hook should use drupal page handling directly.
$temp = module_invoke_all($hook, $object, $page_number, $page_size);
islandora_as_renderable_array($temp);
if (!empty($temp)) {
$output = array_merge_recursive($output, $temp);
}
@ -753,7 +766,8 @@ function islandora_view_object(AbstractObject $object) {
}
arsort($output);
drupal_alter($hooks, $object, $output);
return implode('', $output);
islandora_as_renderable_array($output);
return $output;
}
@ -786,7 +800,11 @@ function islandora_drupal_title(AbstractObject $object) {
*/
function islandora_default_islandora_view_object($object) {
$output = theme('islandora_default', array('islandora_object' => $object));
return array('Default output' => $output);
return array(
'Default output' => array(
'#markup' => $output,
),
);
}
/**

Loading…
Cancel
Save