Browse Source

Merge pull request #350 from nigelgbanks/7.x-admin-menu

Admin settings form will now display even if the Repository is not acces...
pull/366/head
Jordan Dukart 12 years ago
parent
commit
cb2990fca1
  1. 179
      includes/admin.form.inc

179
includes/admin.form.inc

@ -19,77 +19,25 @@
function islandora_repository_admin(array $form, array &$form_state) { function islandora_repository_admin(array $form, array &$form_state) {
module_load_include('inc', 'islandora', 'includes/utilities'); module_load_include('inc', 'islandora', 'includes/utilities');
drupal_add_css(drupal_get_path('module', 'islandora') . '/css/islandora.admin.css'); drupal_add_css(drupal_get_path('module', 'islandora') . '/css/islandora.admin.css');
$url = islandora_system_settings_form_default_value('islandora_base_url', 'http://localhost:8080/fedora', $form_state);
$form = array(); $restrict_namespaces = islandora_system_settings_form_default_value('islandora_namespace_restriction_enforced', FALSE, $form_state);
if (isset($form_state['values']['islandora_base_url'])) { $confirmation_message = islandora_admin_settings_form_repository_access_message($url);
$url = $form_state['values']['islandora_base_url']; $form = array(
} 'islandora_tabs' => array(
else {
$url = variable_get('islandora_base_url', 'http://localhost:8080/fedora');
}
$connection = islandora_get_tuque_connection(NULL, $url);
if (!$connection) {
return;
}
try {
$info = $connection->api->a->describeRepository();
}
catch (RepositoryException $e) {
$info = FALSE;
}
if ($info) {
try {
$dc = $connection->api->m->getDatastream('fedora-system:ContentModel-3.0', 'DC');
}
catch (RepositoryException $e) {
$dc = FALSE;
}
}
if ($info) {
if ($dc) {
$confirmation_message = theme_image(array('path' => 'misc/watchdog-ok.png', 'attributes' => array()));
$confirmation_message .= t('Successfully connected to Fedora Server (Version !version).', array(
'!version' => $info['repositoryVersion']));
}
else {
$confirmation_message = theme_image(array('path' => 'misc/watchdog-warning.png', 'attributes' => array()));
$confirmation_message .= t('Unable to authenticate when connecting to to Fedora Server (Version !version). Please configure the !filter.',
array('!version' => $info['repositoryVersion'], '!filter' => 'Drupal Filter'));
}
}
else {
$confirmation_message = theme_image(array('path' => 'misc/watchdog-error.png', 'attributes' => array()));
$confirmation_message .= t('Unable to connect to Fedora server at !islandora_url', array(
'!islandora_url' => $url));
}
$form['islandora_tabs'] = array(
'#type' => 'vertical_tabs', '#type' => 'vertical_tabs',
); 'islandora_general' => array(
$form['islandora_tabs']['islandora_general'] = array(
'#type' => 'fieldset', '#type' => 'fieldset',
'#title' => t('General Configuarion'), '#title' => t('General Configuarion'),
); 'wrapper' => array(
// Ajax wrapper for url checking.
$form['islandora_tabs']['islandora_general']['wrapper'] = array(
'#prefix' => '<div id="islandora-url">', '#prefix' => '<div id="islandora-url">',
'#suffix' => '</div>', '#suffix' => '</div>',
'#type' => 'markup', '#type' => 'markup',
); 'islandora_base_url' => array(
$form['islandora_tabs']['islandora_general']['wrapper']['islandora_base_url'] = array(
'#type' => 'textfield', '#type' => 'textfield',
'#title' => t('Fedora base URL'), '#title' => t('Fedora base URL'),
'#default_value' => variable_get('islandora_base_url', 'http://localhost:8080/fedora'), '#default_value' => variable_get('islandora_base_url', 'http://localhost:8080/fedora'),
'#description' => t('The URL to use for REST connections <br /> !confirmation_message', array( '#description' => t('The URL to use for REST connections <br/> !confirmation_message', array(
'!confirmation_message' => $confirmation_message, '!confirmation_message' => $confirmation_message)),
)),
'#required' => TRUE, '#required' => TRUE,
'#ajax' => array( '#ajax' => array(
'callback' => 'islandora_update_url_div', 'callback' => 'islandora_update_url_div',
@ -98,75 +46,84 @@ function islandora_repository_admin(array $form, array &$form_state) {
'event' => 'blur', 'event' => 'blur',
'progress' => array('type' => 'throbber'), 'progress' => array('type' => 'throbber'),
), ),
); ),
),
$form['islandora_tabs']['islandora_general']['islandora_repository_pid'] = array( 'islandora_repository_pid' => array(
'#type' => 'textfield', '#type' => 'textfield',
'#title' => t('Root Collection PID'), '#title' => t('Root Collection PID'),
'#default_value' => variable_get('islandora_repository_pid', 'islandora:root'), '#default_value' => variable_get('islandora_repository_pid', 'islandora:root'),
'#description' => t('The PID of the Root Collection Object'), '#description' => t('The PID of the Root Collection Object'),
'#required' => TRUE, '#required' => TRUE,
); ),
),
$form['islandora_tabs']['islandora_namespace'] = array( 'islandora_namespace' => array(
'#type' => 'fieldset', '#type' => 'fieldset',
'#title' => t('Namespaces'), '#title' => t('Namespaces'),
); 'islandora_namespace_restriction_enforced' => array(
$form['islandora_tabs']['islandora_namespace']['wrapper'] = array(
'#type' => 'markup',
'#prefix' => '<div id="islandora-namespace">',
'#suffix' => '</div>',
);
$form['islandora_tabs']['islandora_namespace']['wrapper']['islandora_namespace_restriction_enforced'] = array(
'#weight' => -1,
'#type' => 'checkbox', '#type' => 'checkbox',
'#title' => t('Enforce namespace restrictions'), '#title' => t('Enforce namespace restrictions'),
'#description' => t("Allow administrator to restrict user's access to the PID namepaces listed below"), '#description' => t("Allow administrator to restrict user's access to the PID namepaces listed below"),
'#default_value' => variable_get('islandora_namespace_restriction_enforced', FALSE), '#default_value' => $restrict_namespaces,
'#ajax' => array(
'callback' => 'islandora_update_namespace_div',
'wrapper' => 'islandora-namespace',
'effect' => 'fade',
'event' => 'change',
'progress' => array('type' => 'throbber'),
), ),
); 'islandora_pids_allowed' => array(
if (isset($form_state['values']['islandora_namespace_restriction_enforced'])) {
$namespaces = $form_state['values']['islandora_namespace_restriction_enforced'];
}
else {
$namespaces = variable_get('islandora_namespace_restriction_enforced', FALSE);
}
if ($namespaces) {
$form['islandora_tabs']['islandora_namespace']['wrapper']['islandora_pids_allowed'] = array(
'#type' => 'textfield', '#type' => 'textfield',
'#title' => t('PID namespaces allowed in this Drupal install'), '#title' => t('PID namespaces allowed in this Drupal install'),
'#default_value' => variable_get('islandora_pids_allowed', 'default: demo: changeme: ilives: islandora-book: books: newspapers: '),
'#description' => t('A list of PID namespaces, separated by spaces, that users are permitted to access from this Drupal installation. <br /> This could be more than a simple namespace, e.g. <b>demo:mydemos</b>. <br /> The namespace <b>islandora:</b> is reserved, and is always allowed.'), '#description' => t('A list of PID namespaces, separated by spaces, that users are permitted to access from this Drupal installation. <br /> This could be more than a simple namespace, e.g. <b>demo:mydemos</b>. <br /> The namespace <b>islandora:</b> is reserved, and is always allowed.'),
'#weight' => 0, '#default_value' => variable_get('islandora_pids_allowed', 'default: demo: changeme: ilives: islandora-book: books: newspapers: '),
'#states' => array(
'invisible' => array(
':input[name="islandora_namespace_restriction_enforced"]' => array('checked' => FALSE),
),
),
),
),
),
); );
}
return system_settings_form($form); return system_settings_form($form);
} }
/** /**
* Get the element to render for the AJAX event that triggered this callback. * Gets a message which describes if the repository is accessible.
* *
* @param array $form * Also describes if the user is considered an authenticated user by the
* The Drupal form definition. * repository.
* @param array $form_state
* The Drupal form state.
* *
* @return array * @param string $url
* The form element to render. * The url to the Fedora Repository.
*
* @return string
* A message describing the accessibility of the repository at the given url.
*/ */
function islandora_update_url_div(array $form, array $form_state) { function islandora_admin_settings_form_repository_access_message($url) {
return $form['islandora_tabs']['islandora_general']['wrapper']; $info = $dc = FALSE;
$connection = islandora_get_tuque_connection(NULL, $url);
if ($connection) {
try {
$info = $connection->api->a->describeRepository();
// If we are able to successfully call API-M::getDatastream, assume we are
// an authenticated user, as API-M is usally locked down.
$dc = $connection->api->m->getDatastream('fedora-system:ContentModel-3.0', 'DC');
}
catch (RepositoryException $e) {
// Ignore, we only testing to see what is accessible.
}
}
if ($info && $dc) {
$confirmation_message = theme_image(array('path' => 'misc/watchdog-ok.png', 'attributes' => array()));
$confirmation_message .= t('Successfully connected to Fedora Server (Version !version).', array(
'!version' => $info['repositoryVersion']));
}
elseif ($info) {
$confirmation_message = theme_image(array('path' => 'misc/watchdog-warning.png', 'attributes' => array()));
$confirmation_message .= t('Unable to authenticate when connecting to to Fedora Server (Version !version). Please configure the !filter.', array(
'!version' => $info['repositoryVersion'], '!filter' => 'Drupal Filter'));
}
else {
$confirmation_message = theme_image(array('path' => 'misc/watchdog-error.png', 'attributes' => array()));
$confirmation_message .= t('Unable to connect to Fedora server at !islandora_url', array(
'!islandora_url' => $url));
}
return $confirmation_message;
} }
/** /**
@ -180,6 +137,6 @@ function islandora_update_url_div(array $form, array $form_state) {
* @return array * @return array
* The form element to render. * The form element to render.
*/ */
function islandora_update_namespace_div(array $form, array $form_state) { function islandora_update_url_div(array $form, array $form_state) {
return $form['islandora_tabs']['islandora_namespace']['wrapper']; return $form['islandora_tabs']['islandora_general']['wrapper'];
} }

Loading…
Cancel
Save