Browse Source

better messageing when limits exceeded

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

54
reservation.inc

@ -8,6 +8,7 @@ use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\Core\Link;
use Drupal\Core\Url;
use Drupal\Core\StringTranslation\TranslatableMarkup;
function reserve_form_reserve_reservation_form_alter(array &$form, FormStateInterface $form_state) {
// params either passed in on url - CREATE
@ -18,7 +19,7 @@ function reserve_form_reserve_reservation_form_alter(array &$form, FormStateInte
// Retrieve an array which contains the path pieces.
$current_path = \Drupal::service('path.current')->getPath();
$path_args = explode('/', $current_path);
// for case of std reservation add form - this should likely be blocked; but leave for development
if (count($path_args) <= 3) return;
@ -30,7 +31,7 @@ function reserve_form_reserve_reservation_form_alter(array &$form, FormStateInte
};
$user = \Drupal::currentUser();
$user_roles = $user->getRoles();
//Allow users with the 'add reservation extended' to book unlimited number
//Allow users with the 'add reservation extended' to book unlimited number
//of reservations.'
$book_extended = FALSE;
//Allow administrators to create as many reservations as needed.
@ -79,33 +80,15 @@ function reserve_form_reserve_reservation_form_alter(array &$form, FormStateInte
$d = $yyyymmdd . ' 00:00:00';
if (reserve_daily_max_exceeded($yyyymmdd) && !$book_extended) {
$form = array();
$form['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;
$daily_exceeded_message = t('You have exceeded the max number of daily bookings. Unable to add reservation.');
reserve_set_modal_message($form, $daily_exceeded_message);
}
$config = \Drupal::config('reserve.settings');
$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) {
$form = array();
$form['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;
$max_reservations_exceeded_message = t('You have exceeded your max number of open bookings. Unable to add reservation.');
reserve_set_modal_message($form, $max_reservations_exceeded_message);
}
}
$entity = \Drupal::entityTypeManager()->getStorage($entity_type)->load($eid);
@ -175,7 +158,7 @@ function reserve_form_reserve_reservation_form_alter(array &$form, FormStateInte
if (isset($_GET['single'])) {
$series_link = Link::fromTextAndUrl(t('Click here'), Url::fromUri('internal:/reserve_reservation/' . $rid . '/edit', $modal))->toString();
$message = t('NOTE: you are editing a SINGLE day in a SERIES of reservations. Any changes made here will impact only the reservation
$message = t('NOTE: you are editing a SINGLE day in a SERIES of reservations. Any changes made here will impact only the reservation
for this day. %link if you want to edit the entire series.', array('%link' => $series_link));
// relabel Delete
$form['actions']['delete']['#title'] = t('Cancel Reservation for This Day');
@ -183,7 +166,7 @@ function reserve_form_reserve_reservation_form_alter(array &$form, FormStateInte
else {
$single_link = Link::fromTextAndUrl('Click here', Url::fromUri('internal:/reserve_reservation/' . $rid . '/edit',
['query' => ['single' => 1]] + $modal))->toString();
$message = t('NOTE: you are editing a SERIES of reservations. Any changes made here will impact all reservations in this
$message = t('NOTE: you are editing a SERIES of reservations. Any changes made here will impact all reservations in this
series. %link if you only want to edit this specific day in this series.', array('%link' => $single_link));
// remove single node delete and add Delete Series button
//unset($form['actions']['delete']);
@ -296,6 +279,21 @@ function reserve_return_to_home_page($form, FormStateInterface $form_state) {
$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.
*/
@ -306,4 +304,4 @@ function reserve_return_to_reservations_page($form, FormStateInterface $form_sta
'selected_day' => $form_state->getValue('day'),
];
$form_state->setRedirect('reserve.calendar', $arguments);
}
}

Loading…
Cancel
Save