diff --git a/reservation.inc b/reservation.inc index f8e473b..2257305 100644 --- a/reservation.inc +++ b/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' => ' -
-
', - ]; - 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' => ' -
-
', - ]; - 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' => ' +
+
', + ]; + $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); -} \ No newline at end of file +}