Browse Source

Merge pull request #200 from DannyJoris/7.x

7.x
pull/201/head
Jonathan Green 12 years ago
parent
commit
fc369f722c
  1. 2
      admin/islandora.admin.inc
  2. 230
      includes/solution_packs.inc
  3. 25
      islandora.api.php
  4. 168
      islandora.module

2
admin/islandora.admin.inc

@ -13,6 +13,8 @@
function islandora_repository_admin($form, &$form_state) { function islandora_repository_admin($form, &$form_state) {
module_load_include('inc', 'islandora', 'includes/tuque'); module_load_include('inc', 'islandora', 'includes/tuque');
module_load_include('inc', 'islandora', 'includes/utilities'); module_load_include('inc', 'islandora', 'includes/utilities');
// add css
drupal_add_css(drupal_get_path('module', 'islandora') . '/css/islandora.admin.css');
if (!IslandoraTuque::exists()) { if (!IslandoraTuque::exists()) {
IslandoraTuque::getError(); IslandoraTuque::getError();

230
includes/solution_packs.inc

@ -9,6 +9,8 @@
* Solution pack admin page callback * Solution pack admin page callback
*/ */
function islandora_solution_packs_admin() { function islandora_solution_packs_admin() {
// add css
drupal_add_css(drupal_get_path('module', 'islandora') . '/css/islandora.admin.css');
// check connection // check connection
module_load_include('inc', 'islandora', 'includes/utilities'); module_load_include('inc', 'islandora', 'includes/utilities');
$url = variable_get('islandora_base_url', 'http://localhost:8080/fedora'); $url = variable_get('islandora_base_url', 'http://localhost:8080/fedora');
@ -483,5 +485,233 @@ function islandora_check_object_status($object_model = array()) {
} }
} }
/**
* @defgroup viewer-functions
* @{
* Helper functions to include viewers for solution packs.
*/
/**
* A form construct to create a viewer selection table.
*
* @param string $variable_id
* 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
* @return
* A form api array which defines a themed table to select a viewer.
*/
function islandora_viewers_form($variable_id = NULL, $mimetype = NULL) {
$form = array();
// get viewers
$viewers = islandora_get_viewers($mimetype);
if (!empty($viewers)) {
// add option for no viewer
$no_viewer = array();
$no_viewer['none'] = array(
'label' => t('None'),
'description' => t('Don\'t use a viewer for this solution pack.'),
);
// merge to viewers array
$viewers = array_merge_recursive($no_viewer, $viewers);
}
// get viewer settings
$viewers_config = variable_get($variable_id, array());
// viewer
$form['viewers'] = array(
'#type' => 'fieldset',
'#title' => t('Viewers'),
'#collapsible' => FALSE,
'#collapsed' => FALSE,
);
if (!empty($viewers)) {
// viewers table
$form['viewers'][$variable_id] = array(
'#type' => 'item',
'#title' => t('Select a viewer'),
'#description' => t('Preferred viewer for your solution pack. These may be provided by third-party modules.'),
'#tree' => TRUE, // this attribute is important to return the submitted values in a deeper nested arrays in
'#theme' => 'islandora_viewers_table',
);
// table loop
foreach ($viewers as $name => $profile) {
$options[$name] = '';
// machine name
$form['viewers'][$variable_id]['name'][$name] = array(
'#type' => 'hidden',
'#value' => $name,
);
// label
$form['viewers'][$variable_id]['label'][$name] = array(
'#type' => 'item',
'#markup' => $profile['label'],
);
// description
$form['viewers'][$variable_id]['description'][$name] = array(
'#type' => 'item',
'#markup' => $profile['description'],
);
// configuration url
$form['viewers'][$variable_id]['configuration'][$name] = array(
'#type' => 'item',
'#markup' => (isset($profile['configuration']) AND $profile['configuration'] != '') ? l(t('configure'), $profile['configuration']) : '',
);
}
// radios
$form['viewers'][$variable_id]['default'] = array(
'#type' => 'radios',
'#options' => isset($options) ? $options : array(),
'#default_value' => !empty($viewers_config) ? $viewers_config['default'] : 'none',
);
}
else {
// No viewers found
$form['viewers'][$variable_id . '_no_viewers'] = array(
'#markup' => t('No viewers detected.'),
);
// remove viewers variable
variable_del($variable_id);
}
return $form;
}
/**
* Returns all defined viewers.
*
* @param string $mimetype
* specify a mimetype to return only viewers that support this certain mimetype.
* @return
* array of viewer definitions, or FALSE if none are found.
*/
function islandora_get_viewers($mimetype = 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) {
$viewers[$key] = $value;
}
}
if (!empty($viewers)) {
return $viewers;
}
return FALSE;
}
/**
* Theme function for the admin primary display table
*
* @param type $variables
* render element: $form
* Contains the form array
* @return
* rendered form element
*
* @see islandora_large_image_admin()
*/
function theme_islandora_viewers_table($variables) {
// set form
$form = $variables['form'];
$rows = array();
foreach ($form['name'] as $key => $element) {
// Do not take form control structures.
if (is_array($element) && element_child($key)) {
// set rows
$row = array();
$row[] = array('data' => drupal_render($form['default'][$key]));
$row[] = array('data' => drupal_render($form['label'][$key]));
$row[] = array('data' => drupal_render($form['description'][$key]));
$row[] = array('data' => drupal_render($form['configuration'][$key]));
// add to rows
$rows[] = array('data' => $row);
}
}
// Individual table headers.
// default | label | description | configuration
$header = array();
$header[] = array('data' => t('Default'));
$header[] = array('data' => t('Label'));
$header[] = array('data' => t('Description'));
$header[] = array('data' => t('Configuration'));
// render form
$output = '';
$output .= theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'islandora-viewers-table')));
$output .= drupal_render_children($form);
return $output;
}
/**
* Gather information and return a rendered viewer
*
* @param array/string $params
* Array or string with data the module needs in order to render a full viewer
* @param string $variable_id
* The id of the Drupal variable the viewer settings are saved in
* @return
* The callback to the viewer module. Returns a rendered viewer. Returns FALSE
* if no viewer is set.
*/
function islandora_get_viewer($params = NULL, $variable_id = NULL) {
// get viewer from settings
$settings = variable_get($variable_id, array());
// make sure a viewer is set
if (!empty($settings) AND $settings['default'] !== 'none') {
// get callback function
$viewer_id = islandora_get_viewer_id($variable_id);
if ($viewer_id AND $params !== NULL) {
$callback = islandora_get_viewer_callback($viewer_id);
// call callback function
return $callback($params);
}
}
return NULL;
}
/**
* Get id of the enabled viewer.
*
* @param string $variable_id
* The id of the Drupal variable the viewer settings are saved in
* @return
* The enabled viewer id. Returns FALSE if no viewer config is set.
*/
function islandora_get_viewer_id($variable_id) {
$viewers_config = variable_get($variable_id, array());
if (!empty($viewers_config)) {
return $viewers_config['default'];
}
return FALSE;
}
/**
* Get callback function for a viewer.
*
* @param string $viewer_id
* The ID of a viewer
* @return
* The callback function as a string as defined by the viewer.
*/
function islandora_get_viewer_callback($viewer_id = NULL) {
if ($viewer_id !== NULL) {
// get defined viewers
$viewers = module_invoke_all('islandora_viewer_info');
if (isset($viewers[$viewer_id]['callback'])) {
// return callback function
return $viewers[$viewer_id]['callback'];
}
}
return FALSE;
}
/**
* @} End of "defgroup viewer-functions".
*/

25
islandora.api.php

@ -126,7 +126,7 @@ function hook_CMODEL_PID_islandora_pre_purge_object($fedora_object) {}
function hook_islandora_ingest_registry($collection_object) { function hook_islandora_ingest_registry($collection_object) {
$reg = array( $reg = array(
array( array(
'name' => t('Ingest Route Name'), 'name' => t('Ingest route name'),
'url' => 'ingest_route/url', 'url' => 'ingest_route/url',
'weight' => 0, 'weight' => 0,
), ),
@ -195,3 +195,26 @@ function hook_islandora_post_purge_datastream($object, $dsid) {}
*/ */
function hook_islandora_post_purge_object($object_id, $content_models) {} function hook_islandora_post_purge_object($object_id, $content_models) {}
/**
* Registry hook for required objects.
*
* Solution packs can include data to create certain objects that describe or
* help the objects it would create. This includes collection objects and content
* models.
*
* @see islandora_solution_packs_admin()
* @see islandora_install_solution_pack()
* @example islandora_islandora_required_objects()
*/
function hook_islandora_required_objects() {}
/**
* Registry hook for viewers that can be implemented by solution packs.
*
* Solution packs can use viewers for their data. This hook lets Islandora know
* which viewers there are available.
*
* @see islandora_get_viewers()
* @see islandora_get_viewer_callback()
*/
function hook_islandora_viewer_info() {}

168
islandora.module

@ -223,6 +223,84 @@ function islandora_admin_paths() {
return $paths; return $paths;
} }
/**
* Implements hook_theme().
*
* @return array
*/
function islandora_theme() {
return array(
// default object template
'islandora_default' => array(
'file' => 'theme/islandora.theme.inc',
'template' => 'theme/islandora-object',
'variables' => array('islandora_object' => NULL),
),
// default edit page
'islandora_default_edit' => array(
'file' => 'theme/islandora.theme.inc',
'template' => 'theme/islandora-object-edit',
'variables' => array('islandora_object' => NULL),
),
// admin table for solution pack viewer selection
'islandora_viewers_table' => array(
'file' => 'includes/solution_packs.inc',
'render element' => 'form',
),
);
}
/**
* Implements hook_permission().
*
* @return array
*/
function islandora_permission() {
return array(
FEDORA_VIEW => array(
'title' => t('View repository objects and datastreams'),
'description' => t('View objects in the repository and their associated datastreams. Note: Fedora XACML security policies may override this permission.')
),
FEDORA_ADD_DS => array(
'title' => t('Add datastreams to repository objects'),
'description' => t('Add datastreams to objects in the repository. Note: Fedora XACML security policies may override this position.')
),
FEDORA_METADATA_EDIT => array(
'title' => t('Edit metadata'),
'description' => t('Edit metadata for objects in the repository.')
),
FEDORA_INGEST => array(
'title' => t('Create new repository objects'),
'description' => t('Create new objects in the repository.')
),
FEDORA_PURGE => array(
'title' => t('Permanently remove objects from the repository'),
'description' => t('Permanently remove objects from the repository.')
),
FEDORA_MODIFY_STATE => array(
'title' => t('Change repository object states'),
'description' => t('Change the state of objects in the repository (e.g. from Active to Inactive).')
),
FEDORA_MANAGE => array(
'title' => t('View object management tabs'),
'description' => t('View tabs that provide object management functions.')
)
);
}
/**
* Implements hook_forms().
*/
function islandora_forms($form_id) {
$forms = array();
if (strpos($form_id, 'islandora_solution_pack_form_') !== FALSE) {
$forms[$form_id] = array(
'callback' => 'islandora_solution_pack_form',
);
}
return $forms;
}
/** /**
* determines whether we can see the object or not * determines whether we can see the object or not
* checks PID namespace permissions, and user permissions * checks PID namespace permissions, and user permissions
@ -237,9 +315,9 @@ function islandora_access_callback($object = NULL, $perm = NULL) {
return FALSE; return FALSE;
} }
$isRestricted = variable_get('islandora_namespace_restriction_enforced', FALSE); $is_restricted = variable_get('islandora_namespace_restriction_enforced', FALSE);
if (!$isRestricted) { if (!$is_restricted) {
$namespace_access = TRUE; $namespace_access = TRUE;
} }
else { else {
@ -251,25 +329,6 @@ function islandora_access_callback($object = NULL, $perm = NULL) {
return ($namespace_access && user_access($perm)); return ($namespace_access && user_access($perm));
} }
function islandora_init() {
if (path_is_admin(current_path())) {
drupal_add_css(drupal_get_path('module', 'islandora') . '/css/islandora.admin.css');
}
}
/**
* Implements hook_forms().
*/
function islandora_forms($form_id) {
$forms = array();
if (strpos($form_id, 'islandora_solution_pack_form_') !== FALSE) {
$forms[$form_id] = array(
'callback' => 'islandora_solution_pack_form',
);
}
return $forms;
}
/** /**
* a function to call other modules edit page. If there are not any modules * a function to call other modules edit page. If there are not any modules
* that handle this function this module will build a default page. * that handle this function this module will build a default page.
@ -377,7 +436,7 @@ function islandora_view_object($fedora_object = NULL) {
// Call cmodel oriented variants first. // Call cmodel oriented variants first.
foreach (islandora_build_hook_list(ISLANDORA_VIEW_HOOK, $fedora_object->models) as $hook) { foreach (islandora_build_hook_list(ISLANDORA_VIEW_HOOK, $fedora_object->models) as $hook) {
$temp = module_invoke_all($hook, $fedora_object, $user, $page_number, $page_size); $temp = module_invoke_all($hook, $fedora_object, $page_number, $page_size);
if (!empty($temp)) { if (!empty($temp)) {
$output = array_merge_recursive($output, $temp); $output = array_merge_recursive($output, $temp);
} }
@ -408,64 +467,6 @@ function islandora_default_islandora_view_object($object) {
return array('Default output' => $output); return array('Default output' => $output);
} }
/**
* Implements hook_theme().
*
* @return array
*/
function islandora_theme() {
return array(
'islandora_default' => array(
'file' => 'theme/islandora.theme.inc',
'template' => 'theme/islandora-object',
'variables' => array('islandora_object' => NULL),
),
'islandora_default_edit' => array(
'file' => 'theme/islandora.theme.inc',
'template' => 'theme/islandora-object-edit',
'variables' => array('islandora_object' => NULL),
),
);
}
/**
* Implements hook_permission().
*
* @return array
*/
function islandora_permission() {
return array(
FEDORA_VIEW => array(
'title' => t('View repository objects and datastreams'),
'description' => t('View objects in the repository and their associated datastreams. Note: Fedora XACML security policies may override this permission.')
),
FEDORA_ADD_DS => array(
'title' => t('Add datastreams to repository objects'),
'description' => t('Add datastreams to objects in the repository. Note: Fedora XACML security policies may override this position.')
),
FEDORA_METADATA_EDIT => array(
'title' => t('Edit metadata'),
'description' => t('Edit metadata for objects in the repository.')
),
FEDORA_INGEST => array(
'title' => t('Create new repository objects'),
'description' => t('Create new objects in the repository.')
),
FEDORA_PURGE => array(
'title' => t('Permanently remove objects from the repository'),
'description' => t('Permanently remove objects from the repository.')
),
FEDORA_MODIFY_STATE => array(
'title' => t('Change repository object states'),
'description' => t('Change the state of objects in the repository (e.g. from Active to Inactive).')
),
FEDORA_MANAGE => array(
'title' => t('View object management tabs'),
'description' => t('View tabs that provide object management functions.')
)
);
}
/** /**
* A helper function to get a connection and return an object * A helper function to get a connection and return an object
* *
@ -601,10 +602,8 @@ function islandora_get_islandora_datastream_version($item = NULL, $dsid = NULL,
* Implements hook_islandora_required_objects(). * Implements hook_islandora_required_objects().
*/ */
function islandora_islandora_required_objects() { function islandora_islandora_required_objects() {
// module path // module path
$module_path = drupal_get_path('module', 'islandora'); $module_path = drupal_get_path('module', 'islandora');
return array( return array(
'islandora' => array( 'islandora' => array(
'title' => 'Islandora', 'title' => 'Islandora',
@ -634,3 +633,8 @@ function islandora_islandora_required_objects() {
), ),
); );
} }

Loading…
Cancel
Save