diff --git a/includes/db.inc b/includes/db.inc index ad54e7e..3071dde 100644 --- a/includes/db.inc +++ b/includes/db.inc @@ -44,6 +44,9 @@ function upei_roblib_ill_log_request($request, $response) { 'relais_message' => substr($relais_message, 0, 254), ])->execute(); } catch (Exception $e) { - watchdog_exception('upei_roblib_ill', $e, 'Error logging ILL request.', NULL, WATCHDOG_ERROR); + \Drupal::logger('upei_roblib_ill')->error('Error logging ILL request @msg', + array( + '@msg' => $e->getMessage(), + )); } } diff --git a/includes/doi.inc b/includes/doi.inc index 2a765cd..fcbb983 100644 --- a/includes/doi.inc +++ b/includes/doi.inc @@ -38,7 +38,7 @@ function upei_roblib_ill_doi_get_data($form, $doi) { ) { $crossref_xml = new DOMDocument('1.0'); if (!$crossref_xml->loadXML($response_data)) { - drupal_set_message(t('Error parseing DOI response, @msg')); + \Drupal::messenger()->addMessage(t('Error parseing DOI response')); return $form; } else { @@ -46,7 +46,7 @@ function upei_roblib_ill_doi_get_data($form, $doi) { } } else { - drupal_set_message(t('Error retrieve data using DOI of @doi', ['@doi' => $doi]), 'error'); + \Drupal::messenger()->addmessage(t('Error retrieve data using DOI of @doi', ['@doi' => $doi]), 'error'); return $form; } } diff --git a/includes/form.inc b/includes/form.inc deleted file mode 100644 index 6bba836..0000000 --- a/includes/form.inc +++ /dev/null @@ -1,527 +0,0 @@ - [ - 'message' => $response['ConfirmMessage'], - 'email' => $form_state['values']['DeliveryAddress'], - 'error' => $error, - ], - ], - ]; - } - -} - -/** - * After submitting an ILL request patrons will be redirected to the content - * returned from this function. - * - * @return string - * a string of HTML to display including the results of the ILL request and - * some boilerplate text. - */ -function upei_roblib_ill_form_redirect() { - $contact_email = variable_get('upei_roblib_ill_contact_email', 'ill@upei.ca'); - $contact_phone_number = variable_get('upei_roblib_ill_contact_phone', '902-566-0445'); - $librarian_link = l(t('subject-specific'), 'http://library.upei.ca/librarians', ['html' => TRUE]); - $help_message = t("We can help! Please contact your !librarian_link librarian if you'd like help finding more resources relating to your topic.", - ['!librarian_link' => $librarian_link]); - $standard_message = t("To contact the department about this request, you can send a message to @email or -call @phone.", ['@phone' => $contact_phone_number, '@email' => $contact_email]); - if (isset($_GET['error']) && $_GET['error'] === 'FALSE') { - $standard_message = t("A message including the Request ID has been sent to @email.", [ - '@email' => $_GET['email'], - ]) . $standard_message; - } - - $output = [ - '#prefix' => '
', - '#suffix' => '
', - 'dynamic_message' => [ - '#type' => 'markup', - '#markup' => $_GET['message'], - '#prefix' => '
', - '#suffix' => '
', - ], - 'standard_message' => [ - '#type' => 'markup', - '#markup' => $standard_message, - '#prefix' => '
', - '#suffix' => '
', - ], - 'help_message' => [ - '#type' => 'markup', - '#markup' => $help_message, - '#allowed_tags' => ['a', 'source'], - '#prefix' => '
', - '#suffix' => '
', - ], - ]; - return drupal_render($output); -} - - -/** - * 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 upei_roblib_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'] = '
* = Required Field
-
Protection of Privacy - 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.
'; - $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; - -} - - -/** - * 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 upei_roblib_ill_request_form($form, &$form_state) { - module_load_include('inc', 'upei_roblib_ill', 'includes/utilities'); - $header_message = variable_get('upei_roblib_ill_header_message', ''); - $emergency_message = ''; - if(!empty($header_message)) { - $emergency_message = '
'; - $emergency_message .= $header_message; - $emergency_message .= '
'; - } - $form['#prefix'] = $emergency_message . '
'; - $form['#suffix'] = '
* = Required Field
'; - $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) more info"), - '#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['next'] = [ - '#type' => 'submit', - '#value' => t('Next'), - ]; - return $form; - -} diff --git a/includes/relais.inc b/includes/relais.inc index 8490125..a88447a 100644 --- a/includes/relais.inc +++ b/includes/relais.inc @@ -4,6 +4,9 @@ * 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' : @@ -38,8 +41,8 @@ function upei_roblib_ill_add_request($form_state, $aid) { 'headers' => ['Content-Type' => 'application/json'], ]; if (!isset($aid) || is_array($aid)) { - //upei_roblib_ill_log_request($relais_arr, $aid); - drupal_set_message(t('Error retrieving authentication token, @message', ['@message' => $aid['Problem']['Message']]), 'error'); + 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); @@ -51,10 +54,7 @@ function upei_roblib_ill_add_request($form_state, $aid) { return ['ConfirmMessage' => 'Error Communicating with Relais, ' . $e->getMessage()]; } $response_arr = json_decode($response->getBody(),TRUE); - // for testing $response_arr = array('RequestNumber' => '1234', 'ConfirmMessage' => 'Your request has been submitted'); - //$status_code = $response->getStatusCode(); - module_load_include('inc', 'upei_roblib_ill', 'includes/db'); if (!isset($response_arr)) { return ['ConfirmMessage' => 'Error Communicating with Relais, no data returned.']; } @@ -127,11 +127,6 @@ function upei_roblib_ill_authenticate($barcode, $surname) { return $response_data; } - /*$result = drupal_http_request($url, $options); - if ($result->code != '200') { - $response_data['Problem']['Message'] = $result->error; - return $response_data; - }*/ $response_data = json_decode($response->getBody(),TRUE); $status_code = $response->getStatusCode(); if ($status_code == '200') { @@ -146,17 +141,20 @@ function upei_roblib_ill_authenticate($barcode, $surname) { } function upei_roblib_ill_build_err_msg($msg_from_server) { - $campus_id = l(t('Campus ID'), 'http://www.upei.ca/vpaf/campuscard'); - $ill_email = l(t('ill@upei.ca'), 'mailto:ill@upei.ca'); - $phone = l(t('902-566-0583'), 'tel:902-566-0353'); + $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.
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.
@msg_from_server', +. (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.
@msg_from_server', [ - '!campus_id' => $campus_id, - '!ill_email' => $ill_email, - '!phone' => $phone, + '@campus_id' => $campus_id->toString(), + '@ill_email' => $ill_email->toString(), + '@phone' => $phone->toString(), '@msg_from_server' => $server_response, ]); } diff --git a/src/Controller/RoblibIllController.php b/src/Controller/RoblibIllController.php index 6957325..536fa35 100644 --- a/src/Controller/RoblibIllController.php +++ b/src/Controller/RoblibIllController.php @@ -22,8 +22,8 @@ class RoblibIllController extends ControllerBase { $contact_email = $config->get('ill_contact_email'); $contact_phone_number = $config->get('ill_contact_phone'); $librarian_link = Link::fromTextAndUrl($this->t('subject-specific'), Url::fromUri('http://library.upei.ca/librarians'))->toString(); - $help_message = $this->t("We can help! Please contact your !librarian_link librarian if you'd like help finding more resources relating to your topic.", - ['!librarian_link' => $librarian_link]); + $help_message = $this->t("We can help! Please contact your @librarian_link librarian if you'd like help finding more resources relating to your topic.", + ['@librarian_link' => $librarian_link]); $standard_message = t("To contact the department about this request, you can send a message to @email or call @phone.", ['@phone' => $contact_phone_number, '@email' => $contact_email]); if (isset($_GET['error']) && $_GET['error'] === 'FALSE') { diff --git a/src/Form/RoblibIllLoanForm.php b/src/Form/RoblibIllLoanForm.php index 6604d1b..819463d 100644 --- a/src/Form/RoblibIllLoanForm.php +++ b/src/Form/RoblibIllLoanForm.php @@ -61,7 +61,7 @@ class RoblibIllLoanForm extends FormBase { } } $trigger = $form_state->getTriggeringElement(); - if (empty($form_state->get('step')) && $trigger['#value'] !== 'Lookup DOI' && empty($form_state->getValue('Title'))) { + if (empty($form_state->get('step')) && $trigger['#value'] != 'Lookup DOI' && empty($form_state->getValue('Title'))) { $form_state->setErrorByName('Title', t('Journal/Book Title is required.')); } } @@ -98,20 +98,21 @@ class RoblibIllLoanForm extends FormBase { * {@inheritdoc} */ 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 + $form_state->setRebuild(TRUE); + return; + } //process the form $response = upei_roblib_ill_add_request($form_state, $form_state->get('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, - ], - ], - ]; */ + $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) { @@ -331,7 +332,6 @@ class RoblibIllLoanForm extends FormBase { '#button_type' => 'primary', '#value' => $this->t('Next'), '#submit' => ['::submitStepOne'], - //'#validate' => ['::validatePageOne'], ]; return $form; }