@ -31,9 +31,11 @@ define('FEDORA_PURGE', 'delete fedora objects and datastreams');
define('FEDORA_MODIFY_STATE', 'modify fedora state');
define('FEDORA_MANAGE', 'manage fedora items');
// h ooks
// H ooks
define('ISLANDORA_VIEW_HOOK', 'islandora_view_object');
define('ISLANDORA_EDIT_HOOK', 'islandora_edit_object');
define('ISLANDORA_POST_INGEST_HOOK', 'islandora_ingest_post_ingest');
define('ISLANDORA_PRE_PURGE_OBJECT_HOOK', 'islandora_pre_purge_object');
/**
* Implements hook_menu().
@ -250,11 +252,40 @@ function islandora_access_callback($object = NULL, $perm = NULL) {
}
/**
* returns an array listing object types provided by sub modules
* Returns an array listing object types.
*
* @param string $model
* A string representing a short content model URI, to only get the relevant
* elements.
*
* @return array
* An associative array mapping cmodel pids to modules to a boolean
* indicating if the hook on the given module should be called.
*
* @todo
* Rename this function and the hook, as it now has a wider usage.
*/
function islandora_get_types() {
return module_invoke_all('islandora_get_types');
function islandora_get_types($model = NULL) {
$types = &drupal_static(__FUNCTION__);
if ($types === NULL) {
$types = module_invoke_all('islandora_get_types');
drupal_alter('islandora_get_types', $types);
// TODO: Add in the defaults, where there's no view or edit?
}
if ($model !== NULL) {
if (isset($types[$model])) {
return $types[$model];
}
else {
return array();
}
}
else {
return $types;
}
}
function islandora_init() {
@ -287,13 +318,64 @@ function islandora_edit_object($object) {
if (!$object) {
return drupal_not_found();
}
drupal_alter('islandora_edit_object', $object);
$arr = module_invoke_all('islandora_edit_object', $object);
$output = "";
foreach ($arr as $key => $value) {
$output .= $value; //if we have multiple modules handle one cmodel we need to iterate over multiple
$output = islandora_invoke(ISLANDORA_EDIT_HOOK, $object);
// Add in the default, if we did not get any results.
if (empty($output)) {
$output = islandora_islandora_edit_object($object);
}
//we could do another module invoke all here to build the edit tab with a default implemented in this module?
return implode('', $output);
}
/**
* Invoke a hook registered via islandora_get_types().
*
* @param string $hook
* The hook to invoke.
* @param object $object
* The object to be affected by the hook.
* @param ...
* An optional variable list of arguments.
*
* @return array
* The array of results.
*/
function islandora_invoke($hook, $object) {
// Allow altering of the object, before processing.
drupal_alter($hook, $object);
// Accumulate the output
$output = array();
// Get the models...
$supported_models = islandora_get_types();
// Filter them down to only the ones explicitly supported.
$models = array_intersect(array_keys($supported_models), $object->models);
// And actually call out to accumulate the output for each model.
foreach($models as $model) {
foreach ($supported_models[$model] as $module => $hooks) {
if (isset($hooks[$hook]) && $hooks[$hook]) {
$args = func_get_args();
// Add the module into the list of args, and call module_invoke.
array_unshift($args, $module);
$return = call_user_func_array('module_invoke', $args);
if (is_array($return)) {
$output = array_merge_recursive($output, $return);
}
}
}
}
arsort($output);
drupal_alter($hook . '_output', $output);
return $output;
}
@ -314,20 +396,16 @@ function islandora_edit_properties($object_id) {
}
/**
* builds a default page for the edit tab
* Builds a default page for the edit tab.
*
* @param object $fedora_object
* A tuque Fedora Object
*/
function islandora_islandora_edit_object($fedora_object) {
$supported_models = islandora_get_types();
$output = "";
foreach ($fedora_object->models as $model) {
if (isset($supported_models[$model][ISLANDORA_EDIT_HOOK]) && $supported_models[$model][ISLANDORA_EDIT_HOOK] == TRUE) {//another module is handling the view
return;
}
}
$output = theme('islandora_default_edit', array('islandora_object' => $fedora_object));
$output = theme('islandora_default_edit', array(
'islandora_object' => $fedora_object,
));
return array('Default Edit output' => $output);
}
@ -357,20 +435,13 @@ function islandora_view_object($fedora_object = NULL) {
$page_number = (empty($_GET['page'])) ? '1' : $_GET['page'];
$page_size = (empty($_GET['pagesize'])) ? '10' : $_GET['pagesize'];
drupal_alter('islandora_object', $fedora_object); //modify object if required before it is passed along
$arr = module_invoke_all('islandora_view_object', $fedora_object, $user, $page_number, $page_size); //allow submodules to decide how to handle content base on object type
if (empty($arr)) {
//TODO: make sure we iterate over the array as they will be more then one cmodel per object
drupal_set_message(t('there was an error loading the view for islandora object %s', array('%s' => $object_id)), 'error');
return "";
}
arsort($arr);
drupal_alter('islandora_display', $arr);
$output = "";
foreach ($arr as $key => $value) {
$output .= $value; //if we have multiple modules handle one cmodel we need to iterate over multiple
$output = islandora_invoke(ISLANDORA_VIEW_HOOK, $fedora_object, $user, $page_number, $page_size);
if (empty($output)) {
$output = islandora_islandora_view_object($fedora_object);
}
return $output;
return implode('', $output);
}
/**
@ -381,13 +452,6 @@ function islandora_view_object($fedora_object = NULL) {
* @return string
*/
function islandora_islandora_view_object($object) {
$supported_models = islandora_get_types();
$output = "";
foreach ($object->models as $model) {
if (isset($supported_models[$model][ISLANDORA_VIEW_HOOK]) && (boolean) $supported_models[$model][ISLANDORA_VIEW_HOOK] === TRUE) {//another module is handling the view
return;
}
}
$output = theme('islandora_default', array('islandora_object' => $object));
return array('Default Output' => $output);
}
@ -459,7 +523,7 @@ function islandora_permission() {
*/
function islandora_object_load($object_id) {
module_load_include('inc', 'islandora', 'includes/tuque');
static $islandora_tuque = NULL ;
$islandora_tuque = &drupal_static(__FUNCTION__) ;
if (!$islandora_tuque) {
$islandora_tuque = new IslandoraTuque();
@ -471,6 +535,8 @@ function islandora_object_load($object_id) {
} catch (Exception $e) {
return NULL;
}
drupal_alter('islandora_object', $fedora_object);
return $fedora_object;
}
else {
@ -500,7 +566,7 @@ function islandora_object_purge($object_id) {
return;
}
$content_models = $object->models;
$arr = module_invoke_all('islandora_pre_purge_object' , $object); // notify modules of pending deletion
$arr = islandora_invoke(ISLANDORA_PRE_PURGE_OBJECT_HOOK , $object); // notify modules of pending deletion
if (isset($arr['delete']) && $arr['delete']) {
try {
$object->delete();
@ -517,6 +583,7 @@ function islandora_object_purge($object_id) {
return "";
}
}
module_invoke_all('islandora_post_purge_object', $object_id, $content_models); // notify modules post deletion
}