@ -10,19 +10,22 @@ use Drupal\Core\Form\FormStateInterface;
*
*
* @author ppound
* @author ppound
*/
*/
class RoblibIllLoanForm extends FormBase {
class RoblibIllLoanForm extends FormBase
{
/**
/**
* {@inheritdoc}
* {@inheritdoc}
*/
*/
public function getFormId() {
public function getFormId()
{
return 'roblib_ill_loan_form';
return 'roblib_ill_loan_form';
}
}
/**
/**
* {@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) {
if ($form_state->has('step') & & $form_state->get('step') == 2) {
return $this->ill_auth_form($form, $form_state);
return $this->ill_auth_form($form, $form_state);
}
}
@ -32,8 +35,10 @@ class RoblibIllLoanForm extends FormBase {
/**
/**
* {@inheritdoc}
* {@inheritdoc}
*/
*/
public function validateForm(array & $form, FormStateInterface $form_state) {
public function validateForm(array & $form, FormStateInterface $form_state)
{
\Drupal::moduleHandler()->loadInclude('upei_roblib_ill', 'inc', 'includes/relais');
\Drupal::moduleHandler()->loadInclude('upei_roblib_ill', 'inc', 'includes/relais');
\Drupal::moduleHandler()->loadInclude('upei_roblib_ill', 'inc', 'includes/utilities');
$values = $form_state->getValues();
$values = $form_state->getValues();
if ($form_state->get('step') == 2) {
if ($form_state->get('step') == 2) {
$is_valid_email = \Drupal::service('email.validator')->isValid($values['DeliveryAddress']);
$is_valid_email = \Drupal::service('email.validator')->isValid($values['DeliveryAddress']);
@ -46,22 +51,19 @@ class RoblibIllLoanForm extends FormBase {
$campus_id = $this->ill_form_message_id($values['campus_id']);
$campus_id = $this->ill_form_message_id($values['campus_id']);
$aid = upei_roblib_ill_authenticate($campus_id, $values['Surname']);
$auth = upei_roblib_ill_authenticate($campus_id, $values['Surname']);
if (is_array($aid) & & isset($aid['Problem']['Message'])) {
if (!$auth) {
if (!empty($aid['Problem']['HR_Message'])) {
$err = 'UserID or Surname do not match or not found.';
$form_state->setErrorByName('campus_id', $aid['Problem']['HR_Message']);
$form_state->setErrorByName('Surname', $err);
}
$form_state->setErrorByName('Surname', $aid['Problem']['Message']);
// 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.
// 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();
//$form_state->set('upei_roblib_ill_auth_form_storage') = $form_state->getValues();
\Drupal::moduleHandler()->loadInclude('upei_roblib_ill', 'inc', 'includes/db');
\Drupal::moduleHandler()->loadInclude('upei_roblib_ill', 'inc', 'includes/db');
$arr = upei_roblib_ill_build_relais_arr($form_state);
\Drupal::moduleHandler()->loadInclude('upei_roblib_ill', 'inc', 'includes/rapidill');
upei_roblib_ill_log_request($arr, $aid);
$handler = new \RapidIllRequestHandler();
}
$response = $handler->buildInsertRequest($form_state);
else {
upei_roblib_ill_log_request($response, $err);
$form_state->set('aid', $aid);
}
}
}
$trigger = $form_state->getTriggeringElement();
$trigger = $form_state->getTriggeringElement();
if ($trigger['#value'] != 'Lookup DOI' & & empty($form_state->get('step'))) {
if ($trigger['#value'] != 'Lookup DOI' & & empty($form_state->get('step'))) {
if (empty($form_state->getValue('Title'))) {
if (empty($form_state->getValue('Title'))) {
@ -72,6 +74,7 @@ class RoblibIllLoanForm extends FormBase {
}
}
}
}
}
}
}
/**
/**
* @param string $id
* @param string $id
@ -80,7 +83,8 @@ class RoblibIllLoanForm extends FormBase {
* @return mixed
* @return mixed
* the campus id with leading zeros and leading/trailing whitespace removed.
* 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
// Equinox made some changes to the database so we may not need to do
// this anymore.
// this anymore.
// Doing this simple change for now in case things need to be reverted.
// 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
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
* 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();
$trigger = $form_state->getTriggeringElement();
if ($trigger['#value'] != 'Lookup DOI') {
if ($trigger['#value'] != 'Lookup DOI') {
$form_state
$form_state
@ -108,7 +113,8 @@ class RoblibIllLoanForm extends FormBase {
/**
/**
* {@inheritdoc}
* {@inheritdoc}
*/
*/
public function submitForm(array & $form, FormStateInterface $form_state) {
public function submitForm(array & $form, FormStateInterface $form_state)
{
$trigger = $form_state->getTriggeringElement();
$trigger = $form_state->getTriggeringElement();
if ($trigger['#value'] == 'Lookup DOI') {
if ($trigger['#value'] == 'Lookup DOI') {
//Do nothing as this was just a DOI Lookup
//Do nothing as this was just a DOI Lookup
@ -126,7 +132,8 @@ class RoblibIllLoanForm extends FormBase {
$form_state->setRedirect('roblib_ill.loan_form_finished', $parameters);
$form_state->setRedirect('roblib_ill.loan_form_finished', $parameters);
}
}
public function doiCallback(array & $form, FormStateInterface $form_state) {
public function doiCallback(array & $form, FormStateInterface $form_state)
{
\Drupal::moduleHandler()->loadInclude('upei_roblib_ill', 'inc', 'includes/doi');
\Drupal::moduleHandler()->loadInclude('upei_roblib_ill', 'inc', 'includes/doi');
$doi = $form_state->getValue('doi');
$doi = $form_state->getValue('doi');
$form = upei_roblib_ill_doi_get_data($form, $doi);
$form = upei_roblib_ill_doi_get_data($form, $doi);
@ -144,7 +151,8 @@ class RoblibIllLoanForm extends FormBase {
* @return array
* @return array
* An array representing the bibliographic form.
* An array representing the bibliographic form.
*/
*/
function ill_request_form($form, & $form_state) {
function ill_request_form($form, & $form_state)
{
\Drupal::moduleHandler()->loadInclude('upei_roblib_ill', 'inc', 'includes/utilities');
\Drupal::moduleHandler()->loadInclude('upei_roblib_ill', 'inc', 'includes/utilities');
$config = \Drupal::config('upei_roblib_ill.settings');
$config = \Drupal::config('upei_roblib_ill.settings');
$form['#prefix'] = '< div id = "upei-roblib-ill-request-form" > ';
$form['#prefix'] = '< div id = "upei-roblib-ill-request-form" > ';
@ -358,7 +366,8 @@ class RoblibIllLoanForm extends FormBase {
* @return array
* @return array
* An array representing the bibliographic form.
* An array representing the bibliographic form.
*/
*/
function ill_auth_form($form, & $form_state) {
function ill_auth_form($form, & $form_state)
{
\Drupal::moduleHandler()->loadInclude('upei_roblib_ill', 'inc', 'includes/utilities');
\Drupal::moduleHandler()->loadInclude('upei_roblib_ill', 'inc', 'includes/utilities');
$form['#prefix'] = upei_roblib_format_biblio_info($form_state);
$form['#prefix'] = upei_roblib_format_biblio_info($form_state);
$form['#suffix'] = '< div class = "roblib-required" > * = Required Field< / div >
$form['#suffix'] = '< div class = "roblib-required" > * = Required Field< / div >