The libraries interlibrary loan form module
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

177 lines
6.2 KiB

<?php
namespace Drupal\upei_roblib_ill\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
/**
* Settings form for module
*
* @author ppound
*/
class RoblibIllSettingsForm extends FormBase
{
/**
* {@inheritdoc}
*/
public function getFormId()
{
return 'roblib_ill_settings_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state)
{
$config = \Drupal::config('upei_roblib_ill.settings');
$form = [];
$form['ill_library_symbol'] = [
'#required' => TRUE,
'#type' => 'textfield',
'#size' => 200,
'#title' => t('Your ILL Library Symbol'),
'#description' => t('Your Relais Library Symbol'),
'#default_value' => $config->get('ill_library_symbol'),
];
$form['ill_doi_openurl_pid'] = [
'#required' => TRUE,
'#type' => 'textfield',
'#size' => 200,
'#title' => t('OpenURL PID'),
'#description' => t('An identifier to call yourself, for the OpenURL endpoint. To use this service you first need to register for an account here: http://www.crossref.org/requestaccount/'),
'#default_value' => $config->get('ill_doi_openurl_pid'),
];
$form['ill_contact_email'] = [
'#required' => TRUE,
'#type' => 'textfield',
'#size' => 200,
'#title' => t('Contact Email'),
'#description' => t('The email address we want to show after a user has submitted an ILL request, Roblib uses ill@upei.ca'),
'#default_value' => $config->get('ill_contact_email'),
];
$form['ill_contact_phone'] = [
'#required' => TRUE,
'#type' => 'textfield',
'#size' => 200,
'#title' => t('Contact Phone Number'),
'#description' => t('The phone number we want to show to the user after a user has submitted an ILL request, Roblib uses 902-566-0445'),
'#default_value' => $config->get('ill_contact_phone'),
];
// Evergreen Settings
$form['evergreen_fieldset'] = [
'#type' => 'fieldset',
'#title' => t('Evergreen ILS Settings'),
'#description' => t('Configuration for authenticating users against Evergreen.'),
];
$form['evergreen_fieldset']['evergreen_api_url'] = [
'#type' => 'url',
'#title' => t('Evergreen API URL'),
'#description' => t('The base URL of your Evergreen server (e.g. https://catalogue.example.com). Used for REST API patron lookups.'),
'#default_value' => $config->get('evergreen_api_url'),
'#size' => 200,
'#required' => TRUE,
];
$form['evergreen_fieldset']['evergreen_username'] = [
'#type' => 'textfield',
'#title' => t('Evergreen Staff Username'),
'#description' => t('A staff username for authenticating with the Evergreen REST API.'),
'#default_value' => $config->get('evergreen_username'),
'#size' => 200,
'#required' => TRUE,
];
$form['evergreen_fieldset']['evergreen_password'] = [
'#type' => 'password',
'#title' => t('Evergreen Staff Password'),
'#description' => t('The staff password for the Evergreen REST API. Leave blank to keep the existing value.'),
'#size' => 200,
];
// RapidILL settings.
$form['rapid_ill_fieldset'] = [
'#type' => 'fieldset',
'#title' => t('RapidILL Settings'),
'#description' => t('Credentials and configuration for submitting requests via RapidILL.'),
];
$form['rapid_ill_fieldset']['rapid_ill_username'] = [
'#type' => 'textfield',
'#title' => t('RapidILL Username'),
'#description' => t('Your RapidILL API username.'),
'#default_value' => $config->get('rapid_ill_username'),
'#size' => 200,
];
$form['rapid_ill_fieldset']['rapid_ill_password'] = [
'#type' => 'password',
'#title' => t('RapidILL Password'),
'#description' => t('Your RapidILL API password. Leave blank to keep the existing value.'),
'#size' => 200,
];
$form['rapid_ill_fieldset']['rapid_ill_code'] = [
'#type' => 'textfield',
'#title' => t('RapidILL Rapid Code'),
'#description' => t('Your library Rapid code (e.g. YOUR_RAPID_CODE).'),
'#default_value' => $config->get('rapid_ill_code'),
'#size' => 200,
];
$form['rapid_ill_fieldset']['rapid_ill_branch_name'] = [
'#type' => 'textfield',
'#title' => t('RapidILL Branch Name'),
'#description' => t('Your library branch name (e.g. Main).'),
'#default_value' => $config->get('rapid_ill_branch_name'),
'#size' => 200,
];
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => t('Save'),
'#button_type' => 'primary',
];
return $form;
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state)
{
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state)
{
$config = \Drupal::configFactory()->getEditable('upei_roblib_ill.settings');
$config->set('ill_library_symbol', $form_state->getValue('ill_library_symbol'))->save();
$config->set('ill_doi_openurl_pid', $form_state->getValue('ill_doi_openurl_pid'))->save();
$config->set('ill_contact_email', $form_state->getValue('ill_contact_email'))->save();
$config->set('ill_contact_phone', $form_state->getValue('ill_contact_phone'))->save();
// Evergreen settings.
$config->set('evergreen_api_url', rtrim($form_state->getValue('evergreen_api_url'), '/'))->save();
$config->set('evergreen_username', $form_state->getValue('evergreen_username'))->save();
$eg_password = $form_state->getValue('evergreen_password');
if (!empty($eg_password)) {
$config->set('evergreen_password', $eg_password)->save();
}
// RapidILL settings.
$config->set('rapid_ill_username', $form_state->getValue('rapid_ill_username'))->save();
// Only update the password if a new value was entered.
$password = $form_state->getValue('rapid_ill_password');
if (!empty($password)) {
$config->set('rapid_ill_password', $password)->save();
}
$config->set('rapid_ill_code', $form_state->getValue('rapid_ill_code'))->save();
$config->set('rapid_ill_branch_name', $form_state->getValue('rapid_ill_branch_name'))->save();
}
}