@ -8,7 +8,6 @@ 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
@ -19,7 +18,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;
@ -31,7 +30,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.
@ -80,15 +79,33 @@ function reserve_form_reserve_reservation_form_alter(array &$form, FormStateInte
$d = $yyyymmdd . ' 00:00:00';
if (reserve_daily_max_exceeded($yyyymmdd) & & !$book_extended) {
$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);
$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;
}
$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) {
$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);
$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;
}
}
$entity = \Drupal::entityTypeManager()->getStorage($entity_type)->load($eid);
@ -100,9 +117,9 @@ function reserve_form_reserve_reservation_form_alter(array &$form, FormStateInte
// set default Group Name as name of current user
$form['name']['widget'][0]['value']['#required'] = TRUE;
/* $form['name']['widget'][0]['value']['#default_value'] = $form['name']['widget'][0]['value']['#default_value'] ?
$form['name']['widget'][0]['value']['#default_value'] = $form['name']['widget'][0]['value']['#default_value'] ?
$form['name']['widget'][0]['value']['#default_value'] :
\Drupal::currentUser()->getDisplayName();*/
\Drupal::currentUser()->getDisplayName();
// set values taken from URL
$form['reservation_date']['widget'][0]['value']['#default_value'] = DrupalDateTime::createFromTimestamp(strtotime($yyyymmdd));
@ -158,7 +175,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');
@ -166,7 +183,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']);
@ -279,21 +296,6 @@ 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.
*/
@ -304,4 +306,4 @@ function reserve_return_to_reservations_page($form, FormStateInterface $form_sta
'selected_day' => $form_state->getValue('day'),
];
$form_state->setRedirect('reserve.calendar', $arguments);
}
}