|
|
@ -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 |
|
|
@ -18,7 +19,7 @@ function reserve_form_reserve_reservation_form_alter(array &$form, FormStateInte |
|
|
|
// Retrieve an array which contains the path pieces. |
|
|
|
// Retrieve an array which contains the path pieces. |
|
|
|
$current_path = \Drupal::service('path.current')->getPath(); |
|
|
|
$current_path = \Drupal::service('path.current')->getPath(); |
|
|
|
$path_args = explode('/', $current_path); |
|
|
|
$path_args = explode('/', $current_path); |
|
|
|
|
|
|
|
|
|
|
|
// for case of std reservation add form - this should likely be blocked; but leave for development |
|
|
|
// for case of std reservation add form - this should likely be blocked; but leave for development |
|
|
|
if (count($path_args) <= 3) return; |
|
|
|
if (count($path_args) <= 3) return; |
|
|
|
|
|
|
|
|
|
|
@ -30,7 +31,7 @@ function reserve_form_reserve_reservation_form_alter(array &$form, FormStateInte |
|
|
|
}; |
|
|
|
}; |
|
|
|
$user = \Drupal::currentUser(); |
|
|
|
$user = \Drupal::currentUser(); |
|
|
|
$user_roles = $user->getRoles(); |
|
|
|
$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.' |
|
|
|
//of reservations.' |
|
|
|
$book_extended = FALSE; |
|
|
|
$book_extended = FALSE; |
|
|
|
//Allow administrators to create as many reservations as needed. |
|
|
|
//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'; |
|
|
|
$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); |
|
|
@ -175,7 +158,7 @@ function reserve_form_reserve_reservation_form_alter(array &$form, FormStateInte |
|
|
|
|
|
|
|
|
|
|
|
if (isset($_GET['single'])) { |
|
|
|
if (isset($_GET['single'])) { |
|
|
|
$series_link = Link::fromTextAndUrl(t('Click here'), Url::fromUri('internal:/reserve_reservation/' . $rid . '/edit', $modal))->toString(); |
|
|
|
$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)); |
|
|
|
for this day. %link if you want to edit the entire series.', array('%link' => $series_link)); |
|
|
|
// relabel Delete |
|
|
|
// relabel Delete |
|
|
|
$form['actions']['delete']['#title'] = t('Cancel Reservation for This Day'); |
|
|
|
$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 { |
|
|
|
else { |
|
|
|
$single_link = Link::fromTextAndUrl('Click here', Url::fromUri('internal:/reserve_reservation/' . $rid . '/edit', |
|
|
|
$single_link = Link::fromTextAndUrl('Click here', Url::fromUri('internal:/reserve_reservation/' . $rid . '/edit', |
|
|
|
['query' => ['single' => 1]] + $modal))->toString(); |
|
|
|
['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)); |
|
|
|
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 |
|
|
|
// remove single node delete and add Delete Series button |
|
|
|
//unset($form['actions']['delete']); |
|
|
|
//unset($form['actions']['delete']); |
|
|
@ -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. |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -306,4 +304,4 @@ function reserve_return_to_reservations_page($form, FormStateInterface $form_sta |
|
|
|
'selected_day' => $form_state->getValue('day'), |
|
|
|
'selected_day' => $form_state->getValue('day'), |
|
|
|
]; |
|
|
|
]; |
|
|
|
$form_state->setRedirect('reserve.calendar', $arguments); |
|
|
|
$form_state->setRedirect('reserve.calendar', $arguments); |
|
|
|
} |
|
|
|
} |
|
|
|