diff --git a/includes/datastream.inc b/includes/datastream.inc index 4e47a5c7..a33a08f9 100644 --- a/includes/datastream.inc +++ b/includes/datastream.inc @@ -36,6 +36,27 @@ function islandora_datastream_as_attachment($object_id, $dsid) { exit(); } +function islandora_get_datastream_parents($islandora_object) { + $parent_collections = array(); + $repository = $islandora_object->repository; + $collections = $islandora_object->relationships->get(FEDORA_RELS_EXT_URI, 'isMemberOfCollection'); + + foreach($collections as $collection) { + try { + $pid = $collection['object']['value']; + $object = $repository->getObject($collection['object']['value']); + $parent_collections[$pid] = array(); + $parent_collections[$pid]['object'] = $object; + $parent_collections[$pid]['url'] = 'islandora/object/' . $object->id; + $parent_collections[$pid]['label'] = $object->label; + $parent_collections[$pid]['label_link'] = l($parent_collections[$pid]['label'], $parent_collections[$pid]['url']); + } + catch (RepositoryException $e) {} + } + + return $parent_collections; +} + /** * * @param array $arr diff --git a/islandora.module b/islandora.module index df7644ef..5025e273 100644 --- a/islandora.module +++ b/islandora.module @@ -596,22 +596,12 @@ function islandora_preprocess_islandora_default(&$variables) { drupal_add_js('misc/form.js'); drupal_add_js('misc/collapse.js'); $islandora_object = $variables['islandora_object']; - $repository = $islandora_object->repository; module_load_include('inc', 'islandora', 'includes/islandora_dublin_core'); module_load_include('inc', 'islandora', 'includes/utilities'); + module_load_include('inc', 'islandora', 'includes/datastream'); + + $variables['parent_collections'] = islandora_get_datastream_parents($islandora_object); - $parent_collections = array(); - $collections = $islandora_object->relationships->get(FEDORA_RELS_EXT_URI, 'isMemberOfCollection'); - foreach($collections as $collection) { - $pid = $collection['object']['value']; - $object = $repository->getObject($collection['object']['value']); - $parent_collections[$pid] = array(); - $parent_collections[$pid]['object'] = $object; - $parent_collections[$pid]['url'] = 'islandora/object/' . $object->id; - $parent_collections[$pid]['label'] = $object->label; - $parent_collections[$pid]['label_link'] = l($parent_collections[$pid]['label'], $parent_collections[$pid]['url']); - } - $variables['parent_collections'] = $parent_collections; $datastreams = array(); foreach ($islandora_object as $ds) { $pid = $islandora_object->id; diff --git a/islandora_basic_image/islandora_basic_image.module b/islandora_basic_image/islandora_basic_image.module index cc513cf8..42bc2611 100644 --- a/islandora_basic_image/islandora_basic_image.module +++ b/islandora_basic_image/islandora_basic_image.module @@ -205,6 +205,8 @@ function islandora_basic_image_preprocess_islandora_basic_image(&$variables) { $islandora_object = $variables['islandora_object']; $repository = $islandora_object->repository; module_load_include('inc', 'islandora', 'includes/islandora_dublin_core'); + module_load_include('inc', 'islandora', 'includes/datastream'); + try { $dc = $islandora_object['DC']->content; $dc_object = Dublin_Core::import_from_xml_string($dc); @@ -215,18 +217,7 @@ function islandora_basic_image_preprocess_islandora_basic_image(&$variables) { $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); - $parent_collections = array(); - $collections = $islandora_object->relationships->get(FEDORA_RELS_EXT_URI, 'isMemberOfCollection'); - foreach($collections as $collection) { - $pid = $collection['object']['value']; - $object = $repository->getObject($collection['object']['value']); - $parent_collections[$pid] = array(); - $parent_collections[$pid]['object'] = $object; - $parent_collections[$pid]['url'] = 'islandora/object/' . $object->id; - $parent_collections[$pid]['label'] = $object->label; - $parent_collections[$pid]['label_link'] = l($parent_collections[$pid]['label'], $parent_collections[$pid]['url']); - } - $variables['parent_collections'] = $parent_collections; + $variables['parent_collections'] = islandora_get_datastream_parents($islandora_object); global $base_url; if (isset($islandora_object['OBJ'])) { $full_size_url = $base_url . '/islandora/object/' . $islandora_object->id . '/datastream/OBJ/view';