Compare commits

..

10 Commits

  1. 92
      README.md
  2. 37
      config/schema/upei_roblib_ill.schema.yml
  3. 80
      includes/admin.form.inc
  4. 68
      includes/db.inc
  5. 4
      includes/doi.inc
  6. 260
      includes/rapidill.inc
  7. 167
      includes/relais.inc
  8. 189
      includes/utilities.inc
  9. 91
      src/Form/RoblibIllLoanForm.php
  10. 135
      src/Form/RoblibIllSettingsForm.php
  11. 13
      upei_roblib_ill.install
  12. 4
      upei_roblib_ill.module

92
README.md

@ -1,13 +1,95 @@
# Robertson Library ILL Forms module
# Robertson Library ILL Forms Module
## Introduction
Standalone module to submit ILL requests to Relais. Can read openurl parameters or lookup data based on a DOI
This Drupal module provides a front-end Interlibrary Loan (ILL) request form for
the UPEI Robertson Library. Patrons fill out a two-step form with bibliographic
information and authentication details, and the request is submitted to
**RapidILL** for processing.
**Branch guide:**
- `1.x` -- Relais integration (legacy)
- `3.x` -- RapidILL integration (current)
## How It Works
1. **Step 1 -- Bibliographic Information:** The patron selects a genre
(article, book, or chapter) and enters citation details. A DOI lookup button
can auto-populate fields from CrossRef.
2. **Step 2 -- Patron Authentication:** The patron provides their name, UPEI
ID, email, department, and patron type. The module verifies the patron
against the Evergreen ILS REST API by matching the provided surname to the
`family_name` on file.
3. **Submission:** On successful authentication the request is sent to RapidILL
and logged to the `upei_roblib_ill_request` database table.
4. **Confirmation:** The patron is redirected to a confirmation page with the
RapidILL request number.
OpenURL parameters and DOIs can be passed in via query string so the form can be
pre-populated from discovery tools such as EBSCO or Google Scholar.
## Requirements
* Drupal 7
- Drupal 9 or 10
- An Evergreen ILS instance with the `osrf-gateway-v1` REST API accessible
- A RapidILL account (username, password, Rapid code, and branch name)
- A CrossRef OpenURL PID (for DOI lookups)
## Installation
Install as you would any Drupal module. No additional dependencies are required.
## Configuration
Navigate to **Administration > Settings > Roblib ILL**
(`/admin/settings/roblibill`) and configure the following sections:
### General
| Setting | Description |
|----------------------|-------------------------------------------------------|
| ILL Library Symbol | Your Relais/RapidILL library symbol |
| OpenURL PID | Your CrossRef OpenURL PID for DOI resolution |
| Contact Email | Email shown on the confirmation page (e.g. ill@upei.ca) |
| Contact Phone | Phone number shown on the confirmation page |
### Evergreen ILS
| Setting | Description |
|--------------------------|--------------------------------------------------------------|
| Evergreen API URL | Base URL of your Evergreen server (e.g. `https://catalogue.example.com`) |
| Evergreen Staff Username | Staff account used for REST API authentication |
| Evergreen Staff Password | Password for the staff account |
The module authenticates against Evergreen by calling
`open-ils.auth.authenticate.init` / `open-ils.auth.authenticate.complete` to
obtain a session token, then retrieves the patron record with
`open-ils.actor.user.retrieve` and compares the `family_name` field to the
surname provided by the user.
### RapidILL
| Setting | Description |
|----------------------|-------------------------------------------|
| RapidILL Username | Your RapidILL API username |
| RapidILL Password | Your RapidILL API password |
| RapidILL Rapid Code | Your library's Rapid code |
| RapidILL Branch Name | Your library branch name (e.g. Main) |
## Routes
| Path | Description |
|---------------------------------|------------------------------|
| `/admin/settings/roblibill` | Module settings form |
| `/upei/roblib/ill/{parameters}` | ILL request form |
| `/upei/roblib/ill/finished` | Post-submission confirmation |
## Views Integration
The module exposes the `upei_roblib_ill_request` table to Drupal Views, so
administrators can build custom reports and lists of submitted ILL requests.
## Maintainers/Sponsors
## Maintainers / Sponsors
* UPEI Robertson Library
- UPEI Robertson Library

37
config/schema/upei_roblib_ill.schema.yml

@ -0,0 +1,37 @@
upei_roblib_ill.settings:
type: config_object
label: 'UPEI Roblib ILL settings'
mapping:
ill_library_symbol:
type: string
label: 'Your ILL Library Symbol'
ill_doi_openurl_pid:
type: string
label: 'OpenURL PID'
ill_contact_email:
type: string
label: 'Contact Email'
ill_contact_phone:
type: string
label: 'Contact Phone Number'
rapid_ill_username:
type: string
label: 'RapidILL Username'
rapid_ill_password:
type: string
label: 'RapidILL Password'
rapid_ill_code:
type: string
label: 'RapidILL Rapid Code'
rapid_ill_branch_name:
type: string
label: 'RapidILL Branch Name'
evergreen_api_url:
type: string
label: 'Evergreen API URL'
evergreen_username:
type: string
label: 'Evergreen Staff Username'
evergreen_password:
type: string
label: 'Evergreen Staff Password'

80
includes/admin.form.inc

@ -1,80 +0,0 @@
<?php
/**
* @file
* the administrative form for upei_roblib_ill
*/
function upei_roblib_ill_admin_form($form, &$form_state) {
$form = [];
$form['upei_roblib_ill_add_url'] = [
'#required' => TRUE,
'#type' => 'textfield',
'#size' => 200,
'#title' => t('The Relais AddRequest URL'),
'#description' => t('The URL for the Relais ILL server AddRequest service, the default is
https://caul-cbua.relais-host.com/portal-service/request/add'),
'#default_value' => variable_get('upei_roblib_ill_add_url', 'https://caul-cbua.relais-host.com/portal-service/request/add'),
];
$form['upei_roblib_ill_auth_url'] = [
'#required' => TRUE,
'#type' => 'textfield',
'#size' => 200,
'#title' => t('The Relais Auth URL'),
'#description' => t('The URL for the Relais ILL server Auth service (retrieve the aid), the default is
https://caul-cbua.relais-host.com/portal-service/user/authentication'),
'#default_value' => variable_get('upei_roblib_ill_auth_url', 'https://caul-cbua.relais-host.com/portal-service/user/authentication'),
];
$form['upei_roblib_ill_library_symbol'] = [
'#required' => TRUE,
'#type' => 'textfield',
'#size' => 200,
'#title' => t('Your Relais Library Symbol'),
'#description' => t('Your Relais Library Symbol'),
'#default_value' => variable_get('upei_roblib_ill_library_symbol'),
];
$form['upei_roblib_ill_relais_key'] = [
'#required' => TRUE,
'#type' => 'textfield',
'#size' => 200,
'#title' => t('The Relais API key'),
'#description' => t('The API key used to communicate with the Relais API, Contact Relais International to get your key'),
'#default_value' => variable_get('upei_roblib_ill_relais_key'),
];
$form['upei_roblib_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' => variable_get('upei_roblib_ill_doi_openurl_pid'),
];
$form['upei_roblib_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'),
'#default_value' => variable_get('upei_roblib_ill_contact_email', 'ill@upei.ca'),
];
$form['upei_roblib_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'),
'#default_value' => variable_get('upei_roblib_ill_contact_phone', '902-566-0445'),
];
$form['upei_roblib_ill_header_message'] = [
'#required' => TRUE,
'#type' => 'textarea',
'#title' => t('ILL Header Message'),
'#description' => t('The message that appears at the top of the ILL form, recently used for Covid messages. Leave this blank for no message to appear at the top of the form.'),
'#default_value' => variable_get('upei_roblib_ill_header_message', ''),
];
return system_settings_form($form);
}

68
includes/db.inc

@ -5,42 +5,54 @@
*/
use RapidIll\InsertRequest;
/**
* Log an ILL request
*
* @param array $request
* The request sent to Relais as an array (before it is encoded as JSON)
* @param array $response
* The response from Relais.
* @param \RapidIll\InsertRequest $request
* The request sent to RapidILL as an InsertRequest object.
* @param array|string $response
* The response from RapidILL or an error message.
*/
function upei_roblib_ill_log_request($request, $response) {
$time_submitted = isset($request['RequestInfo']['DateSubmitted']) ? $request['RequestInfo']['DateSubmitted'] : '';
$relais_message = isset($response['ConfirmMessage']) ? $response['ConfirmMessage'] : $response['Problem']['Message'];
function upei_roblib_ill_log_request(InsertRequest $request, $response) {
$soap_data = $request->toSoapArray();
$time_submitted = time();
$relais_message = is_array($response) ? (isset($response['ConfirmMessage']) ? $response['ConfirmMessage'] : ($response['Problem']['Message'] ?? '')) : (string) $response;
$patron_firstname = '';
$patron_lastname = '';
if (!empty($soap_data['PatronName'])) {
$parts = explode(' ', $soap_data['PatronName'], 2);
$patron_firstname = trim($parts[0] ?? '');
$patron_lastname = trim($parts[1] ?? '');
}
$connection = \Drupal::service('database');
try {
$connection->insert('upei_roblib_ill_request')
->fields([
'patron_id' => $request['DeliveryAddress']['campus_id'],
'patron_firstname' => $request['DeliveryAddress']['FirstName'],
'patron_lastname' => $request['DeliveryAddress']['Surname'],
'patron_type' => $request['DeliveryAddress']['patron_type'],
'patron_department' => $request['DeliveryAddress']['Department'],
'patron_email' => $request['DeliveryAddress']['DeliveryAddress'],
'notes' => isset($request['DeliveryAddress']['notes']) ? $request['DeliveryAddress']['notes'] : '',
'genre' => isset($request['BibliographicInfo']['Genre']) ? $request['BibliographicInfo']['Genre'] : '',
'doi' => isset($request['BibliographicInfo']['AdditionalNumbers']) ? $request['BibliographicInfo']['AdditionalNumbers'] : '',
'author' => isset($request['BibliographicInfo']['Author']) ? $request['BibliographicInfo']['Author'] : '',
'citation_date' => isset($request['BibliographicInfo']['Date']) ? $request['BibliographicInfo']['Date'] : '',
'title' => isset($request['BibliographicInfo']['Title']) ? $request['BibliographicInfo']['Title'] : '',
'atitle' => isset($request['BibliographicInfo']['ArticleTitle']) ? $request['BibliographicInfo']['ArticleTitle'] : '',
'issn' => isset($request['BibliographicInfo']['ISSN'][0]) ? $request['BibliographicInfo']['ISSN'][0] : '',
'isbn' => isset($request['BibliographicInfo']['ISBN'][0]) ? $request['BibliographicInfo']['ISBN'][0] : '',
'article_author' => isset($request['BibliographicInfo']['ArticleAuthor']) ? $request['BibliographicInfo']['ArticleAuthor'] : '',
'volume' => isset($request['BibliographicInfo']['Volume']) ? $request['BibliographicInfo']['Volume'] : '',
'issue' => isset($request['BibliographicInfo']['Issue']) ? $request['BibliographicInfo']['Issue'] : '',
'pages_requested' => isset($request['BibliographicInfo']['PagesRequested']) ? $request['BibliographicInfo']['PagesRequested'] : '',
'time_submitted' => strtotime($time_submitted),
'relais_request_id' => isset($response['RequestNumber']) ? $response['RequestNumber'] : '-1',
'patron_id' => $soap_data['PatronId'] ?? '',
'patron_firstname' => $patron_firstname,
'patron_lastname' => $patron_lastname,
'patron_type' => '',
'patron_department' => $soap_data['PatronDepartment'] ?? '',
'patron_email' => $soap_data['PatronEmail'] ?? '',
'notes' => $soap_data['PatronNotes'] ?? '',
'genre' => $soap_data['RapidRequestType'] ?? '',
'doi' => '',
'author' => $soap_data['ArticleAuthor'] ?? '',
'citation_date' => $soap_data['PatronJournalYear'] ?? '',
'title' => $soap_data['PatronJournalTitle'] ?? '',
'atitle' => $soap_data['ArticleTitle'] ?? '',
'issn' => $soap_data['SuggestedIssns']['string'][0] ?? '',
'isbn' => $soap_data['SuggestedIsbns']['string'][0] ?? '',
'article_author' => $soap_data['ArticleAuthor'] ?? '',
'volume' => $soap_data['JournalVol'] ?? '',
'issue' => $soap_data['JournalIssue'] ?? '',
'pages_requested' => $soap_data['ArticlePages'] ?? '',
'time_submitted' => $time_submitted,
'relais_request_id' => is_array($response) && isset($response['RequestNumber']) ? $response['RequestNumber'] : '-1',
'relais_message' => substr($relais_message, 0, 254),
])->execute();
} catch (Exception $e) {

4
includes/doi.inc

@ -157,8 +157,8 @@ function upei_roblib_ill_doi_name_from_url($doi_url) {
* @param bool parse
* parse the doi to remove prefix and whitespace etc.
*
* @return object
* An object as provided by drupal_http_request().
* @return \Psr\Http\Message\ResponseInterface
* An object as provided by \Drupal::httpClient()->get().
*/
function upei_roblib_ill_doi_load($doi, $parse = TRUE) {
// Allows for $id to pass a DOI url string or the DOI name.

260
includes/rapidill.inc

@ -0,0 +1,260 @@
<?php
/**
* @file
* Contains the RapidIllRequestHandler class for submitting ILL requests
* to RapidILL using the roblib/rapidillrequest package.
*/
use Drupal\Core\Form\FormStateInterface;
use RapidIll\InsertRequest;
use RapidIll\InsertResponse;
use RapidIll\RapidIllClient;
use RapidIll\RapidIllException;
use RapidIll\RequestType;
/**
* Handles building and submitting RapidILL requests from the ILL loan form.
*
* Usage (from the form submit handler):
* @code
* \Drupal::moduleHandler()->loadInclude('upei_roblib_ill', 'inc', 'includes/rapidill');
* $handler = new RapidIllRequestHandler();
* $response = $handler->submitRequest($form_state);
* @endcode
*/
class RapidIllRequestHandler {
/**
* Drupal config object for upei_roblib_ill.settings.
*
* @var \Drupal\Core\Config\ImmutableConfig
*/
protected $config;
/**
* Constructs a new RapidIllRequestHandler.
*/
public function __construct() {
$this->config = \Drupal::config('upei_roblib_ill.settings');
}
/**
* Maps a form Genre value to a RapidILL RequestType enum.
*
* @param string $genre
* The genre value from the ILL form ('article', 'book', or 'chapter').
*
* @return \RapidIll\RequestType
* The corresponding RequestType enum value.
*/
public function getRequestType(string $genre): RequestType {
return match ($genre) {
'book' => RequestType::Book,
'chapter' => RequestType::BookChapter,
default => RequestType::Article,
};
}
/**
* Builds a RapidILL InsertRequest from the Drupal form state.
*
* Reads bibliographic data from form storage (step 1) and patron data
* from the current form values (step 2).
*
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current form state containing both steps of the ILL form.
*
* @return \RapidIll\InsertRequest
* A populated InsertRequest ready to be submitted.
*/
public function buildInsertRequest(FormStateInterface $form_state): InsertRequest {
$storage = $form_state->getStorage();
$biblio = $storage['request'] ?? [];
$patron = $form_state->getValues();
$genre = $biblio['Genre'] ?? 'article';
$request = new InsertRequest();
$request->setRequestType($this->getRequestType($genre));
// -- Bibliographic fields --
if (!empty($biblio['Title'])) {
$request->setJournalTitle($biblio['Title']);
}
if (!empty($biblio['ArticleTitle'])) {
$request->setArticleTitle($biblio['ArticleTitle']);
}
// Use ArticleAuthor for articles/chapters, Author for books.
$author = '';
if ($genre !== 'book' && !empty($biblio['ArticleAuthor'])) {
$author = $biblio['ArticleAuthor'];
}
elseif (!empty($biblio['Author'])) {
$author = $biblio['Author'];
}
if (!empty($author)) {
$request->setArticleAuthor($author);
}
if (!empty($biblio['ISSN'])) {
$issn = is_array($biblio['ISSN']) ? reset($biblio['ISSN']) : $biblio['ISSN'];
if (!empty($issn)) {
$request->addIssn($issn);
}
}
if (!empty($biblio['ISBN'])) {
$isbn = is_array($biblio['ISBN']) ? reset($biblio['ISBN']) : $biblio['ISBN'];
if (!empty($isbn)) {
$request->addIsbn($isbn);
}
}
if (!empty($biblio['Volume'])) {
$request->setJournalVolume($biblio['Volume']);
}
if (!empty($biblio['Issue'])) {
$request->setJournalIssue($biblio['Issue']);
}
if (!empty($biblio['PagesRequested'])) {
$request->setArticlePages($biblio['PagesRequested']);
}
if (!empty($biblio['Date'])) {
$request->setJournalYear($biblio['Date']);
}
// -- Patron fields --
if (!empty($patron['campus_id'])) {
$request->setPatronId($patron['campus_id']);
}
$first_name = $patron['FirstName'] ?? '';
$surname = $patron['Surname'] ?? '';
$full_name = trim("$first_name $surname");
if (!empty($full_name)) {
$request->setPatronName($full_name);
}
if (!empty($patron['DeliveryAddress'])) {
$request->setPatronEmail($patron['DeliveryAddress']);
}
if (!empty($patron['Department'])) {
$request->setPatronDepartment($patron['Department']);
}
// Combine user notes and DOI (if present) into patron notes.
$notes_parts = [];
if (!empty($patron['notes'])) {
$notes_parts[] = $patron['notes'];
}
if (!empty($biblio['doi'])) {
$notes_parts[] = 'DOI: ' . $biblio['doi'];
}
if (!empty($notes_parts)) {
$request->setPatronNotes(implode(' | ', $notes_parts));
}
return $request;
}
/**
* Creates a RapidIllClient from the module's Drupal configuration.
*
* Reads the following config keys from 'upei_roblib_ill.settings':
* - rapid_ill_username
* - rapid_ill_password
* - rapid_ill_code
* - rapid_ill_branch_name
*
* @return \RapidIll\RapidIllClient
* A configured RapidILL client.
*
* @throws \RuntimeException
* If any required configuration value is missing.
*/
protected function createClient(): RapidIllClient {
$username = $this->config->get('rapid_ill_username');
$password = $this->config->get('rapid_ill_password');
$rapid_code = $this->config->get('rapid_ill_code');
$branch_name = $this->config->get('rapid_ill_branch_name');
if (empty($username) || empty($password) || empty($rapid_code) || empty($branch_name)) {
\Drupal::logger('upei_roblib_ill')->error(
'RapidILL configuration is incomplete. Please set rapid_ill_username, rapid_ill_password, rapid_ill_code, and rapid_ill_branch_name in the ILL settings.'
);
throw new \RuntimeException('RapidILL configuration is incomplete.');
}
return new RapidIllClient(
username: $username,
password: $password,
rapidCode: $rapid_code,
branchName: $branch_name,
);
}
/**
* Builds and submits a RapidILL request from an InsertRequest object.
*
* @param \RapidIll\InsertRequest $insert_request
* The fully built RapidILL request object.
*
* @return array
* An associative array with at least a 'ConfirmMessage' key, and
* optionally a 'RequestNumber' key on success.
*/
public function submitRequest(InsertRequest $insert_request): array {
\Drupal::moduleHandler()->loadInclude('upei_roblib_ill', 'inc', 'includes/db');
try {
$client = $this->createClient();
}
catch (\RuntimeException $e) {
$error_response = [
'ConfirmMessage' => 'RapidILL is not configured. Please contact the library.',
];
upei_roblib_ill_log_request($insert_request, $error_response);
return $error_response;
}
try {
/** @var \RapidIll\InsertResponse $response */
$response = $client->insertRequest($insert_request);
}
catch (RapidIllException $e) {
\Drupal::logger('upei_roblib_ill')->error(
'RapidILL request failed: @message',
['@message' => $e->getMessage()]
);
$error_response = [
'ConfirmMessage' => 'Error communicating with RapidILL: ' . $e->getMessage(),
];
upei_roblib_ill_log_request($insert_request, $error_response);
return $error_response;
}
// Build a response array compatible with the existing form redirect.
if ($response->isSuccessful) {
$result = [
'RequestNumber' => $response->rapidRequestId,
'ConfirmMessage' => 'Your Interlibrary Loan request has been successfully submitted to RapidILL. Your Rapid Request ID is: ' . $response->rapidRequestId,
];
}
else {
$message = $response->verificationNote ?? 'Unknown error from RapidILL.';
$result = [
'ConfirmMessage' => 'RapidILL could not process your request: ' . $message,
];
}
upei_roblib_ill_log_request($insert_request, $result);
return $result;
}
}

167
includes/relais.inc

@ -1,167 +0,0 @@
<?php
/**
* @file
* Contains the functions to send and receive data to/from Relais.
*/
use Drupal\Core\Url;
use Drupal\Core\Link;
function upei_roblib_ill_get_pub_type($genre) {
switch ($genre) {
case 'book' :
return 'B';
case 'chapter' :
return 'I';
default :
return 'J';
}
}
/**
* Submit an ILL AddRequest to relais.
*
* @param array $form_state
* A drupal form_state array
* @param string $aid
* A relais authentication id (token)
*
* @return array|mixed
*/
function upei_roblib_ill_add_request($form_state, $aid) {
module_load_include('inc', 'upei_roblib_ill', 'includes/db');
module_load_include('inc', 'upei_roblib_ill', 'includes/utilities');
$config = \Drupal::config('upei_roblib_ill.settings');
$url = trim($config->get('ill_add_url'));
$relais_arr = upei_roblib_ill_build_relais_arr($form_state);
$relais_json = json_encode($relais_arr);
$options = [
'body' => $relais_json,
'timeout' => 15,
'headers' => ['Content-Type' => 'application/json'],
];
if (!isset($aid) || is_array($aid)) {
upei_roblib_ill_log_request($relais_arr, $aid);
\Drupal::messenger()->addMessage(t('Error retrieving authentication token, @message', ['@message' => $aid['Problem']['Message']]), 'error');
return ['ConfirmMessage' => t('There was an error processing your request, @msg', ['@msg' => $aid['Problem']['Message']])];
}
//$result = drupal_http_request($url . '?aid=' . $aid, $options);
try {
$response = \Drupal::httpClient()->post($url . '?aid=' . $aid, $options);
//$response_data = (string) $response->getBody();
}
catch (Exception $e) {
return ['ConfirmMessage' => 'Error Communicating with Relais, ' . $e->getMessage()];
}
$response_arr = json_decode($response->getBody(),TRUE);
if (!isset($response_arr)) {
return ['ConfirmMessage' => 'Error Communicating with Relais, no data returned.'];
}
$response_arr['ConfirmMessage'] = isset($response_arr['Problem']['ErrorMessage']) ? $response_arr['Problem']['ErrorMessage'] : $response_arr['ConfirmMessage'];
upei_roblib_ill_log_request($relais_arr, $response_arr);
return $response_arr;
}
/**
* @param $form_state
*
* @return array
*/
function upei_roblib_ill_build_relais_arr($form_state) {
module_load_include('inc', 'upei_roblib_ill', 'includes/utilities');
$storage = $form_state->getStorage();
$ill_request = $storage['request'];
$values = $form_state->getValues();
$config = \Drupal::config('upei_roblib_ill.settings');
$relais_arr = [
"SupplyingLibrarySymbol" => $config->get('ill_library_symbol'),
];
$pub_type = upei_roblib_ill_get_pub_type($ill_request['Genre']);
$relais_arr['BibliographicInfo'] = upei_roblib_ill_clean_array($ill_request);
$relais_arr['DeliveryAddress'] = upei_roblib_ill_clean_array($values);
if ($pub_type != 'B') {
// this is not a book but is a journal or chapter we will send electronically and as copy
$relais_arr['ElectronicDelivery']['DeliveryAddress'] = $relais_arr['ElectronicDelivery']['MessagingAddress'] =
$relais_arr['DeliveryAddress']['DeliveryAddress'];
}
$request_info = upei_roblib_ill_request_info_array($relais_arr['BibliographicInfo'], $values['notes']);
$relais_arr['RequestInfo'] = $request_info;
$relais_arr['PublisherInfo']['PublicationDate'] = isset($ill_request['Date']) ?
$ill_request['Date'] : '';
$relais_arr['PublisherInfo']['PublicationType'] = $pub_type;
return $relais_arr;
}
/**
* Request an aid from Relais.
*
* @param string $barcode
* A patron_id, campus_id or barcode to identify a user
*
* @return string/array
* Returns a Relais authentication id (token) or an array containing the
* Relais response error which should include the error message if
* authentication fails
*/
function upei_roblib_ill_authenticate($barcode, $surname) {
//$url = variable_get('upei_roblib_ill_auth_url', 'https://caul-cbua.relais-host.com/portal-service/user/authentication');
$config = \Drupal::config('upei_roblib_ill.settings');
$url = $config->get('ill_auth_url');
$json_arr = [];
$json_arr['ApiKey'] = $config->get('ill_relais_key');
$json_arr['UserGroup'] = 'patron';
$json_arr['LibrarySymbol'] = $config->get('ill_library_symbol');
$json_arr['PatronId'] = $barcode;
$request_json = json_encode($json_arr);
$options = [
'body' => $request_json,
'timeout' => 15,
'headers' => ['Content-Type' => 'application/json'],
];
try {
$response = \Drupal::httpClient()->post($url, $options);
}
catch (Exception $e) {
$human_readable = '';
if($e->getCode() == '401') {
$human_readable = t('There may have been an issue with your Campus ID, '
. 'Please verify it is correct. ');
}
$response_data['Problem']['Message'] = $e->getMessage();
$response_data['Problem']['HR_Message'] = upei_roblib_ill_build_err_msg($human_readable);
return $response_data;
}
$response_data = json_decode($response->getBody(),TRUE);
$status_code = $response->getStatusCode();
if ($status_code == '200') {
if (isset($response_data['Problem']) || strtolower($response_data['LastName']) !== strtolower($surname)) {
$err_message = isset($response_data['Problem']['Message']) ? $response_data['Problem']['Message'] : '';
$response_data['Problem']['Message'] = upei_roblib_ill_build_err_msg($err_message);
return $response_data;
}
$aid = $response_data['AuthorizationId'];
}
return isset($aid) ? $aid : $response_data;
}
function upei_roblib_ill_build_err_msg($msg_from_server) {
$campus_id = Link::fromTextAndUrl(t('Campus ID'), Url::fromUri('http://www.upei.ca/vpaf/campuscard'));
//$campus_id = l(t('Campus ID'), 'http://www.upei.ca/vpaf/campuscard');
$ill_email = Link::fromTextAndUrl('ill@upei.ca', Url::fromUri('mailto:ill@upei.ca'));
//$ill_email = l(t('ill@upei.ca'), 'mailto:ill@upei.ca');
$phone = Link::fromTextAndUrl('902-566-0583', Url::fromUri('tel:902-566-0353'));
//$phone = l(t('902-566-0583'), 'tel:902-566-0353');
$server_response = !empty($msg_from_server) ? 'Server Response: ' . $msg_from_server : '';
return t('Oops. Something went wrong.<br />Check the "Your Last Name" and "Your Campus ID" fields - those two need to match what is on file
. (Your @campus_id appears as the NUMBER near the middle of your campus card). If you do not have a @campus_id, please contact the Robertson Library Service Desk, or,
call @phone. Note: if you are a student taking online courses only, please email @ill_email.<br />@msg_from_server',
[
'@campus_id' => $campus_id->toString(),
'@ill_email' => $ill_email->toString(),
'@phone' => $phone->toString(),
'@msg_from_server' => $server_response,
]);
}

189
includes/utilities.inc

@ -11,18 +11,120 @@
* @param $key
*/
use Drupal\Component\Utility\Xss;
use Drupal\Component\Utility\Html;
function upei_roblib_ill_check_arr_item(&$value, $key) {
if (is_array($value)) {
array_walk($value, 'upei_roblib_ill_check_arr_item');
/**
* Lookup the user via a simple verification endpoint and verify the surname matches.
*
* Makes an HTTP GET to the configured URL (e.g., https://ill.libraryupei.ca/verify_eg_user.php)
* with a `userid` query parameter, and compares the returned `family_name`.
*
* @param string $user_id
* The Evergreen user ID.
* @param string $surname
* The surname to check against.
*
* @return bool
* TRUE if the surname matches, FALSE otherwise.
*/
function upei_roblib_ill_authenticate($user_id, $surname): bool
{
if (empty($user_id) || empty($surname)) {
return FALSE;
}
else {
$value = Xss::filter($value);
$config = \Drupal::config('upei_roblib_ill.settings');
// Use the configured URL, falling back to the custom one if not set accurately.
$evergreen_api_url = $config->get('evergreen_api_url');
if (empty($evergreen_api_url)) {
$evergreen_api_url = 'https://ill.libraryupei.ca/verify_eg_user.php';
}
try {
$response = \Drupal::httpClient()->get($evergreen_api_url, [
'timeout' => 10,
'query' => [
'userid' => $user_id,
],
]);
$data = json_decode((string)$response->getBody(), TRUE);
if (!empty($data['error'])) {
\Drupal::logger('upei_roblib_ill')->warning('Evergreen REST API returned error for user ID @user_id: @error', [
'@user_id' => $user_id,
'@error' => $data['error'],
]);
return FALSE;
}
$evergreen_surname = $data['family_name'] ?? '';
// Case-insensitive comparison of the Evergreen surname and provided surname.
if (strcasecmp(trim($evergreen_surname), trim($surname)) === 0) {
return TRUE;
}
\Drupal::logger('upei_roblib_ill')->warning('Evergreen authentication failed for user ID @user_id. Expected surname: @surname, got: @evergreen_surname', [
'@user_id' => $user_id,
'@surname' => $surname,
'@evergreen_surname' => $evergreen_surname,
]);
return FALSE;
}
catch (\Exception $e) {
\Drupal::logger('upei_roblib_ill')->error('Failed to connect to Evergreen REST API: @message', [
'@message' => $e->getMessage(),
]);
return FALSE;
}
}
/**
* Allows us to ask for _REQUEST variables that may or may not exist without
* generating a php warning. Also does some formatting for certain variables.
*
* @param string $variable
* The name of the $_REQUEST variable to check
*
* @return string
* The value of the $_REQUEST variable or an empty string.
*/
function upei_roblib_ill_get_request_variable($variable)
{
if ($variable == 'author' && empty($_REQUEST[$variable])) {
//google scholar usually sends auinit aulast instead of author
$initial = isset($_REQUEST['auinit']) ?Html::escape($_REQUEST['auinit']) : NULL;
$last_name = isset($_REQUEST['aulast']) ?Html::escape($_REQUEST['aulast']) : NULL;
return !empty($last_name) ? $last_name . ',' . $initial : '';
}
if ($variable == 'issn' && !empty($_REQUEST[$variable])) {
// ebsco sometimes sends garbage as issns verify this is a valid issn before displaying the value in the form.
return preg_match('/^\d{4}-?\d{3}[\dxX]$/', $_REQUEST[$variable]) ?Html::escape($_REQUEST[$variable]) : '';
}
// ebsco sometimes returns bookitem we only understand chapter
if (($variable == 'genre' && !empty($_REQUEST[$variable])) && $_REQUEST[$variable] == 'bookitem') {
return 'chapter';
}
return isset($_REQUEST[$variable]) ?Html::escape($_REQUEST[$variable]) : '';
}
function upei_roblib_ill_get_doi_from_request()
{
return (!empty($_REQUEST['doi'])) ? $_REQUEST['doi'] : upei_roblib_ill_get_doi_from_id();
}
function upei_roblib_ill_get_doi_from_id()
{
if (!empty($_REQUEST['ID'])) {
return (strpos($_REQUEST['ID'], 'doi:') !== 0) ? '' : $_REQUEST['ID'];
}
return '';
}
/**
* Removes empty elements and drupal specific elements from an array
*
@ -33,7 +135,8 @@ function upei_roblib_ill_check_arr_item(&$value, $key) {
* An array where the keys in the array that have empty values are removed and
* drupal specific elements are removed.
*/
function upei_roblib_ill_clean_array($values) {
function upei_roblib_ill_clean_array($values)
{
$arr = array_filter($values);
if (isset($arr['ISSN'])) {
$arr['ISSN'] = [$arr['ISSN']];
@ -71,72 +174,17 @@ function upei_roblib_ill_clean_array($values) {
return $arr;
}
/**
* Allows us to ask for _REQUEST variables that may or may not exist without
* generating a php warning. Also does some formatting for certain variables.
*
* @param string $variable
* The name of the $_REQUEST variable to check
*
* @return string
* The value of the $_REQUEST variable or an empty string.
*/
function upei_roblib_ill_get_request_variable($variable) {
if ($variable == 'author' && empty($_REQUEST[$variable])) {
//google scholar usually sends auinit aulast instead of author
$initial = isset($_REQUEST['auinit']) ? Html::escape($_REQUEST['auinit']) : NULL;
$last_name = isset($_REQUEST['aulast']) ? Html::escape($_REQUEST['aulast']) : NULL;
return !empty($last_name) ? $last_name . ',' . $initial : '';
}
if ($variable == 'issn' && !empty($_REQUEST[$variable])) {
// ebsco sometimes sends garbage as issns verify this is a valid issn before displaying the value in the form.
return preg_match('/^\d{4}-?\d{3}[\dxX]$/', $_REQUEST[$variable]) ? Html::escape($_REQUEST[$variable]) : '';
}
// ebsco sometimes returns bookitem we only understand chapter
if (($variable == 'genre' && !empty($_REQUEST[$variable])) && $_REQUEST[$variable] == 'bookitem') {
return 'chapter';
function upei_roblib_ill_check_arr_item(&$value, $key) {
if (is_array($value)) {
array_walk($value, 'upei_roblib_ill_check_arr_item');
}
return isset($_REQUEST[$variable]) ? Html::escape($_REQUEST[$variable]) : '';
//else {
// $value = Xss::filter($value);
//}
}
function upei_roblib_ill_get_doi_from_request() {
return (!empty($_REQUEST['doi'])) ? $_REQUEST['doi'] : upei_roblib_ill_get_doi_from_id();
}
function upei_roblib_ill_get_doi_from_id() {
if (!empty($_REQUEST['ID'])) {
return (strpos($_REQUEST['ID'], 'doi:') !== 0) ? '' : $_REQUEST['ID'];
}
return '';
}
/**
* Populates the requestInfo portion of a Relais request
*
* @param array $values
* an array containing a 'Genre' element.
*
* @return array
* The requestInfo portion of a Relais request
*/
function upei_roblib_ill_request_info_array($values, $notes) {
$requestInfo = [];
$genre = $values['Genre'];
$requestInfo['DateSubmitted'] = date('Y-m-d H:i:s');
$requestInfo['Notes'] = $notes;
if ($genre == 'book') {
$requestInfo['ServiceType'] = 'L';
$requestInfo['ServiceLabel'] = "R";
//$requestInfo['RequestSource'] = "C";
}
else {
$requestInfo['ServiceType'] = 'X';
$requestInfo['ServiceLabel'] = "R";
//$requestInfo['RequestSource'] = "C";
}
return $requestInfo;
}
/**
* Creates a summary Table based on the biblio information in the form_state
@ -146,8 +194,9 @@ function upei_roblib_ill_request_info_array($values, $notes) {
*
* @return string
*/
function upei_roblib_format_biblio_info($form_state) {
$values = $form_state->getValues();
function upei_roblib_format_biblio_info($form_state)
{
$values = $form_state->getValues();
$data = upei_roblib_ill_clean_array($values);
$rows = [];
foreach ($data as $key => $value) {

91
src/Form/RoblibIllLoanForm.php

@ -10,19 +10,22 @@ use Drupal\Core\Form\FormStateInterface;
*
* @author ppound
*/
class RoblibIllLoanForm extends FormBase {
class RoblibIllLoanForm extends FormBase
{
/**
* {@inheritdoc}
*/
public function getFormId() {
public function getFormId()
{
return 'roblib_ill_loan_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
public function buildForm(array $form, FormStateInterface $form_state)
{
if ($form_state->has('step') && $form_state->get('step') == 2) {
return $this->ill_auth_form($form, $form_state);
}
@ -32,8 +35,9 @@ class RoblibIllLoanForm extends FormBase {
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
module_load_include('inc', 'upei_roblib_ill', 'includes/relais');
public function validateForm(array &$form, FormStateInterface $form_state)
{
\Drupal::moduleHandler()->loadInclude('upei_roblib_ill', 'inc', 'includes/utilities');
$values = $form_state->getValues();
if ($form_state->get('step') == 2) {
$is_valid_email = \Drupal::service('email.validator')->isValid($values['DeliveryAddress']);
@ -46,29 +50,28 @@ class RoblibIllLoanForm extends FormBase {
$campus_id = $this->ill_form_message_id($values['campus_id']);
$aid = upei_roblib_ill_authenticate($campus_id, $values['Surname']);
if (is_array($aid) && isset($aid['Problem']['Message'])) {
if (!empty($aid['Problem']['HR_Message'])) {
$form_state->setErrorByName('campus_id', $aid['Problem']['HR_Message']);
}
$form_state->setErrorByName('Surname', $aid['Problem']['Message']);
\Drupal::moduleHandler()->loadInclude('upei_roblib_ill', 'inc', 'includes/rapidill');
$handler = new \RapidIllRequestHandler();
$insert_request = $handler->buildInsertRequest($form_state);
$form_state->set('insert_request', $insert_request);
$auth = upei_roblib_ill_authenticate($campus_id, $values['Surname']);
if (!$auth) {
$err = 'UserID or Surname do not match or not found.';
$form_state->setErrorByName('Surname', $err);
// Log invalid requests, we need to build the full array here to log it, even though we won't send it yet as auth has failed.
//$form_state->set('upei_roblib_ill_auth_form_storage') = $form_state->getValues();
module_load_include('inc', 'upei_roblib_ill', 'includes/db');
$arr = upei_roblib_ill_build_relais_arr($form_state);
upei_roblib_ill_log_request($arr, $aid);
}
else {
$form_state->set('aid', $aid);
}
}
$trigger = $form_state->getTriggeringElement();
if($trigger['#value'] != 'Lookup DOI' && empty($form_state->get('step'))) {
if(empty($form_state->getValue('Title'))){
$form_state->setErrorByName('Title', t('Journal/Book Title is required.'));
\Drupal::moduleHandler()->loadInclude('upei_roblib_ill', 'inc', 'includes/db');
upei_roblib_ill_log_request($insert_request, $err);
}
if(empty($form_state->getValue('Genre'))) {
$form_state->setErrorByName('Title', t('Item Type is required.'));
$trigger = $form_state->getTriggeringElement();
if ($trigger['#value'] != 'Lookup DOI' && empty($form_state->get('step'))) {
if (empty($form_state->getValue('Title'))) {
$form_state->setErrorByName('Title', t('Journal/Book Title is required.'));
}
if (empty($form_state->getValue('Genre'))) {
$form_state->setErrorByName('Title', t('Item Type is required.'));
}
}
}
}
@ -80,7 +83,8 @@ class RoblibIllLoanForm extends FormBase {
* @return mixed
* the campus id with leading zeros and leading/trailing whitespace removed.
*/
function ill_form_message_id($id) {
function ill_form_message_id($id)
{
// Equinox made some changes to the database so we may not need to do
// this anymore.
// Doing this simple change for now in case things need to be reverted.
@ -95,7 +99,8 @@ class RoblibIllLoanForm extends FormBase {
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
*/
public function submitStepOne(array &$form, FormStateInterface $form_state) {
public function submitStepOne(array &$form, FormStateInterface $form_state)
{
$trigger = $form_state->getTriggeringElement();
if ($trigger['#value'] != 'Lookup DOI') {
$form_state
@ -108,7 +113,8 @@ class RoblibIllLoanForm extends FormBase {
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
public function submitForm(array &$form, FormStateInterface $form_state)
{
$trigger = $form_state->getTriggeringElement();
if ($trigger['#value'] == 'Lookup DOI') {
//Do nothing as this was just a DOI Lookup
@ -116,18 +122,25 @@ class RoblibIllLoanForm extends FormBase {
return;
}
//process the form
$response = upei_roblib_ill_add_request($form_state, $form_state->get('aid'));
\Drupal::moduleHandler()->loadInclude('upei_roblib_ill', 'inc', 'includes/rapidill');
$handler = new \RapidIllRequestHandler();
$insert_request = $form_state->get('insert_request');
if (!$insert_request) {
$insert_request = $handler->buildInsertRequest($form_state);
}
$response = $handler->submitRequest($insert_request);
$error = isset($response['RequestNumber']) ? 'FALSE' : 'TRUE';
$parameters = [
'message' => $response['ConfirmMessage'],
'email' => $form_state->getValue('DeliveryAddress'),
'error' => $error,
];
];
$form_state->setRedirect('roblib_ill.loan_form_finished', $parameters);
}
public function doiCallback(array &$form, FormStateInterface $form_state) {
module_load_include('inc', 'upei_roblib_ill', 'includes/doi');
public function doiCallback(array &$form, FormStateInterface $form_state)
{
\Drupal::moduleHandler()->loadInclude('upei_roblib_ill', 'inc', 'includes/doi');
$doi = $form_state->getValue('doi');
$form = upei_roblib_ill_doi_get_data($form, $doi);
return $form;
@ -144,8 +157,9 @@ class RoblibIllLoanForm extends FormBase {
* @return array
* An array representing the bibliographic form.
*/
function ill_request_form($form, &$form_state) {
module_load_include('inc', 'upei_roblib_ill', 'includes/utilities');
function ill_request_form($form, &$form_state)
{
\Drupal::moduleHandler()->loadInclude('upei_roblib_ill', 'inc', 'includes/utilities');
$config = \Drupal::config('upei_roblib_ill.settings');
$form['#prefix'] = '<div id="upei-roblib-ill-request-form">';
$form['#suffix'] = '<div class="roblib-required">* = Required Field</div></div>';
@ -358,8 +372,9 @@ class RoblibIllLoanForm extends FormBase {
* @return array
* An array representing the bibliographic form.
*/
function ill_auth_form($form, &$form_state) {
module_load_include('inc', 'upei_roblib_ill', 'includes/utilities');
function ill_auth_form($form, &$form_state)
{
\Drupal::moduleHandler()->loadInclude('upei_roblib_ill', 'inc', 'includes/utilities');
$form['#prefix'] = upei_roblib_format_biblio_info($form_state);
$form['#suffix'] = '<div class="roblib-required">* = Required Field</div>
<div class="roblib-FOIPP"><strong>Protection of Privacy</strong> - The personal information requested
@ -504,4 +519,4 @@ Freedom of Information and Protection of Privacy Act and will be protected
return $form;
}
}
}

135
src/Form/RoblibIllSettingsForm.php

@ -10,57 +10,35 @@ use Drupal\Core\Form\FormStateInterface;
*
* @author ppound
*/
class RoblibIllSettingsForm extends FormBase {
class RoblibIllSettingsForm extends FormBase
{
/**
* {@inheritdoc}
*/
public function getFormId() {
public function getFormId()
{
return 'roblib_ill_settings_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
public function buildForm(array $form, FormStateInterface $form_state)
{
$config = \Drupal::config('upei_roblib_ill.settings');
$form = [];
$form['ill_add_url'] = [
'#required' => TRUE,
'#type' => 'textfield',
'#size' => 200,
'#title' => t('The Relais AddRequest URL'),
'#description' => t('The URL for the Relais ILL server AddRequest service, the default is
https://caul-cbua.relais-host.com/portal-service/request/add'),
'#default_value' => $config->get('ill_add_url'),
];
$form['ill_auth_url'] = [
'#required' => TRUE,
'#type' => 'textfield',
'#size' => 200,
'#title' => t('The Relais Auth URL'),
'#description' => t('The URL for the Relais ILL server Auth service (retrieve the aid), the default is
https://caul-cbua.relais-host.com/portal-service/user/authentication'),
'#default_value' => $config->get('ill_auth_url'),
];
$form['ill_library_symbol'] = [
'#required' => TRUE,
'#type' => 'textfield',
'#size' => 200,
'#title' => t('Your Relais Library Symbol'),
'#title' => t('Your ILL Library Symbol'),
'#description' => t('Your Relais Library Symbol'),
'#default_value' => $config->get('ill_library_symbol'),
];
$form['ill_relais_key'] = [
'#required' => TRUE,
'#type' => 'textfield',
'#size' => 200,
'#title' => t('The Relais API key'),
'#description' => t('The API key used to communicate with the Relais API, Contact Relais International to get your key'),
'#default_value' => $config->get('ill_relais_key'),
];
$form['ill_doi_openurl_pid'] = [
'#required' => TRUE,
'#type' => 'textfield',
@ -85,7 +63,71 @@ class RoblibIllSettingsForm extends FormBase {
'#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'),
];
$form['actions']['submit'] = [
// 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',
@ -97,22 +139,39 @@ class RoblibIllSettingsForm extends FormBase {
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
public function validateForm(array &$form, FormStateInterface $form_state)
{
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
public function submitForm(array &$form, FormStateInterface $form_state)
{
$config = \Drupal::configFactory()->getEditable('upei_roblib_ill.settings');
$config->set('ill_add_url', $form_state->getValue('ill_add_url'))->save();
$config->set('ill_auth_url', $form_state->getValue('ill_auth_url'))->save();
$config->set('ill_library_symbol', $form_state->getValue('ill_library_symbol'))->save();
$config->set('ill_relais_key', $form_state->getValue('ill_relais_key'))->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();
}
}
}

13
upei_roblib_ill.install

@ -6,7 +6,7 @@
function upei_roblib_ill_update_7100() {
db_change_field('upei_roblib_ill_request', 'isbn', 'isbn',
\Drupal::database()->schema()->changeField('upei_roblib_ill_request', 'isbn', 'isbn',
array(
'description' => 'book isbn',
'type' => 'varchar',
@ -16,6 +16,17 @@ function upei_roblib_ill_update_7100() {
);
}
/**
* Remove obsolete Relais configuration keys.
*/
function upei_roblib_ill_update_9301() {
\Drupal::configFactory()->getEditable('upei_roblib_ill.settings')
->clear('ill_add_url')
->clear('ill_auth_url')
->clear('ill_relais_key')
->save();
}
/**
* Implements hook_schema().
*/

4
upei_roblib_ill.module

@ -9,7 +9,7 @@
* @return array
*/
function upei_roblib_ill_doi_callback($form, &$form_state) {
module_load_include('inc', 'upei_roblib_ill', 'includes/doi');
\Drupal::moduleHandler()->loadInclude('upei_roblib_ill', 'inc', 'includes/doi');
$form = upei_roblib_ill_doi_get_data($form, $form_state['values']['doi']);
return $form;
}
@ -20,7 +20,7 @@ function upei_roblib_ill_doi_callback($form, &$form_state) {
function upei_roblib_ill_views_api() {
return [
'api' => 3,
'path' => drupal_get_path('module', 'upei_roblib_ill') . '/views',
'path' => \Drupal::service('extension.list.module')->getPath('upei_roblib_ill') . '/views',
];
}

Loading…
Cancel
Save