From 41f1737d9bca8f9e5326591bf3094fb5069e5cb4 Mon Sep 17 00:00:00 2001 From: Nigel Banks Date: Sat, 15 Dec 2012 20:43:31 +0000 Subject: [PATCH 1/5] Viewers can be defined by content type as well, for aggregate objects such as books. --- includes/solution_packs.inc | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/includes/solution_packs.inc b/includes/solution_packs.inc index 21e22619..5b932b51 100644 --- a/includes/solution_packs.inc +++ b/includes/solution_packs.inc @@ -439,13 +439,16 @@ function islandora_check_object_status(NewFedoraObject $object_definition) { * The ID of the Drupal variable to save the viewer settings in * @param string $mimetype * The table will be populated with viewers supporting this mimetype + * @param string $model + * The table will be populated with viewers supporting this content model + * * @return * A form api array which defines a themed table to select a viewer. */ -function islandora_viewers_form($variable_id = NULL, $mimetype = NULL) { +function islandora_viewers_form($variable_id = NULL, $mimetype = NULL, $model = NULL) { $form = array(); // get viewers - $viewers = islandora_get_viewers($mimetype); + $viewers = islandora_get_viewers($mimetype, $model); if (!empty($viewers)) { // add option for no viewer $no_viewer = array(); @@ -530,13 +533,15 @@ function islandora_viewers_form($variable_id = NULL, $mimetype = NULL) { * @return * array of viewer definitions, or FALSE if none are found. */ -function islandora_get_viewers($mimetype = NULL) { +function islandora_get_viewers($mimetype = NULL, $content_model = NULL) { $viewers = array(); // get all viewers $defined_viewers = module_invoke_all('islandora_viewer_info'); // filter viewers by mimetype foreach ($defined_viewers as $key => $value) { - if (in_array($mimetype, $value['mimetype']) OR $mimetype == NULL) { + $value['mimetype'] = isset($value['mimetype']) ? $value['mimetype'] : array(); + $value['model'] = isset($value['model']) ? $value['model'] : array(); + if (in_array($mimetype, $value['mimetype']) OR in_array($content_model, $value['model'])) { $viewers[$key] = $value; } } From 8680f911c9442e35b91eaecff9127badefc06aa5 Mon Sep 17 00:00:00 2001 From: Nigel Banks Date: Thu, 20 Dec 2012 19:30:04 +0000 Subject: [PATCH 2/5] Fixed namespace problem caused by previous commit --- includes/utilities.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/utilities.inc b/includes/utilities.inc index 066946e9..b2006722 100644 --- a/includes/utilities.inc +++ b/includes/utilities.inc @@ -382,7 +382,7 @@ function islandora_get_datastreams_requirements_from_content_model(FedoraObject function islandora_prepare_new_object($namespace = NULL, $label = NULL, $datastreams = array(), $content_models = array(), $relationships = array()) { global $user; $tuque = islandora_get_tuque_connection(); - $object = $tuque->repository->constructObject($namespace); + $object = isset($namespace) ? $tuque->repository->constructObject($namespace) : new IslandoraNewFedoraObject(NULL, $tuque->repository); $object->owner = isset($user->name) ? $user->name : $object->owner; $object->label = isset($label) ? $label : $object->label; foreach ($content_models as $content_model) { From 96a4eb6279086ff7eb014fba4a4bc415588a26da Mon Sep 17 00:00:00 2001 From: Nigel Banks Date: Tue, 1 Jan 2013 20:06:00 +0000 Subject: [PATCH 3/5] Decode the pid when retrieved from the url as it may be encoded, which causes problems with tuque. --- islandora.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/islandora.module b/islandora.module index f8673546..3bb2f92d 100644 --- a/islandora.module +++ b/islandora.module @@ -507,7 +507,7 @@ function islandora_object_load($object_id) { $tuque = islandora_get_tuque_connection(); if ($tuque) { try { - $object = $tuque->repository->getObject($object_id); + $object = $tuque->repository->getObject(urldecode($object_id)); drupal_alter('islandora_object', $object); return $object; } catch (Exception $e) { From f2bec4baab90431634f0a9250c1dcb6256d6e673 Mon Sep 17 00:00:00 2001 From: Nigel Banks Date: Wed, 2 Jan 2013 03:25:57 +0000 Subject: [PATCH 4/5] Updated function header. --- includes/solution_packs.inc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/includes/solution_packs.inc b/includes/solution_packs.inc index 5b932b51..75eac263 100644 --- a/includes/solution_packs.inc +++ b/includes/solution_packs.inc @@ -528,10 +528,14 @@ function islandora_viewers_form($variable_id = NULL, $mimetype = NULL, $model = * Returns all defined viewers. * * @param string $mimetype - * specify a mimetype to return only viewers that support this certain + * Specify a mimetype to return only viewers that support this certain * mimetype. - * @return - * array of viewer definitions, or FALSE if none are found. + * @param string $content_model + * Specify a content model to return only viewers that support the content + * model. + * + * @return array + * Viewer definitions, or FALSE if none are found. */ function islandora_get_viewers($mimetype = NULL, $content_model = NULL) { $viewers = array(); From 777dab15111182cf362f2acaa380d5251b272b00 Mon Sep 17 00:00:00 2001 From: Nigel Banks Date: Wed, 2 Jan 2013 05:32:58 +0000 Subject: [PATCH 5/5] Parameters documented for viewer functions. --- includes/solution_packs.inc | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/includes/solution_packs.inc b/includes/solution_packs.inc index 75eac263..bf50a1f5 100644 --- a/includes/solution_packs.inc +++ b/includes/solution_packs.inc @@ -435,6 +435,12 @@ function islandora_check_object_status(NewFedoraObject $object_definition) { /** * A form construct to create a viewer selection table. * + * The list of selectable viewers is limited by the $mimetype and the $model + * parameters. When neither are given all defined viewers are listed. If only + * $mimetype is given only viewers that support that mimetype will be listed, + * the same goes for the $model parameter. If both are given, than any viewer + * that supports either the give $mimetype or $model will be listed. + * * @param string $variable_id * The ID of the Drupal variable to save the viewer settings in * @param string $mimetype @@ -527,6 +533,13 @@ function islandora_viewers_form($variable_id = NULL, $mimetype = NULL, $model = /** * Returns all defined viewers. * + * The list of selectable viewers is limited by the $mimetype and the + * $content_model parameters. When neither are given all defined viewers are + * listed. If only $mimetype is given only viewers that support that mimetype + * will be listed, the same goes for the $content_model parameter. If both are + * given, than any viewer that supports either the give $mimetype or $model will + * be listed. + * * @param string $mimetype * Specify a mimetype to return only viewers that support this certain * mimetype.