From d26e46abbcbe21e08cd4507cd9799e0a0a199ef1 Mon Sep 17 00:00:00 2001 From: Alexander O'Neill Date: Tue, 14 Dec 2010 17:39:22 -0400 Subject: [PATCH 1/2] Fix ISLANDORA-117 Purging an object should go back to a node. --- ObjectHelper.inc | 5 +- fedora_repository.module | 90 +++++++++++++++++++++----------- plugins/pidfield/pidfield.module | 2 +- 3 files changed, 64 insertions(+), 33 deletions(-) diff --git a/ObjectHelper.inc b/ObjectHelper.inc index 7520907c..c22d39b9 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -474,8 +474,9 @@ class ObjectHelper { $allow= fedora_fesl_check_roles($object_pid,'write'); } if ($allow) { - $purgeObject = '' . t('Purge Object') . '' . t('Purge Object') . ''; + //$purgeObject = '' . t('Purge Object') . '' . t('Purge Object') . ''; + $purgeObject = drupal_get_form('fedora_repository_purge_object_form', $object_pid, check_plain(request_uri())); } } else { $purgeObject = ' '; diff --git a/fedora_repository.module b/fedora_repository.module index 093bdb2d..7f48fa35 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -62,6 +62,7 @@ function fedora_repository_purge_object($pid = NULL, $name = NULL) { '%name' => $name, '%pid' => $pid) ); + $output .= drupal_get_form('fedora_repository_purge_object_form', $pid); return $output; } @@ -233,20 +234,40 @@ function fedora_repository_ingest_form(&$form_state, $collection_pid, $collectio return $ingestForm->createIngestForm($collection_pid, $collection_label, $form_state); } -function fedora_repository_purge_object_form(&$form_state, $pid, $collectionPid = NULL) { +function fedora_repository_purge_object_form(&$form_state, $pid, $referrer) { + global $base_url; + // $form['#redirect'] = "fedora/repository/$collectionPid/"; $form['pid'] = array( '#type' => 'hidden', '#value' => "$pid" ); + if (!strstr( drupal_get_destination(), urlencode('fedora/repository'))) { + $form['referrer'] = array( + '#type' => 'hidden', + '#value' => $referrer, + ); + } + if(!isset($form_state['storage']['confirm'])) { + // do your normal $form definition here - $form['submit'] = array( - '#type' => 'submit', - '#value' => t('Purge') - ); - if ($collectionPid == NULL) { - $collectionPid = $_SESSION['fedora_collection']; + + $form['submit'] = array( + '#type' => 'image_button', + '#src' => drupal_get_path('module', 'fedora_repository').'/images/purge_big.png', + '#value' => t('Purge') + ); + if ($collectionPid == NULL) { + $collectionPid = $_SESSION['fedora_collection']; + } + //$form['#redirect'] = $referrer; + + return $form; + } + else { + // ALSO do $form definition here. Your final submit handler (after user clicks Yes, I Confirm) will only see $form_state info defined here. Form you create here passed as param1 to confirm_form + + return confirm_form($form,'You Sure?', $base_url.$referrer, 'Description text','Yes, nuke it','Cancel'); //Had better luck leaving off last param 'name' } - // $form['#redirect'] = "fedora/repository/$collectionPid/"; return $form; } @@ -384,31 +405,40 @@ function fedora_repository_purge_object_form_submit($form, &$form_state) { module_load_include('inc', 'fedora_repository', 'ConnectionHelper'); //$client = getSoapClient(variable_get('fedora_soap_manage_url', 'http://localhost:8080/fedora/services/management?wsdl')); $pid = $form_state['values']['pid']; - - $params = array( - "pid" => $pid, - "logMessage" => "Purged", - "force" => "" - ); - try { - $soapHelper = new ConnectionHelper(); - $client = $soapHelper->getSoapClient(variable_get('fedora_soap_manage_url', 'http://localhost:8080/fedora/services/management?wsdl')); - $object = $client->__soapCall('purgeObject', array( - $params - ) + if (!isset($form_state['storage']['confirm'])) { + $form_state['storage']['confirm'] = TRUE; // this will cause the form to be rebuilt, entering the confirm part of the form + $form_state['rebuild'] = TRUE; // along with this + } + else { + // this is where you do your processing after they have pressed the confirm button + $params = array( + "pid" => $pid, + "logMessage" => "Purged", + "force" => "" ); - } catch (exception $e) { - if (preg_match('/org\.fcrepo\.server\.security\.xacml\.pep\.AuthzDeniedException/',$e->getMessage())) { - drupal_set_message(t('Error: Insufficient permissions to purge object.'), 'error'); - } else { - drupal_set_message(t($e->getMessage()), 'error'); + try { + $soapHelper = new ConnectionHelper(); + $client = $soapHelper->getSoapClient(variable_get('fedora_soap_manage_url', 'http://localhost:8080/fedora/services/management?wsdl')); + $object = $client->__soapCall('purgeObject', array($params)); + unset($form_state['storage']['confirm']); + } catch (exception $e) { + if (preg_match('/org\.fcrepo\.server\.security\.xacml\.pep\.AuthzDeniedException/', $e->getMessage())) { + drupal_set_message(t('Error: Insufficient permissions to purge object.'), 'error'); + } else { + drupal_set_message(t($e->getMessage()), 'error'); + } + return; + } + if (empty($collectionPid)) { + $collectionPid = $_SESSION['fedora_collection']; + } + if (!empty($form_state['values']['referrer'])) { + $form_state['redirect'] = substr($form_state['values']['referrer'], 1); + } + else { + $form_state['redirect'] = "fedora/repository/$collectionPid/"; } - return; - } - if (empty($collectionPid)) { - $collectionPid = $_SESSION['fedora_collection']; } - $form_state['redirect'] = "fedora/repository/$collectionPid/"; } function fedora_repository_purge_stream_form(&$form_state, $pid, $dsId) { diff --git a/plugins/pidfield/pidfield.module b/plugins/pidfield/pidfield.module index 53e176a2..d9c475fc 100644 --- a/plugins/pidfield/pidfield.module +++ b/plugins/pidfield/pidfield.module @@ -281,7 +281,7 @@ function theme_pidfield_formatter_default($element) { $item = new Fedora_Item($pid); return fedora_repository_get_items($pid); - //return $item->objectProfile->objLabel; + } return null; } From 71115175c00b0997248331cf79efda45949b2523 Mon Sep 17 00:00:00 2001 From: Alexander O'Neill Date: Wed, 15 Dec 2010 15:52:47 -0400 Subject: [PATCH 2/2] Fixed URL redirect. --- ObjectHelper.inc | 4 ++-- fedora_repository.module | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/ObjectHelper.inc b/ObjectHelper.inc index c22d39b9..be80f817 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -476,7 +476,7 @@ class ObjectHelper { if ($allow) { //$purgeObject = '' . t('Purge Object') . '' . t('Purge Object') . ''; - $purgeObject = drupal_get_form('fedora_repository_purge_object_form', $object_pid, check_plain(request_uri())); + $purgeObject = drupal_get_form('fedora_repository_purge_object_form', $object_pid, check_plain(substr(request_uri(), strlen(base_path())))); } } else { $purgeObject = ' '; @@ -708,7 +708,7 @@ class ObjectHelper { // $ingestObject = ' $collectionName, '!collection_pid' => $collection_pid)) . '" href="' . base_path() . 'fedora/ingestObject/' . $collection_pid . '/' . $collectionName . '">' . t('Add a New Object') . '' . t('Add to this Collection') . ''; + '/images/ingest.png" alt="' . t('Add a New Object') . '" class="icon">' . t(' Add to this Collection'); } } } diff --git a/fedora_repository.module b/fedora_repository.module index c4012e69..c7cc9e41 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -254,7 +254,8 @@ function fedora_repository_purge_object_form(&$form_state, $pid, $referrer) { $form['submit'] = array( '#type' => 'image_button', '#src' => drupal_get_path('module', 'fedora_repository').'/images/purge_big.png', - '#value' => t('Purge') + '#value' => t('Purge'), + '#suffix' => 'Purge this object', ); if ($collectionPid == NULL) { $collectionPid = $_SESSION['fedora_collection']; @@ -266,7 +267,7 @@ function fedora_repository_purge_object_form(&$form_state, $pid, $referrer) { else { // ALSO do $form definition here. Your final submit handler (after user clicks Yes, I Confirm) will only see $form_state info defined here. Form you create here passed as param1 to confirm_form - return confirm_form($form,'You Sure?', $base_url.$referrer, 'Description text','Yes, nuke it','Cancel'); //Had better luck leaving off last param 'name' + return confirm_form($form, 'Confirm Purge Object', $referrer, 'Are you sure you want to delete this object? This action cannot be undone.', 'Delete', 'Cancel'); //Had better luck leaving off last param 'name' } return $form; } @@ -433,7 +434,7 @@ function fedora_repository_purge_object_form_submit($form, &$form_state) { $collectionPid = $_SESSION['fedora_collection']; } if (!empty($form_state['values']['referrer'])) { - $form_state['redirect'] = substr($form_state['values']['referrer'], 1); + $form_state['redirect'] = $form_state['values']['referrer']; } else { $form_state['redirect'] = "fedora/repository/$collectionPid/";