Browse Source

Merge pull request #239 from ajstanley/6.x

added ajax callback to admin page, guaranteed collection object
pull/240/merge
ajstanley 12 years ago
parent
commit
d36f48a6cc
  1. 2
      fedora_repository.api.php
  2. 119
      fedora_repository.module
  3. 105
      formClass.inc

2
fedora_repository.api.php

@ -26,7 +26,7 @@ function hook_islandora_tabs($content_models, $pid, $page_number) {
$tabset['A TAB'] = array( $tabset['A TAB'] = array(
'#type' => 'tabpage', '#type' => 'tabpage',
'#title' => t('A TITLE'), '#title' => t('A TITLE'),
'#content' => 'content') '#content' => 'content'
); );
return $tabset; return $tabset;

119
fedora_repository.module

@ -1,4 +1,5 @@
<?php <?php
/** /**
* @file * @file
* This file is the Drupal module file for fedora_repository. * This file is the Drupal module file for fedora_repository.
@ -10,10 +11,10 @@
* Stores this info in the drupal variables table. * Stores this info in the drupal variables table.
* the name and pid can also be passed as url parameters * the name and pid can also be passed as url parameters
*/ */
function fedora_repository_admin() { function fedora_repository_admin(&$form_state) {
module_load_include('inc', 'fedora_repository', 'formClass'); module_load_include('inc', 'fedora_repository', 'formClass');
$admin_form = new formClass(); $admin_form = new formClass();
return $admin_form->createAdminForm(); return $admin_form->createAdminForm(&$form_state);
} }
/** /**
@ -325,7 +326,7 @@ function fedora_repository_purge_object_form(&$form_state, $pid, $referrer = NUL
/* ALSO do $form definition here. Your final submit handler /* ALSO do $form definition here. Your final submit handler
* (after user clicks Yes, I Confirm) * (after user clicks Yes, I Confirm)
* will only see $form_state info defined here. * will only see $form_state info defined here.
* Form you create here passed as param1 to confirm_form*/ * Form you create here passed as param1 to confirm_form */
// Had better luck leaving off last param 'name'. // 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'); return confirm_form($form, 'Confirm Purge Object', $referrer, 'Are you sure you want to delete this object? This action cannot be undone.', 'Delete', 'Cancel');
@ -531,7 +532,7 @@ function fedora_repository_purge_object_form_validate($form, &$form_state) {
foreach ($content_models as $content_model) { foreach ($content_models as $content_model) {
if ($content_model->pid == 'islandora:collectionCModel') { if ($content_model->pid == 'islandora:collectionCModel') {
$member_pids = get_related_items_as_array($pid, 'isMemberOfCollection', 10000, 0, FALSE); $member_pids = get_related_items_as_array($pid, 'isMemberOfCollection', 10000, 0, FALSE);
if (is_array($member_pids) && ! empty($member_pids)) { if (is_array($member_pids) && !empty($member_pids)) {
form_set_error('new_collection_pid', t("Please purge all members of this collection before deleting the collection itself.")); form_set_error('new_collection_pid', t("Please purge all members of this collection before deleting the collection itself."));
return; return;
} }
@ -556,14 +557,14 @@ function fedora_repository_purge_object_form_submit($form, &$form_state) {
if (!isset($form_state['storage']['confirm'])) { if (!isset($form_state['storage']['confirm'])) {
/* This will cause the form to be rebuilt, /* This will cause the form to be rebuilt,
* entering the confirm part of the form.*/ * entering the confirm part of the form. */
$form_state['storage']['confirm'] = TRUE; $form_state['storage']['confirm'] = TRUE;
// Along with this. // Along with this.
$form_state['rebuild'] = TRUE; $form_state['rebuild'] = TRUE;
} }
else { else {
/* This is where you do your processing after /* This is where you do your processing after
* they have pressed the confirm button.*/ * they have pressed the confirm button. */
$params = array( $params = array(
"pid" => $pid, "pid" => $pid,
"logMessage" => "Purged", "logMessage" => "Purged",
@ -771,14 +772,14 @@ function fedora_repository_replace_stream_form_submit($form, &$form_state) {
$dsLabel = $form_state['values']['dsLabel']; $dsLabel = $form_state['values']['dsLabel'];
$streamUrl = ($file !== NULL) ? $streamUrl = ($file !== NULL) ?
file_create_url($file->filepath): file_create_url($file->filepath) :
url($form_state['values']['reference'], array('absolute' => TRUE)); url($form_state['values']['reference'], array('absolute' => TRUE));
// Remove the original file extension from the label and add the new one // Remove the original file extension from the label and add the new one
// use strrpos to get the last dot // use strrpos to get the last dot
if (($indexOfDot = strrpos($dsLabel, '.')) !== FALSE) { if (($indexOfDot = strrpos($dsLabel, '.')) !== FALSE) {
$dsLabel = substr($dsLabel, 0, $indexOfDot) . $dsLabel = substr($dsLabel, 0, $indexOfDot) .
substr($streamUrl, strrpos($streamUrl, '.')); // Add the file extention to the end of the label. substr($streamUrl, strrpos($streamUrl, '.')); // Add the file extention to the end of the label.
} }
$dformat = $form_state['storage']['mime_type']; $dformat = $form_state['storage']['mime_type'];
@ -901,7 +902,7 @@ function fedora_repository_edit_qdc_form_submit($form, &$form_state) {
$client = $soap_helper->getSoapClient(variable_get('fedora_soap_manage_url', 'http://localhost:8080/fedora/wsdl?api=API-M')); $client = $soap_helper->getSoapClient(variable_get('fedora_soap_manage_url', 'http://localhost:8080/fedora/wsdl?api=API-M'));
/* Check the content model for a custom /* Check the content model for a custom
* edit metadata form submit function.*/ * edit metadata form submit function. */
if (isset($form_state['values']['pid'])) { if (isset($form_state['values']['pid'])) {
module_load_include('inc', 'fedora_repository', 'ContentModel'); module_load_include('inc', 'fedora_repository', 'ContentModel');
if (($cm = ContentModel::loadFromObject($form_state['values']['pid'])) !== FALSE) { if (($cm = ContentModel::loadFromObject($form_state['values']['pid'])) !== FALSE) {
@ -1003,9 +1004,9 @@ function fedora_repository_islandora_tabs($content_models, $pid, $page_number) {
} }
else { else {
$cmodels_tabs[$content_model->pid] = array( $cmodels_tabs[$content_model->pid] = array(
'#type' => 'tabpage', '#type' => 'tabpage',
'#title' => $content_model->name, '#title' => $content_model->name,
'#content' => $content_model_fieldset, '#content' => $content_model_fieldset,
); );
} }
} }
@ -1621,10 +1622,10 @@ function fedora_repository_imagecache_default_presets() {
function _fedora_repository_render_image($tn_path, $imagecache_preset = 'fedora_repository_collection_thumbnail', $truncated_title = '', $title = '') { function _fedora_repository_render_image($tn_path, $imagecache_preset = 'fedora_repository_collection_thumbnail', $truncated_title = '', $title = '') {
$thumbnail = NULL; $thumbnail = NULL;
if ($thumbnail === NULL && if ($thumbnail === NULL &&
module_exists('imagecache_external') && module_exists('imagecache_external') &&
is_callable('theme_imagecache_external_image') && is_callable('theme_imagecache_external_image') &&
variable_get('fedora_repository_use_imagecache_external_in_collection_view', FALSE) && variable_get('fedora_repository_use_imagecache_external_in_collection_view', FALSE) &&
imagecache_external_can_fetch($tn_path, TRUE)) { imagecache_external_can_fetch($tn_path, TRUE)) {
$thumbnail = theme('imagecache_external_image', $imagecache_preset, $tn_path, $truncated_title, $title); $thumbnail = theme('imagecache_external_image', $imagecache_preset, $tn_path, $truncated_title, $title);
} }
if ($thumbnail === NULL) { if ($thumbnail === NULL) {
@ -1755,3 +1756,87 @@ function fedora_repository_fedora_repository_check_perm($op, $pid, $user) {
return NULL; return NULL;
} }
} }
function update_fedora_url_div() {
$form = islandora_callback_prep();
$changed_elements = $form['fedora_ahah_wrapper'];
unset($changed_elements['#prefix'], $changed_elements['#suffix']);
$output = theme('status_messages') . drupal_render($changed_elements);
drupal_json(array(
'status' => TRUE,
'data' => $output,
));
}
function islandora_callback_prep() {
$form_state = array('storage' => NULL, 'submitted' => FALSE, 'rebuild' => TRUE);
$form_build_id = $_POST['form_build_id'];
$form = form_get_cache($form_build_id, $form_state);
$args = $form['#parameters'];
$form_id = array_shift($args);
$form_state['post'] = $form['#post'] = $_POST;
// Enable the submit/validate handlers to determine whether AHAH-submittted.
$form_state['ahah_submission'] = TRUE;
$form['#programmed'] = $form['#redirect'] = FALSE;
drupal_process_form($form_id, $form, $form_state);
$form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id);
return $form;
}
function islandora_fedora_settings_form_submit($form, &$form_state) {
$op = isset($form_state['values']['op']) ? $form_state['values']['op'] : '';
if ($form_state['ahah_submission'] == TRUE) {
$form_state['rebuild'] = TRUE;
return;
}
if ($form_state['clicked_button']['#id'] != 'edit-submit' && $op != t('Reset to defaults')) {
$form_state['rebuild'] = TRUE;
return;
}
// Exclude unnecessary elements.
unset($form_state['values']['submit'], $form_state['values']['reset'], $form_state['values']['form_id'], $form_state['values']['op'], $form_state['values']['form_token'], $form_state['values']['form_build_id']);
foreach ($form_state['values'] as $key => $value) {
if ($op == t('Reset to defaults')) {
variable_del($key);
}
else {
if (is_array($value) && isset($form_state['values']['array_filter'])) {
$value = array_keys(array_filter($value));
}
variable_set($key, $value);
}
}
//set elements previously defined in config code.
//the elements are left in to allow for third party modules.
if ($op != t('Reset to defaults')) {
$fedora_base = variable_get('fedora_base_url', 'http://localhost:8080/fedora');
variable_set('fedora_soap_url', $fedora_base . '/wsdl?api=API-A');
variable_set('fedora_soap_manage_url', $fedora_base . '/wsdl?api=API-M');
}
if ($op == t('Reset to defaults')) {
drupal_set_message(t('The configuration options have been reset to their default values.'));
}
else {
drupal_set_message(t('The Islandora configuration options have been saved.'));
}
$root = variable_get('fedora_repository_pid', 'islandora:root');
islandora_guarantee_root_collection($root);
cache_clear_all();
drupal_rebuild_theme_registry();
}
function islandora_guarantee_root_collection($pid){
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
$item = new Fedora_Item($pid);
if($item->exists()){
return;
}
$item = Fedora_item::ingest_new_item($pid, 'A', 'Islandora Root Collection', 'admin');
$item->add_relationship('hasModel', 'islandora:collectionCModel', FEDORA_MODEL_URI);
}

105
formClass.inc

@ -158,6 +158,13 @@ class formClass {
'access arguments' => array('administer site configuration'), 'access arguments' => array('administer site configuration'),
); );
$items['islandora/fedora/url'] = array(
'page callback' => 'update_fedora_url_div',
'access arguments' => array('view fedora collection'),
'file' => 'fedora_repository.module',
'type' => MENU_CALLBACK,
);
return $items; return $items;
} }
@ -165,14 +172,25 @@ class formClass {
* Create admin form * Create admin form
* @return array * @return array
*/ */
function createAdminForm() { function createAdminForm(&$form_state) {
if (!user_access('administer site configuration')) { if (!user_access('administer site configuration')) {
drupal_set_message(t('You must be a site administrator to edit the Fedora collections list.'), 'error'); drupal_set_message(t('You must be a site administrator to edit the Fedora collections list.'), 'error');
return; return;
} }
module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); module_load_include('inc', 'fedora_repository', 'api/fedora_utils');
module_load_include('inc', 'fedora_repository', 'ObjectHelper'); module_load_include('inc', 'fedora_repository', 'ObjectHelper');
$fedora_path = isset($form_state['values']['fedora_base_url']) ? $form_state['values']['fedora_base_url'] : variable_get('fedora_base_url', 'http://localhost:8080/fedora');
$triplepath = "$fedora_path/risearch";
$response = do_curl_ext($fedora_path . '/describe');
$available = ($response != NULL) ? ($response[1] == 0) : FALSE;
$confirmation_message = ($available ? '<img src="' . url('misc/watchdog-ok.png') . '"/>'
. t('Successfully connected to Fedora server at @fedora_soap_url', array('@fedora_soap_url' => $fedora_path)) : '<img src="'
. url('misc/watchdog-error.png') . '"/> '
. t('Unable to connect to Fedora server at @fedora_soap_url', array('@fedora_soap_url' => $fedora_path)));
$form = array(); $form = array();
$form['fedora_repository_pid'] = array( $form['fedora_repository_pid'] = array(
'#type' => 'textfield', '#type' => 'textfield',
'#title' => t('Root Collection PID'), '#title' => t('Root Collection PID'),
@ -182,45 +200,41 @@ class formClass {
'#weight' => -18 '#weight' => -18
); );
$form['fedora_base_url'] = array(
'#type' => 'textfield',
'#title' => t('Fedora base URL'),
'#default_value' => variable_get('fedora_base_url', 'http://localhost:8080/fedora'),
'#description' => t('The URL to use for REST-type connections'),
'#required' => TRUE,
'#weight' => -16,
);
$form['fedora_repository_url'] = array( // new ahah stuff
'#type' => 'textfield',
'#title' => t('Fedora RISearch URL'), $form['fedora_ahah_wrapper'] = array(
'#default_value' => variable_get('fedora_repository_url', 'http://localhost:8080/fedora/risearch'), '#prefix' => '<div id="islandora-fedora-url">',
'#description' => t('The url of the Fedora server'), '#required' => TRUE, '#suffix' => '</div>',
'#weight' => -14 '#type' => 'markup',
); );
$form['fedora_soap_url'] = array( $form['fedora_ahah_wrapper']['fedora_base_url'] = array(
'#type' => 'textfield', '#type' => 'textfield',
'#title' => t('Fedora SOAP Url'), '#title' => t('Fedora base URL'),
'#default_value' => variable_get('fedora_soap_url', 'http://localhost:8080/fedora/wsdl?api=API-A'), '#default_value' => $fedora_path,
'#description' => t('The URL to use for SOAP connections'), '#description' => t('The URL to use for REST-type connections'),
'#required' => TRUE, '#ahah' => array(
'#weight' => -12, 'path' => 'islandora/fedora/url',
'#suffix' => '<p>' . ( 'wrapper' => 'islandora-fedora-url',
fedora_available() ? 'effect' => 'fade',
theme('image', 'misc/watchdog-ok.png') . t('Successfully connected to Fedora server at @fedora_soap_url', array('@fedora_soap_url' => variable_get('fedora_soap_url', ''))) : 'event' => 'change'),
theme('image', 'misc/watchdog-error.png') . t('Unable to connect to Fedora server at @fedora_soap_url', array('@fedora_soap_url' => variable_get('fedora_soap_url', '')))) . '</p>',
); );
$form['fedora_ahah_wrapper']['infobox'] = array(
$form['fedora_soap_manage_url'] = array( '#type' => 'item',
'#value' => $confirmation_message,
);
$form['fedora_ahah_wrapper']['fedora_repository_url'] = array(
'#type' => 'textfield', '#type' => 'textfield',
'#title' => t('Fedora SOAP management URL'), '#title' => t('Fedora RISearch URL'),
'#default_value' => variable_get('fedora_soap_manage_url', 'http://localhost:8080/fedora/wsdl?api=API-M'), '#description' => t('The URL to use for SOAP API-M connections'), '#default_value' => $triplepath,
'#description' => t('The url of the Fedora server\'s Triplestore. Change this only if you have set up an external triplestore'),
'#required' => TRUE, '#required' => TRUE,
'#weight' => -10
); );
// will allow admin user to remove namepsace restrictions if not explicitly disallowed in settings.php // will allow admin user to remove namepsace restrictions if not explicitly disallowed in settings.php
if (variable_get('allow_open_namespace', TRUE)) { if (variable_get('allow_open_namespace', TRUE)) {
$form['fedora_namespace'] = array( $form['fedora_namespace'] = array(
@ -288,7 +302,7 @@ class formClass {
if (array_key_exists('config', $profile)) { if (array_key_exists('config', $profile)) {
$config_path = $profile['config']; $config_path = $profile['config'];
if (isset($config_path) && $config_path != "") { if (isset($config_path) && $config_path != "") {
$display_options[$machine_name] .= " (". l("config", $config_path, array()) .")"; $display_options[$machine_name] .= " (" . l("config", $config_path, array()) . ")";
} }
} }
} }
@ -322,14 +336,14 @@ class formClass {
'#title' => t('Allow imagecache_external use for thumbnails in collection view'), '#title' => t('Allow imagecache_external use for thumbnails in collection view'),
'#default_value' => variable_get('fedora_repository_use_imagecache_external_in_collection_view', FALSE), '#default_value' => variable_get('fedora_repository_use_imagecache_external_in_collection_view', FALSE),
'#description' => t('If enabled, the default collection list view (or ' . '#description' => t('If enabled, the default collection list view (or ' .
'anywhere the function "@function" is used) will try to use ' . 'anywhere the function "@function" is used) will try to use ' .
'imagecache_external, defaulting to the "@preset" preset. XSLTs may ' . 'imagecache_external, defaulting to the "@preset" preset. XSLTs may ' .
'be updated to use this function.', 'be updated to use this function.',
array( array(
'@function' => '_fedora_repository_render_image()', '@function' => '_fedora_repository_render_image()',
'@preset' => 'fedora_repository_collection_thumbnail', '@preset' => 'fedora_repository_collection_thumbnail',
'@xsl' => 'sparql_to_html.xsl', '@xsl' => 'sparql_to_html.xsl',
)), )),
); );
$form['advanced']['fedora_control_group_control_during_ingest'] = array( $form['advanced']['fedora_control_group_control_during_ingest'] = array(
@ -352,7 +366,7 @@ class formClass {
'#type' => 'textfield', '#type' => 'textfield',
'#title' => t('Path to FITS executable'), '#title' => t('Path to FITS executable'),
'#description' => t("Path to FITS program on your server. It must be accessible by Drupal (i.e. apache user)."), '#description' => t("Path to FITS program on your server. It must be accessible by Drupal (i.e. apache user)."),
'#default_value' => variable_get('fits_path','/usr/local/bin/fits.sh'), '#default_value' => variable_get('fits_path', '/usr/local/bin/fits.sh'),
); );
//Export functionality //Export functionality
@ -365,9 +379,13 @@ class formClass {
); );
$form['#attributes'] = array('enctype' => "multipart/form-data"); $form['#attributes'] = array('enctype' => "multipart/form-data");
$form['buttons']['submit'] = array('#type' => 'submit', '#value' => t('Save Configuration'));
$form['buttons']['reset'] = array('#type' => 'submit', '#value' => t('Reset to defaults'));
$form['#submit'][] = 'islandora_fedora_settings_form_submit';
$form['#theme'] = 'system_settings_form';
return ($form);
// return system_settings_form($form);
return system_settings_form($form);
} }
/** /**
@ -422,8 +440,7 @@ class formClass {
} }
// Save the title // Save the title
if ( $label != null ) if ($label != null) {
{
$object = new Fedora_Item($form_values['pid']); $object = new Fedora_Item($form_values['pid']);
$object->modify_object($label); $object->modify_object($label);
} }

Loading…
Cancel
Save