Browse Source

Merge pull request #230 from nigelgbanks/7.x-allow-viewers-based-on-content-type

7.x allow viewers based on content type
pull/232/merge
Jonathan Green 12 years ago
parent
commit
f657adcadf
  1. 36
      includes/solution_packs.inc

36
includes/solution_packs.inc

@ -435,17 +435,26 @@ function islandora_check_object_status(NewFedoraObject $object_definition) {
/** /**
* A form construct to create a viewer selection table. * 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 * @param string $variable_id
* The ID of the Drupal variable to save the viewer settings in * The ID of the Drupal variable to save the viewer settings in
* @param string $mimetype * @param string $mimetype
* The table will be populated with viewers supporting this 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 * @return
* A form api array which defines a themed table to select a viewer. * 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(); $form = array();
// get viewers // get viewers
$viewers = islandora_get_viewers($mimetype); $viewers = islandora_get_viewers($mimetype, $model);
if (!empty($viewers)) { if (!empty($viewers)) {
// add option for no viewer // add option for no viewer
$no_viewer = array(); $no_viewer = array();
@ -524,19 +533,32 @@ function islandora_viewers_form($variable_id = NULL, $mimetype = NULL) {
/** /**
* Returns all defined viewers. * 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 * @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. * mimetype.
* @return * @param string $content_model
* array of viewer definitions, or FALSE if none are found. * 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) { function islandora_get_viewers($mimetype = NULL, $content_model = NULL) {
$viewers = array(); $viewers = array();
// get all viewers // get all viewers
$defined_viewers = module_invoke_all('islandora_viewer_info'); $defined_viewers = module_invoke_all('islandora_viewer_info');
// filter viewers by mimetype // filter viewers by mimetype
foreach ($defined_viewers as $key => $value) { 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; $viewers[$key] = $value;
} }
} }

Loading…
Cancel
Save