Browse Source

loan request form displays but no processing yet

9.x-1.0
ppound 3 years ago
parent
commit
c01f54555b
  1. 10
      includes/utilities.inc
  2. 411
      src/Form/RoblibIllLoanForm.php
  3. 36
      upei_roblib_ill.module
  4. 4
      upei_roblib_ill.routing.yml

10
includes/utilities.inc

@ -10,12 +10,15 @@
* @param $value * @param $value
* @param $key * @param $key
*/ */
use Drupal\Component\Utility\Xss;
function upei_roblib_ill_check_arr_item(&$value, $key) { function upei_roblib_ill_check_arr_item(&$value, $key) {
if (is_array($value)) { if (is_array($value)) {
array_walk($value, 'upei_roblib_ill_check_arr_item'); array_walk($value, 'upei_roblib_ill_check_arr_item');
} }
else { else {
$value = filter_xss($value); $value = Xss::filter($value);
} }
} }
@ -143,7 +146,8 @@ function upei_roblib_ill_request_info_array($values, $notes) {
* @return string * @return string
*/ */
function upei_roblib_format_biblio_info($form_state) { function upei_roblib_format_biblio_info($form_state) {
$data = upei_roblib_ill_clean_array($form_state['storage']['upei_roblib_ill_request_form']); $values = $form_state->getValues();
$data = upei_roblib_ill_clean_array($values);
$rows = []; $rows = [];
foreach ($data as $key => $value) { foreach ($data as $key => $value) {
if ($key == 'ISSN' || $key == 'ISBN') { if ($key == 'ISSN' || $key == 'ISBN') {
@ -157,6 +161,6 @@ function upei_roblib_format_biblio_info($form_state) {
'#prefix' => '<div class=upei-roblib-ill-biblio-info>', '#prefix' => '<div class=upei-roblib-ill-biblio-info>',
'#suffix' => '</div>', '#suffix' => '</div>',
]; ];
$html_output = drupal_render($output); $html_output = \Drupal::service('renderer')->render($output);
return $html_output; return $html_output;
} }

411
src/Form/RoblibIllLoanForm.php

@ -23,11 +23,22 @@ class RoblibIllLoanForm extends FormBase {
* {@inheritdoc} * {@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);
}
return $this->ill_request_form($form, $form_state);
/* $values = $form_state->getValues();
$form = []; if (empty($values)) {
$form_name = 'upei_roblib_ill_request_form';
return $form; }
else {
$form_name = 'upei_roblib_ill_auth_form';
}
$form_state->setValue('step', $from_name);
return $form_name === 'upei_roblib_ill_request_form' ? $this->ill_request_form($form, $form_state) :
$this->ill_auth_form($form, $form_state);
* */
} }
/** /**
@ -37,11 +48,403 @@ class RoblibIllLoanForm extends FormBase {
} }
/**
* @param array $form
* An associative array containing the structure of the form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
*/
public function submitStepOne(array &$form, FormStateInterface $form_state) {
$form_state
->set('step', 2)
->setRebuild(TRUE);
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function submitForm(array &$form, FormStateInterface $form_state) { public function submitForm(array &$form, FormStateInterface $form_state) {
//process the form
//$response = upei_roblib_ill_add_request($form_state, $form_state['storage']['aid']);
//$error = isset($response['RequestNumber']) ? 'FALSE' : 'TRUE';
$form_state->setRedirect('roblib_ill.loan_form_finished');
/*$form_state->set['redirect'] = [
'/upei/roblib/ill/finished',
[
'query' => [
'message' => 'test message',//$response['ConfirmMessage'],
'email' => 'test email',//$form_state['values']['DeliveryAddress'],
'error' => 'no errors',//$error,
],
],
];*/
}
/**
* The bibliographic portion of the ILL form.
*
* @param array $form
* An array representing a Drupal form.
* @param array $form_state
* An array containing the Drupal form state.
*
* @return array
* An array representing the bibliographic form.
*/
function ill_request_form($form, &$form_state) {
module_load_include('inc', 'upei_roblib_ill', 'includes/utilities');
$config = \Drupal::config('upei_roblib_ill.settings');
$header_message = $config->get('ill_header_message', '');
$emergency_message = '';
if (!empty($header_message)) {
$emergency_message = '<div class="messages messages--error closure-notice">';
$emergency_message .= $header_message;
$emergency_message .= '</div>';
}
$form['#prefix'] = $emergency_message . '<div id="upei-roblib-ill-request-form">';
$form['#suffix'] = '<div class="roblib-required">* = Required Field</div></div>';
$type = upei_roblib_ill_get_request_variable('genre');
$genre = empty($type) ? 'article' : $type;
$form['Genre'] = [
'#type' => 'select',
'#title' => t('Item Type'),
'#options' => [
'book' => t('Book'),
'chapter' => t('Book Chapter'),
'article' => t('Journal Article'),
],
'#required' => TRUE,
];
if (!empty($type)) {
$form['Genre']['#default_value'] = $type;
}
$form['doi'] = [
'#type' => 'textfield',
'#title' => t("DOI (ex: 10.1016/j.ypmed.2019.01.018) <a href='https://library.upei.ca/doi'>more info</a>"),
'#default_value' => upei_roblib_ill_get_doi_from_request(),
//'#description' => 'DOI, if you provide a DOI we will attempt to lookup the record for you',
'#size' => 50,
'#states' => [
'invisible' => [
':input[name="Genre"]' => ['value' => 'book'],
],
],
'#required' => FALSE,
];
$form['doi_button'] = [
'#type' => 'submit',
'#value' => 'Lookup DOI',
'#ajax' => [
'callback' => 'upei_roblib_ill_doi_callback',
'method' => 'replace',
'wrapper' => 'upei-roblib-ill-request-form',
'effect' => 'fade',
],
'#states' => [
'invisible' => [
':input[name="Genre"]' => ['value' => 'book'],
],
],
'#required' => FALSE,
];
$form['Title'] = [
'#type' => 'textarea',
'#rows' => 2,
'#title' => t('Journal/Book Title *'),
'#default_value' => upei_roblib_ill_get_request_variable('title'),
//'#description' => 'Journal or Book Title (Required)',
'#size' => 50,
'#required' => FALSE,
];
$form['ArticleTitle'] = [
'#type' => 'textarea',
'#rows' => 2,
'#title' => t('Article/Chapter Title'),
'#default_value' => upei_roblib_ill_get_request_variable('atitle'),
//'#description' => 'Article or Chapter Title',
'#size' => 50,
'#states' => [
'invisible' => [
':input[name="Genre"]' => ['value' => 'book'],
],
],
'#required' => FALSE,
];
$form['ISSN'] = [
'#type' => 'textfield',
'#title' => t('ISSN (ex: 1234-567X)'),
'#default_value' => upei_roblib_ill_get_request_variable('issn'),
'#size' => 50,
'#states' => [
'visible' => [
':input[name="Genre"]' => ['value' => 'article'],
],
],
'#required' => FALSE,
];
$article_author = ($genre == 'book') ? '' : upei_roblib_ill_get_request_variable('author');
$form['ArticleAuthor'] = [
'#type' => 'textfield',
'#title' => t('Article/Chapter Author'),
'#default_value' => $article_author,
'#size' => 50,
'#required' => FALSE,
//'#description' => 'Article or Chapter Author',
'#states' => [
'invisible' => [
':input[name="Genre"]' => ['value' => 'book'],
],
],
];
$author = ($genre == 'book') ? upei_roblib_ill_get_request_variable('author') : '';
$form['Author'] = [
'#type' => 'textfield',
'#title' => t('Book Author'),
'#default_value' => $author,
'#size' => 50,
'#required' => FALSE,
'#states' => [
'invisible' => [
':input[name="Genre"]' => ['value' => t('article')],
],
],
];
$form['ISBN'] = [
'#type' => 'textfield',
'#title' => t('ISBN (ex: 9780323554459)'),
'#default_value' => upei_roblib_ill_get_request_variable('isbn'),
'#size' => 50,
'#states' => [
'invisible' => [
':input[name="Genre"]' => ['value' => 'article'],
],
],
'#required' => FALSE,
];
$form['SubTitle'] = [
'#type' => 'hidden',
'#title' => t('Sub Title'),
'#default_value' => upei_roblib_ill_get_request_variable('ubtitle'),
'#size' => 50,
'#required' => FALSE,
];
$form['SeriesTitle'] = [
'#type' => 'hidden',
'#title' => t('Series Title'),
'#default_value' => upei_roblib_ill_get_request_variable('stitle'),
'#size' => 50,
'#required' => FALSE,
];
$form['Volume'] = [
'#type' => 'textfield',
'#title' => t('Volume'),
'#default_value' => upei_roblib_ill_get_request_variable('volume'),
'#size' => 50,
'#required' => FALSE,
'#states' => [
'visible' => [
':input[name="Genre"]' => ['value' => 'article'],
],
],
];
$form['Issue'] = [
'#type' => 'textfield',
'#title' => t('Issue'),
'#default_value' => upei_roblib_ill_get_request_variable('issue'),
'#size' => 50,
'#required' => FALSE,
'#states' => [
'visible' => [
':input[name="Genre"]' => ['value' => 'article'],
],
],
];
$form['PagesRequested'] = [
'#type' => 'textfield',
'#title' => t('Pages (startpage-endpage)'),
'#default_value' => upei_roblib_ill_get_request_variable('pages'),
//'#description' => 'Pages requested (startpage-endpage)',
'#size' => 50,
'#required' => FALSE,
'#states' => [
'invisible' => [
':input[name="Genre"]' => ['value' => 'book'],
],
],
];
$form['Date'] = [
'#type' => 'textfield',
'#title' => t('Publication Date'),
'#default_value' => upei_roblib_ill_get_request_variable('date'),
'#size' => 50,
'#required' => FALSE,
];
$form['actions'] = [
'#type' => 'actions',
];
$form['actions']['next'] = [
'#type' => 'submit',
'#button_type' => 'primary',
'#value' => $this->t('Next'),
'#submit' => ['::submitStepOne'],
//'#validate' => ['::validatePageOne'],
];
return $form;
}
/**
* The patron portion of the ILL form.
*
* The campus_id and email portion are also used in a request for an Relais aid.
*
* @param array $form
* An array representing a Drupal form.
* @param array $form_state
* An array containing the Drupal form state.
*
* @return array
* An array representing the bibliographic form.
*/
function ill_auth_form($form, &$form_state) {
module_load_include('inc', 'upei_roblib_ill', '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
on this form is collected under the authority of Section 31(c) of the PEI
Freedom of Information and Protection of Privacy Act and will be protected
under Part 2 of that Act. It will be used for the purpose of administering
and providing library service. Direct any questions about this collection to
Health Sciences and Scholarly Communications Librarian at ill@upei.ca, 550
University Ave, Charlottetown PE , 902-566-0453.</div>';
$form['FirstName'] = [
'#type' => 'textfield',
'#title' => t('Your First Name'),
'#size' => 50,
'#required' => TRUE,
];
$form['Surname'] = [
'#type' => 'textfield',
'#title' => t('Your Last Name'),
'#size' => 50,
'#required' => TRUE,
];
$form['campus_id'] = [
'#type' => 'textfield',
'#title' => t('Your Campus ID'),
'#size' => 50,
'#required' => TRUE,
];
$patron_types = [
'Faculty/Staff' => t('Faculty/Staff'),
'Undergraduate Student' => t('Undergraduate Student'),
'Masters Student' => t('Masters Student'),
'Doctoral Student' => t('Doctoral Student'),
'Alumni Premiere Subscriber' => t('Alumni Premiere Subscriber'),
'Alumni/Public' => t('Alumni/Public'),
'Other' => 'Other',
];
$departments = [
'Actuarial Science' => t('Actuarial Science'),
'Analytics' => t('Analytics'),
'Applied Communication, Leadership, and Culture' => t('Applied Communication, Leadership, and Culture'),
'Applied Health Services Research' => t('Applied Health Services Research'),
'Applied Human Sciences' => t('Applied Human Sciences'),
'Arts (General)' => t('Arts (General)'),
'Biology' => t('Biology'),
'Business' => t('Business'),
'Canadian Studies' => t('Canadian Studies'),
'Chemistry' => t('Chemistry'),
'Climate Change and Adaptation' => t('Climate Change and Adaptation'),
'Computer Science' => t('Computer Science'),
'Diversity and Social Justice Studies' => t('Diversity and Social Justice Studies'),
'Economics' => t('Economics'),
'Education' => t('Education'),
'English' => t('English'),
'Environmental Studies/Sciences' => t('Environmental Studies/Sciences'),
'Financial Mathematics' => t('Financial Mathematics'),
'Foods and Nutrition' => t('Foods and Nutrition'),
'French' => t('French'),
'Global Affairs' => t('Global Affairs'),
'History' => t('History'),
'Integrated Studies' => t('Integrated Studies'),
'Island Studies' => t('Island Studies'),
'Journalism' => t('Journalism'),
'Kinesiology' => t('Kinesiology'),
'Library, Robertson' => t('Library, Robertson'),
'Nursing' => t('Nursing'),
'Mathematics' => t('Mathematics'),
'Modern Languages' => t('Modern Languages'),
'Music' => t('Music'),
'Paramedicine' => t('Paramedicine'),
'Philosophy' => t('Philosophy'),
'Physics' => t('Physics'),
'Political Science' => t('Political Science'),
'Psychology' => t('Psychology'),
'Radiography' => t('Radiography'),
'Religious Studies' => t('Religious Studies'),
'Science (General)' => t('Science (General)'),
'Sociology/Anthropology' => t('Sociology/Anthropology'),
'Spanish' => t('Spanish'),
'Statistics' => t('Statistics'),
'Sustainable Design Engineering' => t('Sustainable Design Engineering'),
'Wildlife Conservation' => t('Wildlife Conservation'),
'Veterinary Medicine' => t('Veterinary Medicine'),
'Other' => ('Other (please add to the notes field)'),
];
$form['patron_type'] = [
'#type' => 'select',
'#title' => t('Your Patron Type'),
'#options' => $patron_types,
'#required' => TRUE,
];
$form['Department'] = [
'#type' => 'select',
'#title' => t('Your Department'),
'#options' => $departments,
'#required' => TRUE,
];
$form['DeliveryAddress'] = [
'#type' => 'textfield',
'#title' => t('Your Email (If using an email address other than @upei.ca, enter that address in the Notes field as well.)'),
'#size' => 50,
'#required' => TRUE,
];
$form['InstitutionName'] = [
'#type' => 'hidden',
'#title' => t('Name of Institution'),
'#size' => 50,
'#default_value' => 'University of Prince Edward Island',
'#required' => TRUE,
];
$form['LibraryName'] = [
'#type' => 'hidden',
'#title' => t('Name of Library'),
'#size' => 50,
'#default_value' => 'Robertson Library',
'#required' => TRUE,
];
$form['notes'] = [
'#type' => 'textarea',
'#title' => t('Notes'),
'#size' => 50,
'#required' => FALSE,
];
$form['certify'] = [
'#title' => t('I certify'),
'#type' => 'checkbox',
'#description' => 'I hereby certify that this item is being sought for a fair dealing purpose and any copying will be in accordance with the Copyright Act. ',
'#size' => 50,
'#required' => TRUE,
];
$form['submit'] = [
'#type' => 'submit',
'#value' => 'Submit',
];
return $form;
} }
} }

36
upei_roblib_ill.module

@ -1,40 +1,4 @@
<?php <?php
/**
* @file
* The drupal module file for upei_roblib_ill module
*/
function upei_roblib_ill_menu() {
$items = [];
$items['admin/settings/roblibill'] = [
'title' => 'UPEI Roblib ILL settings',
'description' => 'Conifiguration for the UPEI ILL forms',
'page callback' => 'drupal_get_form',
'page arguments' => ['upei_roblib_ill_admin_form'],
'access arguments' => ['access administration pages'],
'file' => 'includes/admin.form.inc',
'type' => MENU_NORMAL_ITEM,
];
$items['upei/roblib/ill'] = [
'title' => 'UPEI ILL Form',
'description' => 'The entry point for the UPEI ILL forms',
'page callback' => 'drupal_get_form',
'page arguments' => ['upei_roblib_ill_form'],
'access arguments' => ['access content'],
'file' => 'includes/form.inc',
'type' => MENU_NORMAL_ITEM,
];
$items['upei/roblib/ill/finished'] = [
'title' => 'UPEI ILL Request',
'description' => 'Redirect to this page after form is submitted',
'page callback' => 'upei_roblib_ill_form_redirect',
'access arguments' => ['access content'],
'file' => 'includes/form.inc',
'type' => MENU_NORMAL_ITEM,
];
return $items;
}
/** /**
* Get the metadata associated with this DOI. * Get the metadata associated with this DOI.

4
upei_roblib_ill.routing.yml

@ -10,7 +10,7 @@ roblib_ill.loan_form:
path: 'upei/roblib/ill/{parameters}' path: 'upei/roblib/ill/{parameters}'
defaults: defaults:
_form: '\Drupal\upei_roblib_ill\Form\RoblibIllLoanForm' _form: '\Drupal\upei_roblib_ill\Form\RoblibIllLoanForm'
_title: 'Roblib ILL Loan Form' _title: 'Interlibrary Loan Request'
parameters: '[a-zA-Z\s]+' parameters: '[a-zA-Z\s]+'
requirements: requirements:
_permission: 'access content' _permission: 'access content'
@ -19,6 +19,6 @@ roblib_ill.loan_form_finished:
path: 'upei/roblib/ill/finished' path: 'upei/roblib/ill/finished'
defaults: defaults:
_controller: '\Drupal\upei_roblib_ill\Controller\RoblibIllController::finished' _controller: '\Drupal\upei_roblib_ill\Controller\RoblibIllController::finished'
_title: 'Inter Library Loan Completed' _title: 'Interlibrary Loan Request Completed'
requirements: requirements:
_permission: 'access content' _permission: 'access content'
Loading…
Cancel
Save