Browse Source

better messageing when limits exceeded

d10-dev
Paul Pound 1 year ago
parent
commit
e011c7acf1
  1. 42
      reservation.inc

42
reservation.inc

@ -8,6 +8,7 @@ use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Datetime\DrupalDateTime; use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\Core\Link; use Drupal\Core\Link;
use Drupal\Core\Url; use Drupal\Core\Url;
use Drupal\Core\StringTranslation\TranslatableMarkup;
function reserve_form_reserve_reservation_form_alter(array &$form, FormStateInterface $form_state) { function reserve_form_reserve_reservation_form_alter(array &$form, FormStateInterface $form_state) {
// params either passed in on url - CREATE // params either passed in on url - CREATE
@ -79,33 +80,15 @@ function reserve_form_reserve_reservation_form_alter(array &$form, FormStateInte
$d = $yyyymmdd . ' 00:00:00'; $d = $yyyymmdd . ' 00:00:00';
if (reserve_daily_max_exceeded($yyyymmdd) && !$book_extended) { if (reserve_daily_max_exceeded($yyyymmdd) && !$book_extended) {
$form = array(); $daily_exceeded_message = t('You have exceeded the max number of daily bookings. Unable to add reservation.');
$form['message'] = [ reserve_set_modal_message($form, $daily_exceeded_message);
'#type' => 'markup',
'#weight' => -25,
'#markup' => '
<div class="messages__wrapper layout-container">
<div role="contentinfo" aria-label="Warning message" class="messages messages--warning">' .
t('You have exceeded the max number of daily bookings. Unable to add reservation.') .
'</div></div>',
];
return;
} }
$config = \Drupal::config('reserve.settings'); $config = \Drupal::config('reserve.settings');
$max_per_user = $config->get('reservations_per_user'); $max_per_user = $config->get('reservations_per_user');
if (count(reserve_user_reservations()) > $max_per_user if (count(reserve_user_reservations()) > $max_per_user
&& !$book_extended) { && !$book_extended) {
$form = array(); $max_reservations_exceeded_message = t('You have exceeded your max number of open bookings. Unable to add reservation.');
$form['message'] = [ reserve_set_modal_message($form, $max_reservations_exceeded_message);
'#type' => 'markup',
'#weight' => -25,
'#markup' => '
<div class="messages__wrapper layout-container">
<div role="contentinfo" aria-label="Warning message" class="messages messages--warning">' .
t('You have exceeded your max number of open bookings. Unable to add reservation.') .
'</div></div>',
];
return;
} }
} }
$entity = \Drupal::entityTypeManager()->getStorage($entity_type)->load($eid); $entity = \Drupal::entityTypeManager()->getStorage($entity_type)->load($eid);
@ -296,6 +279,21 @@ function reserve_return_to_home_page($form, FormStateInterface $form_state) {
$form_state->setRedirectUrl($url); $form_state->setRedirectUrl($url);
} }
function reserve_set_modal_message(&$form, $message) {
$form['message'] = [
'#type' => 'markup',
'#weight' => -25,
'#markup' => '
<div class="messages__wrapper layout-container">
<div role="contentinfo" aria-label="Warning message" class="messages messages--warning">' .
$message .
'</div></div>',
];
$form['message']['#errors'] = TRUE;
$form['actions']['submit']['#attributes']['disabled'] = 'disabled';
$form['actions']['submit']['#access'] = FALSE;
}
/** /**
* Custom submit handler for login form. * Custom submit handler for login form.
*/ */

Loading…
Cancel
Save