diff --git a/includes/relais.inc b/includes/relais.inc index a88447a..800c3ed 100644 --- a/includes/relais.inc +++ b/includes/relais.inc @@ -123,7 +123,13 @@ function upei_roblib_ill_authenticate($barcode, $surname) { $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; } diff --git a/src/Form/RoblibIllLoanForm.php b/src/Form/RoblibIllLoanForm.php index 7d9e627..5809de1 100644 --- a/src/Form/RoblibIllLoanForm.php +++ b/src/Form/RoblibIllLoanForm.php @@ -48,8 +48,10 @@ class RoblibIllLoanForm extends FormBase { $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']); - $form_state->setErrorByName('campus_id', ''); // 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'); @@ -61,8 +63,13 @@ class RoblibIllLoanForm extends FormBase { } } $trigger = $form_state->getTriggeringElement(); - 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.')); + 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.')); + } } } @@ -148,7 +155,8 @@ class RoblibIllLoanForm extends FormBase { 'chapter' => t('Book Chapter'), 'article' => t('Journal Article'), ], - '#required' => TRUE, + '#default_value' => 'article', + '#required' => FALSE, ]; if (!empty($type)) { $form['Genre']['#default_value'] = $type;