Browse Source

Merge branch '7.x' of git://github.com/Islandora/islandora into 7.x-alter-hook-defs

Conflicts:
	islandora.module
pull/193/head
Adam Vessey 12 years ago
parent
commit
508718075a
  1. 7
      includes/islandora.ingest.inc
  2. 50
      includes/utilities.inc
  3. 85
      islandora.module

7
includes/islandora.ingest.inc

@ -132,7 +132,8 @@ function islandora_ingest_new_object_prepare($namespace = NULL, $label = NULL, $
$object->ingestDatastream($datastream); $object->ingestDatastream($datastream);
} }
foreach (_islandora_build_hook_list('islandora_ingest_pre_ingest', $content_models) as $hook) { module_load_include('inc', 'islandora', 'includes/utilities');
foreach (islandora_build_hook_list('islandora_ingest_pre_ingest', $content_models) as $hook) {
module_invoke_all($hook, $object, $content_models, $collection_pid); module_invoke_all($hook, $object, $content_models, $collection_pid);
} }
@ -151,7 +152,9 @@ function islandora_ingest_new_object_prepare($namespace = NULL, $label = NULL, $
function islandora_ingest_add_object(&$object) { function islandora_ingest_add_object(&$object) {
$object->repository->ingestObject($object); $object->repository->ingestObject($object);
foreach (_islandora_build_hook_list(ISLANDORA_POST_INGEST_HOOK, $object->models) as $hook) { module_load_include('inc', 'islandora', 'includes/utilities');
foreach (islandora_build_hook_list(ISLANDORA_POST_INGEST_HOOK, $object->models) as $hook) {
module_invoke_all($hook, $object); module_invoke_all($hook, $object);
} }

50
includes/utilities.inc

@ -8,6 +8,8 @@
/** /**
* Convert bytes to human readable format * Convert bytes to human readable format
* *
* XXX: Shouldn't Drupal's format_size() be preferred?
*
* @param integer bytes Size in bytes to convert * @param integer bytes Size in bytes to convert
* @return string * @return string
*/ */
@ -103,4 +105,50 @@ function islandora_describe_repository($url) {
catch (RepositoryException $e) { catch (RepositoryException $e) {
return FALSE; return FALSE;
} }
} }
/**
* Build a list of all the hooks to call.
*
* Concatenates the each pid (escaped) to the hook name, for calling in
* module_invoke_all().
*
* @param string $hook
* A hook to call.
* @param array $pids
* An array of PIDs (probably content models).
*
* @return array
* An array with each PID escaped and concatenated with the base hook name,
* in addition to the base hook name at the end.
*/
function islandora_build_hook_list($hook, $pids = array()) {
$hooks = array();
foreach ($pids as $model) {
$hooks[] = islandora_escape_pid_for_function($model) . '_' . $hook;
}
$hooks[] = $hook;
return $hooks;
}
/**
* Escape a Fedora PID to be valid inside of a PHP function name.
*
* Originally intended to allow inclusion of a PID in a module_invoke_all()
* call.
*/
function islandora_escape_pid_for_function($pid) {
// Apparently, case doesn't matter for function calls in PHP, so let's not
// really worry about changing the case.
return str_replace(
// Any PID characters which are not valid in the name of a PHP function.
array(
':',
'-',
),
'_',
$pid
);
}

85
islandora.module

@ -270,52 +270,6 @@ function islandora_forms($form_id) {
return $forms; return $forms;
} }
/**
* Escape a Fedora PID to be valid inside of a PHP function name.
*
* Originally intended to allow inclusion of a PID in a module_invoke_all()
* call.
*/
function _islandora_escape_pid_for_function($pid) {
// Apparently, case doesn't matter for function calls in PHP, so let's not
// really worry about changing the case.
return str_replace(
// Any PID characters which are not valid in the name of a PHP function.
array(
':',
'-',
),
'_',
$pid
);
}
/**
* Build a list of all the hooks to call.
*
* Concatenates the each pid (escaped) to the hook name, for calling in
* module_invoke_all().
*
* @param string $hook
* A hook to call.
* @param array $pids
* An array of PIDs (probably content models).
*
* @return array
* An array with each PID escaped and concatenated with the base hook name,
* in addition to the base hook name at the end.
*/
function _islandora_build_hook_list($hook, $pids = array()) {
$hooks = array();
foreach ($pids as $model) {
$hooks[] = _islandora_escape_pid_for_function($model) . '_' . $hook;
}
$hooks[] = $hook;
return $hooks;
}
/** /**
* 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.
@ -328,11 +282,13 @@ function islandora_edit_object($object) {
return drupal_not_found(); return drupal_not_found();
} }
module_load_include('inc', 'islandora', 'includes/utilities');
// Accumulate the output. // Accumulate the output.
$output = array(); $output = array();
// Call cmodel oriented variants first. // Call cmodel oriented variants first.
foreach (_islandora_build_hook_list(ISLANDORA_EDIT_HOOK, $object->models) as $hook) { foreach (islandora_build_hook_list(ISLANDORA_EDIT_HOOK, $object->models) as $hook) {
$temp = module_invoke_all($hook, $object); $temp = module_invoke_all($hook, $object);
if (!empty($temp)) { if (!empty($temp)) {
$output = array_merge_recursive($output, $temp); $output = array_merge_recursive($output, $temp);
@ -341,7 +297,7 @@ function islandora_edit_object($object) {
// Add in the default, if we did not get any results. // Add in the default, if we did not get any results.
if (empty($output)) { if (empty($output)) {
$output = _islandora_islandora_edit_object($object); $output = islandora_default_islandora_edit_object($object);
} }
arsort($output); arsort($output);
@ -373,7 +329,7 @@ function islandora_edit_properties($object_id) {
* @param object $fedora_object * @param object $fedora_object
* A tuque Fedora Object * A tuque Fedora Object
*/ */
function _islandora_islandora_edit_object($fedora_object) { function islandora_default_islandora_edit_object($fedora_object) {
$output = theme('islandora_default_edit', array( $output = theme('islandora_default_edit', array(
'islandora_object' => $fedora_object, 'islandora_object' => $fedora_object,
)); ));
@ -381,6 +337,12 @@ function _islandora_islandora_edit_object($fedora_object) {
return array('Default Edit output' => $output); return array('Default Edit output' => $output);
} }
/**
* Page callback for the path "islandora".
*
* Redirects to the view of the object indicated by the Drupal variable
* islandora_repository_pid.
*/
function islandora_view_default_object() { function islandora_view_default_object() {
$pid = variable_get('islandora_repository_pid', 'islandora:root'); $pid = variable_get('islandora_repository_pid', 'islandora:root');
drupal_goto("islandora/object/$pid"); drupal_goto("islandora/object/$pid");
@ -396,14 +358,17 @@ function islandora_view_default_object() {
*/ */
function islandora_view_object($fedora_object = NULL) { function islandora_view_object($fedora_object = NULL) {
module_load_include('inc', 'islandora', 'includes/breadcrumb'); module_load_include('inc', 'islandora', 'includes/breadcrumb');
module_load_include('inc', 'islandora', 'includes/utilities');
global $user; global $user;
if (!$fedora_object) { if (!$fedora_object) {
return drupal_not_found(); return drupal_not_found();
} }
// set breadcrumbs
drupal_set_breadcrumb(islandora_get_breadcrumbs($fedora_object)); drupal_set_breadcrumb(islandora_get_breadcrumbs($fedora_object));
// optional pager parameters
$page_number = (empty($_GET['page'])) ? '1' : $_GET['page']; $page_number = (empty($_GET['page'])) ? '1' : $_GET['page'];
$page_size = (empty($_GET['pagesize'])) ? '10' : $_GET['pagesize']; $page_size = (empty($_GET['pagesize'])) ? '10' : $_GET['pagesize'];
@ -411,7 +376,7 @@ function islandora_view_object($fedora_object = NULL) {
$output = array(); $output = array();
// 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, $user, $page_number, $page_size);
if (!empty($temp)) { if (!empty($temp)) {
$output = array_merge_recursive($output, $temp); $output = array_merge_recursive($output, $temp);
@ -420,7 +385,7 @@ function islandora_view_object($fedora_object = NULL) {
// Add in the default, if we did not get any results. // Add in the default, if we did not get any results.
if (empty($output)) { if (empty($output)) {
$output = _islandora_islandora_view_object($fedora_object); $output = islandora_default_islandora_view_object($fedora_object);
} }
arsort($output); arsort($output);
@ -431,15 +396,16 @@ function islandora_view_object($fedora_object = NULL) {
} }
/** /**
* The default view hook. If there are no modules registered to handle this objects cmodels or there are * If there are no modules registered to handle this objects cmodels or there are
* not any cmodels specified this will create a default display. * not any cmodels specified this will create a default display.
* *
* @param string $object_id * @param FedoraObject $object
* @return string * The object whose display we are to render.
* @return array
*/ */
function _islandora_islandora_view_object($object) { function islandora_default_islandora_view_object($object) {
$output = theme('islandora_default', array('islandora_object' => $object)); $output = theme('islandora_default', array('islandora_object' => $object));
return array('Default Output' => $output); return array('Default output' => $output);
} }
/** /**
@ -551,10 +517,13 @@ function islandora_object_purge($object_id) {
drupal_set_message(t('Could not remove object, object not found')); drupal_set_message(t('Could not remove object, object not found'));
return; return;
} }
module_load_include('inc', 'islandora', 'includes/utilities');
$content_models = $object->models; $content_models = $object->models;
$arr = array(); $arr = array();
foreach (_islandora_build_hook_list(ISLANDORA_PRE_PURGE_OBJECT_HOOK, $object->models) as $hook) { foreach (islandora_build_hook_list(ISLANDORA_PRE_PURGE_OBJECT_HOOK, $object->models) as $hook) {
$temp = module_invoke_all($hook, $object); $temp = module_invoke_all($hook, $object);
if (!empty($temp)) { if (!empty($temp)) {
$arr = array_merge_recursive($arr, $temp); $arr = array_merge_recursive($arr, $temp);

Loading…
Cancel
Save