Browse Source

Changed how we get objects.

pull/122/merge
jonathangreen 13 years ago
parent
commit
1d7f26c8d9
  1. 5
      includes/Breadcrumbs.inc
  2. 128
      includes/datastream.inc
  3. 11
      includes/ingest-menu.inc
  4. 19
      includes/object_properties.inc
  5. 159
      includes/purge.form.inc
  6. 2
      islandora.api.php
  7. 345
      islandora.module
  8. 18
      islandora_basic_collection/islandora_basic_collection.module

5
includes/Breadcrumbs.inc

@ -1,11 +1,10 @@
<?php
function islandora_get_breadcrumbs($pid) {
module_load_include('inc', 'islandora', 'RestConnection');
function islandora_get_breadcrumbs($object) {
$breadcrumbs = array();
$connection = new RestConnection();
islandora_get_breadcrumbs_recursive($pid, $breadcrumbs, $connection->repository);
islandora_get_breadcrumbs_recursive($object->id, $breadcrumbs, $object->repository);
if(isset($breadcrumbs[0])) {
unset($breadcrumbs[0]);

128
includes/datastream.inc

@ -13,35 +13,22 @@ define('DS_COMP_STREAM', 'DS-COMPOSITE-MODEL');
* @return stream
* prints datastream to browser
*/
function islandora_datastream_as_attachment($object_id, $dsid) {
module_load_include('inc', 'islandora', 'RestConnection');
drupal_add_http_header("Cache-Control", 'public');
drupal_add_http_header("Pragma", FALSE);
global $user;
try {
$restConnection = new RestConnection($user);
$fedora_object = new FedoraObject($object_id, $restConnection->repository);
// if the object exists but the datastream doesn't
if(!isset($fedora_object[$dsid])) {
return drupal_not_found();
}
header('Content-type: ' . $fedora_object[$dsid]->mimetype);
if($fedora_object[$dsid]->controlGroup == 'M' || $fedora_object[$dsid]->controlGroup == 'X') {
header('Content-length: ' . $fedora_object[$dsid]->size);
}
$method = arg(5);
if (isset($method) && $method == 'download') {
header("Content-Disposition: attachment; filename=\"" . $fedora_object[$dsid]->label);
}
print($fedora_object[$dsid]->content);
exit();
} catch (Exception $e) {
function islandora_view_datastream($object, $dsid, $method = 'view') {
// if the object exists but the datastream doesn't
if(!isset($object[$dsid])) {
return drupal_not_found();
}
header('Content-type: ' . $object[$dsid]->mimetype);
if($object[$dsid]->controlGroup == 'M' || $object[$dsid]->controlGroup == 'X') {
header('Content-length: ' . $object[$dsid]->size);
}
if ($method == 'download') {
header("Content-Disposition: attachment; filename=\"" . $object[$dsid]->label);
}
print($object[$dsid]->content);
exit();
}
function islandora_datastream_get_parents($islandora_object) {
@ -96,26 +83,19 @@ function islandora_get_defined_dsids_array(&$arr, $ds_comp_stream) {
* @param string $object_id
* @return string|array
*/
function islandora_get_unused_dsids($object_id) {
module_load_include('inc', 'islandora', 'RestConnection');
global $user;
try {
$restConnection = new RestConnection($user);
$fedora_object = new FedoraObject($object_id, $restConnection->repository);
} catch (Exception $e) {
drupal_set_message(t('Error getting Islandora object %s ', array('%s' => $object_id)), 'error');
return;
}
if (!isset($fedora_object)) {
drupal_set_message(t('Could not create add datastream form for %s'), array('%s' => $object_id));
return;
}
$models = $fedora_object->models;
function islandora_get_unused_dsids($object) {
$defined_dsids = array();
if(!$object) {
return $defined_dsids;
}
$models = $object->models;
if (isset($models)) {
foreach ($models as $model) {
try {
$model_object = new FedoraObject($model, $restConnection->repository);
$model_object = $object->repository->getObject($model);
if (isset($model_object[DS_COMP_STREAM])) {
$dscomposite_stream = $model_object[DS_COMP_STREAM]->content;
islandora_get_defined_dsids_array($defined_dsids, $dscomposite_stream);
@ -140,8 +120,8 @@ function islandora_get_unused_dsids($object_id) {
* @return array
* a form ready to be rendered with a call to Drupal render
*/
function islandora_get_add_datastream_form($object_id, &$form_state) {
$unused_dsids = islandora_get_unused_dsids($object_id); //$defined_dsids;
function islandora_get_add_datastream_form($object, &$form_state) {
$unused_dsids = islandora_get_unused_dsids($object);
$form = array();
$form['add_fieldset'] = array(
'#type' => 'fieldset',
@ -298,7 +278,8 @@ function islandora_add_datastream_form_validate($form, &$form_state) {
}
$mimetype = new MimeClass();
$unused_dsids = islandora_get_unused_dsids($form_state['values']['pid']);
$object = islandora_object_load($form_state['values']['pid']);
$unused_dsids = islandora_get_unused_dsids($object);
if(isset($unused_dsids[$dsid])) {
$types_allowed = $unused_dsids[$dsid];
$arr = array();
@ -331,8 +312,8 @@ function islandora_add_datastream_form_validate($form, &$form_state) {
* @return array
* a form ready to be rendered with a call to Drupal render
*/
function islandora_add_datastream_form($form, &$form_state, $object_id) {
$unused_dsids = islandora_get_unused_dsids($object_id); //$defined_dsids;
function islandora_add_datastream_form($form, &$form_state, $object) {
$unused_dsids = islandora_get_unused_dsids($object); //$defined_dsids;
$form = array();
$form['add_fieldset'] = array(
'#type' => 'fieldset',
@ -347,7 +328,7 @@ function islandora_add_datastream_form($form, &$form_state, $object_id) {
$form['pid'] = array(
'#type' => 'hidden',
'#value' => "$object_id"
'#value' => "$object->id"
);
$form['add_fieldset']['stream_label'] = array(
@ -365,13 +346,13 @@ function islandora_add_datastream_form($form, &$form_state, $object_id) {
// '#required'=>'TRUE',
'#description' => t('The file to upload.')
);
$form['#redirect'] = "islandora/object/$object_id/";
$form['#redirect'] = "islandora/object/$object->id/";
$form['add_fieldset']['submit'] = array(
'#type' => 'submit',
'#value' => t('Add Datastream')
);
$unused_dsids = islandora_get_unused_dsids($object_id);
$unused_dsids = islandora_get_unused_dsids($object);
$dsidsForForm = '';
$i = 0;
foreach ($unused_dsids as $key => $value) {
@ -387,13 +368,13 @@ function islandora_add_datastream_form($form, &$form_state, $object_id) {
'#description' => t('An ID for this stream that is unique to this object. Must start with a letter and contain only alphanumeric characters and dashes and underscores. Datastreams that are defined by the content model dont currently exist: <b>' . $dsidsForForm . '</b>.'),
'#type' => 'textfield',
'#weight' => -1,
'#autocomplete_path' => "islandora/object/$object_id/manage/datastreams/add/autocomplete",
'#autocomplete_path' => "islandora/object/$object->id/manage/datastreams/add/autocomplete",
);
return $form;
}
function islandora_datastream_autocomplete_callback($object_id, $string = '') {
$dsids = islandora_get_unused_dsids($object_id);
function islandora_datastream_autocomplete_callback($object, $string = '') {
$dsids = islandora_get_unused_dsids($object);
$output = array();
foreach($dsids as $id => $ds) {
if(trim($string) == '') {
@ -455,34 +436,23 @@ function islandora_datastream_edit_get_link($object, $ds_id) {
}
}
function islandora_edit_datastream($object_id, $ds_id) {
global $user;
try {
module_load_include('inc', 'islandora', 'RestConnection');
$restConnection = new RestConnection($user);
$object = new FedoraObject($object_id, $restConnection->repository);
$edit_registry = module_invoke_all('islandora_edit_datastream_registry', $object, $ds_id);
$edit_count = count($edit_registry);
function islandora_edit_datastream($object, $ds_id) {
$edit_registry = module_invoke_all('islandora_edit_datastream_registry', $object, $ds_id);
$edit_count = count($edit_registry);
if ($edit_count == 0) {
// No edit implementations.
drupal_set_message(t('There are no edit methods specified for this datastream.'));
drupal_goto('islandora/object/' . $object->id . '/manage/datastreams');
}
elseif ($edit_count == 1) {
// One registry implementation, go there
drupal_goto($edit_registry[0]['url']);
}
else {
// Multiple edit routes registered
return islandora_edit_datastream_registry_render($edit_registry);
}
} catch (Exception $e) {
drupal_set_message(t('Error getting Islandora edit method for %s ', array('%s' => $object_id)), 'error');
return;
if ($edit_count == 0) {
// No edit implementations.
drupal_set_message(t('There are no edit methods specified for this datastream.'));
drupal_goto('islandora/object/' . $object->id . '/manage/datastreams');
}
elseif ($edit_count == 1) {
// One registry implementation, go there
drupal_goto($edit_registry[0]['url']);
}
else {
// Multiple edit routes registered
return islandora_edit_datastream_registry_render($edit_registry);
}
}
//@TODO: theme / preprocess

11
includes/ingest-menu.inc

@ -10,15 +10,18 @@
* @TODO: validate?: pid, registry return
* @param string $pid
*/
function islandora_ingest_callback($collection_pid) {
$ingest_registry = module_invoke_all('islandora_ingest_registry', $collection_pid);
function islandora_ingest_callback($collection_object) {
if(!$collection_object) {
return drupal_not_found();
}
$ingest_registry = module_invoke_all('islandora_ingest_registry', $collection_object);
$registry_count = count($ingest_registry);
if ($registry_count == 0) {
// No ingest implementations.
drupal_set_message(t('There are no ingest methods specified for this collection.'));
drupal_goto('islandora/object/' . $collection_pid);
drupal_set_message(t('There are no ingest methods specified for @name.', array('@name', $collection_object->label)));
drupal_goto('islandora/object/' . $collection_object->id);
}
elseif ($registry_count == 1) {
// One registry implementation, go there

19
includes/object_properties.inc

@ -10,7 +10,7 @@
* @return boolean
*/
function islandora_edit_properties_form_validate($form, &$form_state) {
$islandora_object = islandora_get_object($form_state['values']['pid']);
$islandora_object = islandora_object_load($form_state['values']['pid']);
if (!isset($islandora_object)) {
form_set_error('', t('Could not update properties object not found.'));
return FALSE;
@ -23,7 +23,7 @@ function islandora_edit_properties_form_validate($form, &$form_state) {
* @param array $form_state
*/
function islandora_edit_properties_form_submit($form, &$form_state) {
$islandora_object = islandora_get_object($form_state['values']['pid']);
$islandora_object = islandora_object_load($form_state['values']['pid']);
$owner = $form_state['values']['object_owner'];
$state = $form_state['values']['object_state'];
$label = $form_state['values']['object_label'];
@ -66,35 +66,34 @@ function islandora_edit_properties_form_delete($form, &$form_state) {
* an object id
* @return array
*/
function islandora_edit_properties_form($form, &$form_state, $object_id) {
function islandora_edit_properties_form($form, &$form_state, $object) {
$form = array();
$islandora_object = islandora_get_object($object_id);
drupal_set_title($islandora_object->label);
if (!isset($islandora_object)) {
if (!isset($object)) {
return NULL;
}
drupal_set_title($object->label);
$form['pid'] = array(
'#type' => 'hidden',
'#value' => $object_id,
'#value' => $object->id,
);
$form['object_label'] = array(
'#title' => t('Item Label'),
'#default_value' => $islandora_object->label,
'#default_value' => $object->label,
'#required' => 'TRUE',
'#description' => t('A Human readable label'),
'#type' => 'textfield'
);
$form['object_owner'] = array(
'#title' => t('Owner'),
'#default_value' => $islandora_object->owner,
'#default_value' => $object->owner,
'#required' => FALSE,
'#description' => t('The owner id'),
'#type' => 'textfield',
);
$form['object_state'] = array(
'#title' => t('State'),
'#default_value' => $islandora_object->state,
'#default_value' => $object->state,
'#required' => TRUE,
'#description' => t('The items state one of active, inactive or deleted'),
'#type' => 'select',

159
includes/purge.form.inc

@ -0,0 +1,159 @@
<?php
/**
* Gives the option of deleting or purging and object.
*
* The default behaviour is to purge the object to reduce maintenance.
* If a solution pack wants to change this behaviour and have the object set to deleted then
* it can respond to the 'islandora_pre_purge_object' hook with an array containing the pair
* 'delete' => TRUE.
* Once the object has been deleted/purged then a second call lets the solution packs know that
* the object has been dealt with. In this call the object id and content models are sent out so
* that the solution packs can act on this news. There is no guarantee that the object still exists
* and so the object object isn't sent.
*
* @param string $object_id
* ID of the object
* @return type
*/
function islandora_purge_object_submit($form, &$form_state) {
$object_id = $form_state['values']['pid'];
$collection = $form_state['values']['col'];
if (!isset($object_id)) {
drupal_set_message(t('Cannot remove object, object id not set'));
return;
}
$object = islandora_object_load($object_id);
if (!isset($fedora_object)) {
drupal_set_message(t('Could not remove object, object not found'));
return;
}
$content_models = $fedora_object->models;
$arr = module_invoke_all('islandora_pre_purge_object', $fedora_object); //notify modules of pending deletion
if (isset($arr['delete']) && $arr['delete']) {
try {
$fedora_object->delete();
} catch (Exception $e) {
drupal_set_message(t('Error deleting Islandora object %s %e', array('%s' => $object_id, '%e' => $e)), 'error');
return "";
}
}
else {
try {
$restConnection->repository->purgeObject($object_id);
} catch (Exception $e) {
drupal_set_message(t('Error purging Islandora object %s %e', array('%s' => $object_id, '%e' => $e)), 'error');
return "";
}
}
module_invoke_all('islandora_post_purge_object', $object_id, $content_models); //notify modules post deletion
drupal_goto($collection);
}
function islandora_purge_object($form, &$form_state, $object) {
module_load_include('inc', 'islandora', 'includes/datastream');
$parent = islandora_datastream_get_parents($object);
$key = array_keys($parent);
if (count($key) > 0) {
$redirect = "islandora/object/$key[0]";
}
else {
$redirect = "islandora";
}
$form['pid'] = array('#type' => 'value', '#value' => $object->id);
$form['col'] = array('#type' => 'value', '#value' => $redirect);
return confirm_form($form,
t('Are you sure you want to delete %title?', array('%title' => $object->label)),
"islandora/object/$object->id",
t('This action cannot be undone.'),
t('Delete'),
t('Cancel')
);
}
function islandora_purge_datastream($form, &$form_state, $object, $datastream_id) {
module_load_include('inc', 'islandora', 'includes/datastream');
$datastream = $object->getDatastream($datastream_id);
$redirect = "islandora/object/$object->id";
$form['pid'] = array('#type' => 'value', '#value' => $object->id);
$form['dsid'] = array('#type' => 'value', '#value' => $datastream_id);
$form['col'] = array('#type' => 'value', '#value' => $redirect);
return confirm_form($form,
t('Are you sure you want to delete the %dsid datastream?', array('%dsid' => $datastream->id)),
"islandora/object/$object->id",
t('This action cannot be undone.'),
t('Delete'),
t('Cancel')
);
}
/**
* Gives the option of purging or deleting a datastream.
*
* The default behaviour is to purge the datastream but this can be overridden using the
* 'islandora_pre_purge_datastream' hook. The returned array can include a 'block' => TRUE
* pair which will prevent the datastream from being deleted if it particularly needed for
* a certain function. Returning 'delete' => TRUE will cause the datastream to be put into
* a deleted state.
*
* @param string $object_id
* ID of the object
* @param string $datastream_id
* ID of the datastream
*
*/
function islandora_purge_datastream_submit($form, &$form_state) {
$object_id = $form_state['values']['pid'];
$datastream_id = $form_state['values']['dsid'];
if (!isset($datastream_id)) {
drupal_set_message(t('Cannot remove datastream, datastream id not set'));
return;
}
$object = islandora_object_load($object_id);
if (!isset($object)) {
drupal_set_message(t('Could not remove object, object not found'));
return;
}
//notify modules of pending deletion so we can update rels etc
$arr = module_invoke_all('islandora_pre_purge_datastream', $object[$datastream_id]);
if (isset($arr['block']) && $arr['block']) {
drupal_set_message(t('Purging of the %d datastream was blocked', array('%d' => $datastream_id)), 'warning');
return;
}
if (isset($arr['delete']) && $arr['delete']) {
try {
$object[$datastream_id]->state = 'D';
} catch (Exception $e) {
drupal_set_message(t('Error deleting %s datastream from Islandora object %o %e', array('%s' => $datastream_id, '%o' => $object->id, '%e' => $e)), 'error');
return;
}
}
else {
try {
$object->purgeDatastream($datastream_id);
} catch (Exception $e) {
drupal_set_message(t('Error purging %s datastream from Islandora object %o %e', array('%s' => $datastream_id, '%o' => $object_id, '%e' => $e)), 'error');
return;
}
}
//notify modules post deletion
module_invoke_all('islandora_post_purge_datastream', $object, $datastream_id);
drupal_set_message(t('%d datastream sucessfully purged from Islandora object %o', array('%d' => $datastream_id, '%o' => $object->id)));
drupal_goto('islandora/object/' . $object->id);
}

2
islandora.api.php

@ -25,4 +25,4 @@ function hook_islandora_datastream_edit($object, $dsid){}
* array('name' => t('Ingest Route Name'), 'url' => 'ingest_route/url', 'weight' => 0),
* );
*/
function hook_islandora_ingest_registry($collection_pid) {}
function hook_islandora_ingest_registry($collection_object) {}

345
islandora.module

@ -59,13 +59,13 @@ function islandora_menu() {
'weight' => -1,
);
$items['islandora/ingest/%'] = array(
'title' => 'Ingest object',
$items['islandora/object/%islandora_object/manage/ingest'] = array(
'title' => 'Add an object',
'page callback' => 'islandora_ingest_callback',
'page arguments' => array(2),
'file' => 'includes/ingest-menu.inc',
'type' => MENU_CALLBACK,
'access callback' => 'islandora_access_callback',
'type' => MENU_LOCAL_ACTION,
'access callback' => 'islandora_ingest_access_callback',
'access arguments' => array(2, FEDORA_INGEST),
);
@ -76,7 +76,7 @@ function islandora_menu() {
'access arguments' => array(FEDORA_VIEW),
);
$items['islandora/object/%'] = array(
$items['islandora/object/%islandora_object'] = array(
'title' => 'Repository',
'page callback' => 'islandora_view_object',
'page arguments' => array(2),
@ -86,25 +86,19 @@ function islandora_menu() {
);
$items['islandora/object/%/view'] = array(
$items['islandora/object/%islandora_object/view'] = array(
'title' => 'View',
'page arguments' => array(2),
'type' => MENU_DEFAULT_LOCAL_TASK,
'access callback' => 'islandora_access_callback',
'access arguments' => array(2, FEDORA_VIEW),
'weight' => -10
'weight' => -1,
);
$items['islandora/object/%/view/default'] = array(
$items['islandora/object/%islandora_object/view/default'] = array(
'title' => 'View',
'page callback' => 'islandora_view_object',
'page arguments' => array(2),
'type' => MENU_LOCAL_TASK,
'access callback' => 'islandora_access_callback',
'access arguments' => array(2, FEDORA_VIEW),
'weight' => -10,
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -1,
);
$items['islandora/object/%/manage'] = array(
$items['islandora/object/%islandora_object/manage'] = array(
'title' => 'Manage',
'page callback' => 'islandora_edit_object',
'page arguments' => array(2),
@ -113,17 +107,13 @@ function islandora_menu() {
'access arguments' => array(2, FEDORA_MODIFY_STATE),
);
$items['islandora/object/%/manage/datastreams'] = array(
$items['islandora/object/%islandora_object/manage/datastreams'] = array(
'title' => 'Datastreams',
//'page callback' => 'islandora_edit_object',
'page arguments' => array(2),
'type' => MENU_DEFAULT_LOCAL_TASK,
'access callback' => 'islandora_access_callback',
'access arguments' => array(2, FEDORA_PURGE),
'weight' => -10,
);
$items['islandora/object/%/manage/properties'] = array(
$items['islandora/object/%islandora_object/manage/properties'] = array(
'title' => 'Properties',
'page callback' => 'drupal_get_form',
'file' => 'includes/object_properties.inc',
@ -134,8 +124,9 @@ function islandora_menu() {
'weight' => -5,
);
$items['islandora/object/%/delete'] = array(
$items['islandora/object/%islandora_object/delete'] = array(
'title' => 'Delete object',
'file' => 'includes/purge.form.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_purge_object', 2),
'type' => MENU_CALLBACK,
@ -143,17 +134,17 @@ function islandora_menu() {
'access arguments' => array(2, FEDORA_PURGE),
);
$items['islandora/object/%/manage/datastreams/add'] = array(
$items['islandora/object/%islandora_object/manage/datastreams/add'] = array(
'title' => 'Add a datastream',
'file' => 'includes/datastream.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_add_datastream_form', 2),
'type' => MENU_NORMAL_ITEM,
'type' => MENU_LOCAL_ACTION,
'access callback' => 'islandora_access_callback',
'access arguments' => array(2, FEDORA_ADD_DS)
);
$items['islandora/object/%/manage/datastreams/add/autocomplete'] = array(
$items['islandora/object/%islandora_object/manage/datastreams/add/autocomplete'] = array(
'file' => 'includes/datastream.inc',
'page callback' => 'islandora_datastream_autocomplete_callback',
'page arguments' => array(2),
@ -162,9 +153,9 @@ function islandora_menu() {
'access arguments' => array(2, FEDORA_ADD_DS)
);
$items['islandora/object/%/datastream/%'] = array(
$items['islandora/object/%islandora_object/datastream/%'] = array(
'title' => 'View datastream',
'page callback' => 'islandora_datastream_as_attachment',
'page callback' => 'islandora_view_datastream',
'page arguments' => array(2, 4),
'type' => MENU_CALLBACK,
'file' => 'includes/datastream.inc',
@ -172,27 +163,22 @@ function islandora_menu() {
'access arguments' => array(2, FEDORA_VIEW),
);
$items['islandora/object/%/datastream/%/view'] = array(
$items['islandora/object/%islandora_object/datastream/%/view'] = array(
'title' => 'View datastream',
'page callback' => 'islandora_datastream_as_attachment',
'page arguments' => array(2, 4),
'type' => MENU_CALLBACK,
'file' => 'includes/datastream.inc',
'access callback' => 'islandora_access_callback',
'access arguments' => array(2, FEDORA_VIEW),
'type' => MENU_DEFAULT_LOCAL_TASK,
);
$items['islandora/object/%/datastream/%/download'] = array(
$items['islandora/object/%islandora_object/datastream/%/download'] = array(
'title' => 'Download datastream',
'page callback' => 'islandora_datastream_as_attachment',
'page arguments' => array(2, 4),
'page callback' => 'islandora_view_datastream',
'page arguments' => array(2, 4, 5),
'type' => MENU_CALLBACK,
'file' => 'includes/datastream.inc',
'access callback' => 'islandora_access_callback',
'access arguments' => array(2, FEDORA_VIEW),
);
$items['islandora/object/%/datastream/%/edit'] = array(
$items['islandora/object/%islandora_object/datastream/%/edit'] = array(
'title' => 'Edit datastream',
'page callback' => 'islandora_edit_datastream',
'page arguments' => array(2, 4),
@ -202,10 +188,11 @@ function islandora_menu() {
'access arguments' => array(2, FEDORA_METADATA_EDIT),
);
$items['islandora/object/%/datastream/%/delete'] = array(
$items['islandora/object/%islandora_object/datastream/%/delete'] = array(
'title' => 'Purge data stream',
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_purge_datastream', 2, 4),
'file' => 'includes/purge.form.inc',
'type' => MENU_CALLBACK,
'access callback' => 'islandora_access_callback',
'access arguments' => array(2, FEDORA_PURGE),
@ -214,26 +201,10 @@ function islandora_menu() {
return $items;
}
function islandora_admin_paths_alter(&$paths) {
function islandora_admin_paths() {
$paths = array();
$paths['*/manage*'] = TRUE;
}
/**
* Implements hook_menu_local_tasks_alter().
*/
function islandora_menu_local_tasks_alter(&$data, $router_item, $root_path) {
// Add action link 'islandora/object/%/manage/datastreams'.
if ($root_path == 'islandora/object/%/manage') {
$object_id = $router_item['page_arguments'][0];
$item = menu_get_item("islandora/object/$object_id/manage/datastreams/add");
if ($item['access']) {
$data['actions']['output'][] = array(
'#theme' => 'menu_local_action',
'#link' => $item,
);
}
}
return $paths;
}
/**
@ -258,103 +229,12 @@ function islandora_access_callback($pid = NULL, $perm = NULL) {
else {
$pid_namespace = substr($pid, 0, strpos($pid, ':') + 1); //Get the namespace (with colon)
$allowed_namespaces = explode(" ", variable_get('islandora_pids_allowed', 'default: demo: changeme: islandora: ilives: islandora-book: books: newspapers: '));
$namespace_access = in_array($pid_namespace, $allowed_namespaces);
}
return ($namespace_access && user_access($perm));
}
/**
* Gives the option of deleting or purging and object.
*
* The default behaviour is to purge the object to reduce maintenance.
* If a solution pack wants to change this behaviour and have the object set to deleted then
* it can respond to the 'islandora_pre_purge_object' hook with an array containing the pair
* 'delete' => TRUE.
* Once the object has been deleted/purged then a second call lets the solution packs know that
* the object has been dealt with. In this call the object id and content models are sent out so
* that the solution packs can act on this news. There is no guarantee that the object still exists
* and so the object object isn't sent.
*
* @param string $object_id
* ID of the object
* @return type
*/
function islandora_purge_object_submit($form, &$form_state) {
$object_id = $form_state['values']['pid'];
$collection = $form_state['values']['col'];
module_load_include('inc', 'islandora', 'RestConnection');
global $user;
if (!isset($object_id)) {
drupal_set_message(t('Cannot remove object, object id not set'));
return;
}
try {
$restConnection = new RestConnection($user);
$fedora_object = new FedoraObject($object_id, $restConnection->repository);
} catch (Exception $e) {
drupal_set_message(t('Error getting Islandora object %s %e', array('%s' => $object_id, '%e' => $e)), 'error');
return "";
}
if (!isset($fedora_object)) {
drupal_set_message(t('Could not remove object, object not found'));
return;
}
$content_models = $fedora_object->models;
$arr = module_invoke_all('islandora_pre_purge_object', $fedora_object); //notify modules of pending deletion
if (isset($arr['delete']) && $arr['delete']) {
try {
$fedora_object->delete();
} catch (Exception $e) {
drupal_set_message(t('Error deleting Islandora object %s %e', array('%s' => $object_id, '%e' => $e)), 'error');
return "";
}
}
else {
try {
$restConnection->repository->purgeObject($object_id);
} catch (Exception $e) {
drupal_set_message(t('Error purging Islandora object %s %e', array('%s' => $object_id, '%e' => $e)), 'error');
return "";
}
}
module_invoke_all('islandora_post_purge_object', $object_id, $content_models); //notify modules post deletion
drupal_goto($collection);
}
function islandora_purge_object($form, &$form_state, $pid) {
module_load_include('inc', 'islandora', 'RestConnection');
module_load_include('inc', 'islandora', 'includes/datastream');
$connection = new RestConnection();
$object = $connection->repository->getObject($pid);
$parent = islandora_datastream_get_parents($object);
$key = array_keys($parent);
if (count($key) > 0) {
$redirect = "islandora/object/$key[0]";
}
else {
$redirect = "islandora";
}
// Always provide entity id in the same form key as in the entity edit form.
$form['pid'] = array('#type' => 'value', '#value' => $pid);
$form['col'] = array('#type' => 'value', '#value' => $redirect);
return confirm_form($form,
t('Are you sure you want to delete %title?', array('%title' => $object->label)),
"islandora/object/$pid",
t('This action cannot be undone.'),
t('Delete'),
t('Cancel')
);
}
/**
* returns an array listing object types provided by sub modules
* @return array
@ -376,18 +256,12 @@ function islandora_init() {
* @param string $object_id
* @return string
*/
function islandora_edit_object($object_id) {
module_load_include('inc', 'islandora', 'RestConnection');
global $user;
try {
$restConnection = new RestConnection($user);
$fedora_object = new FedoraObject($object_id, $restConnection->repository);
} catch (Exception $e) {
drupal_set_message(t('Error getting Islandora object %s', array('%s' => $object_id)), 'error');
return"";
function islandora_edit_object($object) {
if(!$object) {
return drupal_not_found();
}
drupal_alter('islandora_edit_object', $fedora_object);
$arr = module_invoke_all('islandora_edit_object', $fedora_object);
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
@ -402,7 +276,7 @@ function islandora_edit_object($object_id) {
* @return string
*/
function islandora_edit_properties($object_id) {
$object = islandora_get_object($object_id);
$object = islandora_object_load($object_id);
if (isset($object)) {
module_load_include('inc', 'islandora', 'includes/object_properties');
$form = drupal_get_form('islandora_edit_properties_form', $object);
@ -430,97 +304,6 @@ function islandora_islandora_edit_object($fedora_object) {
return array('Default Edit output' => $output);
}
function islandora_purge_datastream($form, &$form_state, $object_id, $datastream_id) {
module_load_include('inc', 'islandora', 'RestConnection');
module_load_include('inc', 'islandora', 'includes/datastream');
$connection = new RestConnection();
$object = $connection->repository->getObject($object_id);
$datastream = $object->getDatastream($datastream_id);
$redirect = "islandora/object/$object_id";
// Always provide entity id in the same form key as in the entity edit form.
$form['pid'] = array('#type' => 'value', '#value' => $object_id);
$form['dsid'] = array('#type' => 'value', '#value' => $datastream_id);
$form['col'] = array('#type' => 'value', '#value' => $redirect);
return confirm_form($form,
t('Are you sure you want to delete the %dsid datastream?', array('%dsid' => $datastream->id)),
"islandora/object/$object_id",
t('This action cannot be undone.'),
t('Delete'),
t('Cancel')
);
}
/**
* Gives the option of purging or deleting a datastream.
*
* The default behaviour is to purge the datastream but this can be overridden using the
* 'islandora_pre_purge_datastream' hook. The returned array can include a 'block' => TRUE
* pair which will prevent the datastream from being deleted if it particularly needed for
* a certain function. Returning 'delete' => TRUE will cause the datastream to be put into
* a deleted state.
*
* @param string $object_id
* ID of the object
* @param string $datastream_id
* ID of the datastream
*
*/
function islandora_purge_datastream_submit($form, &$form_state) {
module_load_include('inc', 'islandora', 'RestConnection');
$object_id = $form_state['values']['pid'];
$datastream_id = $form_state['values']['dsid'];
global $user;
if (!isset($datastream_id)) {
drupal_set_message(t('Cannot remove datastream, datastream id not set'));
return;
}
try {
$restConnection = new RestConnection($user);
$fedora_object = new FedoraObject($object_id, $restConnection->repository);
} catch (Exception $e) {
drupal_set_message(t('Error getting Islandora object %s %e', array('%s' => $object_id, '%e' => $e)), 'error');
return "";
}
if (!isset($fedora_object)) {
drupal_set_message(t('Could not remove object, object not found'));
return;
}
if (!isset($fedora_object)) {
drupal_set_message(t('Could not remove object, object not found'));
return;
}
$arr = module_invoke_all('islandora_pre_purge_datastream', $fedora_object, $datastream_id); //notify modules of pending deletion so we can update rels etc
if (isset($arr['block']) && $arr['block']) {
drupal_set_message(t('Purging of the %d datastream was blocked', array('%d' => $datastream_id)), 'warning');
return;
}
if (isset($arr['delete']) && $arr['delete']) {
try {
$datastream = new FedoraDatastream($datastream_id, $fedora_object, $restConnection->repository);
$datastream->state = 'D';
} catch (Exception $e) {
drupal_set_message(t('Error deleting %s datastream from Islandora object %o %e', array('%s' => $datastream_id, '%o' => $object_id, '%e' => $e)), 'error');
return;
}
}
else {
try {
$fedora_object->purgeDatastream($datastream_id);
} catch (Exception $e) {
drupal_set_message(t('Error purging %s datastream from Islandora object %o %e', array('%s' => $datastream_id, '%o' => $object_id, '%e' => $e)), 'error');
return;
}
}
module_invoke_all('islandora_post_purge_datastream', $fedora_object, $datastream_id); //notify modules post deletion
drupal_set_message(t('%d datastream sucessfully purged from Islandora object %o', array('%d' => $datastream_id, '%o' => $object_id)));
drupal_goto('islandora/object/' . $object_id);
}
function islandora_view_default_object() {
$pid = variable_get('islandora_repository_pid', 'islandora:root');
drupal_goto("islandora/object/$pid");
@ -534,26 +317,19 @@ function islandora_view_default_object() {
*
* @return string
*/
function islandora_view_object($object_id = NULL) {
function islandora_view_object($fedora_object = NULL) {
module_load_include('inc', 'islandora', 'includes/Breadcrumbs');
drupal_set_breadcrumb(islandora_get_breadcrumbs($object_id));
//return $object_id;
if (!isset($object_id)) {
$object_id = variable_get('islandora_repository_pid', 'islandora:root');
//return;
global $user;
if(!$fedora_object) {
return drupal_not_found();
}
drupal_set_breadcrumb(islandora_get_breadcrumbs($fedora_object));
$page_number = (empty($_GET['page'])) ? '1' : $_GET['page'];
$page_size = (empty($_GET['pagesize'])) ? '10' : $_GET['pagesize'];
module_load_include('inc', 'islandora', 'RestConnection');
global $user;
try {
$restConnection = new RestConnection($user);
$fedora_object = new FedoraObject($object_id, $restConnection->repository);
} catch (Exception $e) {
drupal_set_message(t('Error getting Islandora object %s', array('%s' => $object_id)), 'error');
return"";
}
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)) {
@ -695,16 +471,20 @@ function islandora_preprocess_islandora_default(&$variables) {
* @param string $object_id
* @return FedoraObject
*/
function islandora_get_object($object_id) {
function islandora_object_load($object_id) {
module_load_include('inc', 'islandora', 'RestConnection');
global $user;
static $restConnection = NULL;
if(!$restConnection) {
$restConnection = new RestConnection();
}
try {
$restConnection = new RestConnection($user);
$fedora_object = new FedoraObject($object_id, $restConnection->repository);
$fedora_object = $restConnection->repository->getObject($object_id);
} catch (Exception $e) {
drupal_set_message(t('Error getting Islandora object %s', array('%s' => $object_id)), 'error');
return NULL;
}
return $fedora_object;
}
@ -749,3 +529,18 @@ function islandora_preprocess_islandora_default_edit(&$variables) {
$table = array('colgroups' => NULL, 'sticky' => TRUE, 'empty' => 'Error loading datastreams', 'caption' => $caption, 'header' => $header, 'rows' => $rows, 'attributes' => $table_attributes);
$variables['datastream_table'] = theme_table($table);
}
function islandora_ingest_access_callback($object, $perm) {
if(islandora_access_callback($object, $perm) === FALSE) {
return FALSE;
}
$ingest_registry = module_invoke_all('islandora_ingest_registry', $object);
if(count($ingest_registry) > 0) {
return TRUE;
}
else {
return FALSE;
}
}

18
islandora_basic_collection/islandora_basic_collection.module

@ -67,24 +67,6 @@ function islandora_basic_collection_init() {
}
}
/**
* Implements hook_menu_local_tasks_alter().
*/
function islandora_basic_collection_menu_local_tasks_alter(&$data, $router_item, $root_path) {
// Add action link
if ($root_path == 'islandora/object/%/manage/collection') {
$object_id = $router_item['page_arguments'][0];
$item = menu_get_item("islandora/ingest/$object_id");
$item['title'] = 'Add a repository item';
if ($item['access']) {
$data['actions']['output'][] = array(
'#theme' => 'menu_local_action',
'#link' => $item,
);
}
}
}
/**
* This function is where we create the view for the related menu item
* @param type $object_id

Loading…
Cancel
Save