Compare commits

..

No commits in common. 'd10-dev' and '4.0.x-roblib' have entirely different histories.

  1. 58
      reservation.inc
  2. 20
      reserve.inc
  3. 2
      reserve.info.yml
  4. 6
      reserve.module
  5. 18
      reserve.series.inc
  6. 7
      src/Controller/CalendarController.php
  7. 1
      src/Form/ReserveDailyHoursForm.php
  8. 5
      src/Form/ReserveDefaultHoursForm.php
  9. 6
      src/Form/ReserveSettingsForm.php
  10. 3
      src/Plugin/Field/FieldFormatter/ReserveCategoryFormatter.php
  11. 9
      src/Plugin/Field/FieldType/ReserveCategory.php
  12. 8
      src/Plugin/Field/FieldWidget/ReserveCategorySelect.php
  13. 46
      src/Tests/LoadTest.php

58
reservation.inc

@ -8,7 +8,6 @@ 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
@ -19,7 +18,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;
@ -31,7 +30,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.
@ -80,15 +79,33 @@ 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) {
$daily_exceeded_message = t('You have exceeded the max number of daily bookings. Unable to add reservation.'); $form = array();
reserve_set_modal_message($form, $daily_exceeded_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">' .
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) {
$max_reservations_exceeded_message = t('You have exceeded your max number of open bookings. Unable to add reservation.'); $form = array();
reserve_set_modal_message($form, $max_reservations_exceeded_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">' .
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);
@ -100,9 +117,9 @@ function reserve_form_reserve_reservation_form_alter(array &$form, FormStateInte
// set default Group Name as name of current user // set default Group Name as name of current user
$form['name']['widget'][0]['value']['#required'] = TRUE; $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'] : $form['name']['widget'][0]['value']['#default_value'] :
\Drupal::currentUser()->getDisplayName();*/ \Drupal::currentUser()->getDisplayName();
// set values taken from URL // set values taken from URL
$form['reservation_date']['widget'][0]['value']['#default_value'] = DrupalDateTime::createFromTimestamp(strtotime($yyyymmdd)); $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'])) { 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');
@ -166,7 +183,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']);
@ -279,21 +296,6 @@ 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.
*/ */
@ -304,4 +306,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);
} }

20
reserve.inc

@ -1,5 +1,4 @@
<?php <?php
use Drupal\field\Entity\FieldConfig;
/** /**
* @file * @file
* Classes and general Room Reservations helper functions. * Classes and general Room Reservations helper functions.
@ -22,13 +21,13 @@ function reserve_categories($ebundle = null) {
$entity_type = ebundle_split($ebundle, 'type'); $entity_type = ebundle_split($ebundle, 'type');
$bundle = ebundle_split($ebundle, 'bundle'); $bundle = ebundle_split($ebundle, 'bundle');
$field = reserve_category_fields($ebundle); $field = reserve_category_fields($ebundle);
$fconfig = FieldConfig::loadByName($entity_type, $bundle, $field)->getSettings(); $fconfig = \Drupal\field\Entity\FieldConfig::loadByName($entity_type, $bundle, $field)->getSettings();
$ids = array_filter($fconfig['categories']); $ids = array_filter($fconfig['categories']);
} }
else { else {
$query = \Drupal::service('entity_type.manager') $query = \Drupal::service('entity_type.manager')
->getStorage('reserve_category')->getQuery(); ->getStorage('reserve_category')->getQuery();
$ids = $query->condition('status', TRUE)->accessCheck(FALSE)->execute(); $ids = $query->condition('status', TRUE)->execute();
} }
$cats = \Drupal::entityTypeManager()->getStorage('reserve_category')->loadMultiple($ids); $cats = \Drupal::entityTypeManager()->getStorage('reserve_category')->loadMultiple($ids);
@ -67,7 +66,7 @@ function reserve_entities($ebundle) {
} }
//->sort('reservations_display_order', 'ASC') //->sort('reservations_display_order', 'ASC')
$ids = $query->accessCheck(FALSE)->execute(); $ids = $query->execute();
$entities = \Drupal::entityTypeManager()->getStorage($entity_type)->loadMultiple($ids); $entities = \Drupal::entityTypeManager()->getStorage($entity_type)->loadMultiple($ids);
@ -354,8 +353,8 @@ function reserve_facility_hours($date, $reset = FALSE) {
$year = substr($month, 0, 4); $year = substr($month, 0, 4);
$mo_hours = reserve_default_monthly_hours($year, $m); $mo_hours = reserve_default_monthly_hours($year, $m);
} }
$start = ($day - 1) * 5; $start = ($day - 1) * 5;
$first_shift_open = $mo_hours[$start + 1]; $first_shift_open = $mo_hours[$start + 1];
$first_shift_close = $mo_hours[$start + 2]; $first_shift_close = $mo_hours[$start + 2];
$second_shift_open = $mo_hours[$start + 3]; $second_shift_open = $mo_hours[$start + 3];
@ -697,7 +696,7 @@ function reserve_start_conflicts($room, $yyyy_mmdd, $time) {
) )
"; ";
$conflicts_found = FALSE; $conflicts_found = FALSE;
$conflicts_found = \Drupal::database()->query($sql, array( $conflicts_found = db_query($sql, array(
':room' => $room, ':room' => $room,
':date0' => $search_items[0]['date'], ':time0' => $search_items[0]['start_time'], ':length0' => $search_items[0]['length'], ':date0' => $search_items[0]['date'], ':time0' => $search_items[0]['start_time'], ':length0' => $search_items[0]['length'],
':date1' => $search_items[1]['date'], ':time1' => $search_items[1]['start_time'], ':length1' => $search_items[1]['length'], ':date1' => $search_items[1]['date'], ':time1' => $search_items[1]['start_time'], ':length1' => $search_items[1]['length'],
@ -706,7 +705,8 @@ function reserve_start_conflicts($room, $yyyy_mmdd, $time) {
':date4' => $search_items[4]['date'], ':time4' => $search_items[4]['start_time'], ':length4' => $search_items[4]['length'], ':date4' => $search_items[4]['date'], ':time4' => $search_items[4]['start_time'], ':length4' => $search_items[4]['length'],
':date5' => $search_items[5]['date'], ':time5' => $search_items[5]['start_time'], ':length5' => $search_items[5]['length'], ':date5' => $search_items[5]['date'], ':time5' => $search_items[5]['start_time'], ':length5' => $search_items[5]['length'],
':date6' => $search_items[6]['date'], ':time6' => $search_items[6]['start_time'], ':length6' => $search_items[6]['length'], ':date6' => $search_items[6]['date'], ':time6' => $search_items[6]['start_time'], ':length6' => $search_items[6]['length'],
':date7' => $search_items[7]['date'], ':time7' => $search_items[7]['start_time'], ':length7' => $search_items[7]['length']))->rowCount(); ':date7' => $search_items[7]['date'], ':time7' => $search_items[7]['start_time'], ':length7' => $search_items[7]['length'])
)->rowCount();
return $conflicts_found; return $conflicts_found;
} }
@ -923,7 +923,7 @@ function reserve_valid_lengths($rid, $ebundle, $yyyy_mmdd, $time, $id = NULL, $a
* FALSE - the maximum has not been exceeded. * FALSE - the maximum has not been exceeded.
*/ */
function reserve_daily_max_exceeded($yyyy_mmdd) { function reserve_daily_max_exceeded($yyyy_mmdd) {
$user = \Drupal::currentUser(); $user = \Drupal::currentUser();
$config = \Drupal::config('reserve.settings'); $config = \Drupal::config('reserve.settings');
$max = $config->get('reservations_per_day'); $max = $config->get('reservations_per_day');
if (!$max) { if (!$max) {
@ -933,7 +933,6 @@ function reserve_daily_max_exceeded($yyyy_mmdd) {
if ($user->id()) { if ($user->id()) {
$ids = \Drupal::service('entity_type.manager') $ids = \Drupal::service('entity_type.manager')
->getStorage('reserve_reservation')->getQuery() ->getStorage('reserve_reservation')->getQuery()
->accessCheck(FALSE)
->condition('user_id', $user->id()) ->condition('user_id', $user->id())
->condition('reservation_date', $yyyy_mmdd . '%', 'like') ->condition('reservation_date', $yyyy_mmdd . '%', 'like')
->execute(); ->execute();
@ -967,7 +966,6 @@ function reserve_user_reservations() {
$latest_date = date('Y-m-d', strtotime("now +13 days")); $latest_date = date('Y-m-d', strtotime("now +13 days"));
$ids = \Drupal::service('entity_type.manager') $ids = \Drupal::service('entity_type.manager')
->getStorage('reserve_reservation')->getQuery() ->getStorage('reserve_reservation')->getQuery()
->accessCheck(TRUE)
->condition('user_id', $user->id()) ->condition('user_id', $user->id())
->condition('reservation_date', $earliest_date, '>=') ->condition('reservation_date', $earliest_date, '>=')
->condition('reservation_date', $latest_date, '<=') ->condition('reservation_date', $latest_date, '<=')

2
reserve.info.yml

@ -2,7 +2,7 @@ name: Reserve
type: module type: module
description: Reservation system. description: Reservation system.
package: Reserve package: Reserve
core_version_requirement: ^9.5 || ^10 core_version_requirement: ^8 || ^9
dependencies: dependencies:
- drupal:views - drupal:views
- drupal:options - drupal:options

6
reserve.module

@ -16,9 +16,9 @@ use Drupal\Core\Form\FormStateInterface;
define ('RESERVE_SAVE_CONFIRMATION_MSG', t('Configuration settings have been saved')); define ('RESERVE_SAVE_CONFIRMATION_MSG', t('Configuration settings have been saved'));
define ('RESERVE_RESET_CONFIRMATION_MSG', t('Configuration settings have been reset to their default values')); define ('RESERVE_RESET_CONFIRMATION_MSG', t('Configuration settings have been reset to their default values'));
include(dirname(__FILE__) . '/reserve.inc'); module_load_include('inc', 'reserve', 'reserve');
include(dirname(__FILE__) . '/reserve.series.inc'); module_load_include('inc', 'reserve', 'reserve.series');
include(dirname(__FILE__) . '/reservation.inc'); module_load_include('inc', 'reserve', 'reservation');
$GLOBALS['debug'] = false; $GLOBALS['debug'] = false;

18
reserve.series.inc

@ -1,4 +1,4 @@
<?php <?php
/** /**
* Reservation CRUD for supporting Series * Reservation CRUD for supporting Series
@ -39,7 +39,7 @@ function reserve_reserve_reservation_insert($entity) {
$ebundle = $rtype . '.' . \Drupal::entityTypeManager() $ebundle = $rtype . '.' . \Drupal::entityTypeManager()
->getStorage($rtype)->load($rid)->bundle(); ->getStorage($rtype)->load($rid)->bundle();
$day = date('l', strtotime($start)); $day = date('l', strtotime($start));
$msg = ''; $msg = '';
switch ($repeat_type) { switch ($repeat_type) {
// every day until.... // every day until....
@ -48,7 +48,7 @@ function reserve_reserve_reservation_insert($entity) {
$back = '-1 day'; $back = '-1 day';
$msg = t('You have booked every day from %start until %end', array('%start' => $start_yyyy_mm_dd, '%end' => $end)); $msg = t('You have booked every day from %start until %end', array('%start' => $start_yyyy_mm_dd, '%end' => $end));
break; break;
// this day of the week until.. // this day of the week until..
case 2: case 2:
$skip = '+7 day'; $skip = '+7 day';
@ -70,7 +70,7 @@ function reserve_reserve_reservation_insert($entity) {
$failed = array(); $failed = array();
while (strtotime($date) <= strtotime($back, strtotime($end))) { while (strtotime($date) <= strtotime($back, strtotime($end))) {
$date = date('Y-m-d', strtotime($skip, strtotime($date))); $date = date('Y-m-d', strtotime($skip, strtotime($date)));
// must check to see if next booking is available // must check to see if next booking is available
// the first one we don't check as we could not have picked it if it wasn't // the first one we don't check as we could not have picked it if it wasn't
if (reserve_is_slot_free($rid, $ebundle, $date, $time, $length)) { if (reserve_is_slot_free($rid, $ebundle, $date, $time, $length)) {
@ -111,12 +111,12 @@ function reserve_reserve_reservation_update($entity) {
} }
$sid = $entity->reservation_series_id->getString(); $sid = $entity->reservation_series_id->getString();
// if not part of a Series or special single only url -> do nothing // if not part of a Series or special single only url -> do nothing
if (!$sid || isset($_GET['single'])) { if (!$sid || isset($_GET['single'])) {
return; return;
} }
// reservation details // reservation details
$start = $entity->reservation_date->getString(); $start = $entity->reservation_date->getString();
$time = $entity->reservation_time->getString(); $time = $entity->reservation_time->getString();
@ -130,7 +130,6 @@ function reserve_reserve_reservation_update($entity) {
// grab all reservations in this series except the one being submitted // grab all reservations in this series except the one being submitted
$ids = \Drupal::service('entity_type.manager') $ids = \Drupal::service('entity_type.manager')
->getStorage('reserve_reservation')->getQuery() ->getStorage('reserve_reservation')->getQuery()
->accessCheck(TRUE)
->condition('status', TRUE) ->condition('status', TRUE)
->condition('reservation_series_id', $sid) ->condition('reservation_series_id', $sid)
->condition('id', $entity->id(), '!=') ->condition('id', $entity->id(), '!=')
@ -163,7 +162,7 @@ function reserve_reserve_reservation_update($entity) {
if (count($failed)) { if (count($failed)) {
$dates = Markup::create('<br>' . implode('<br>', $failed)); $dates = Markup::create('<br>' . implode('<br>', $failed));
\Drupal::messenger()->addStatus(t('NOTE: The following dates did not have their length changed due to scheduling conflicts: %dates', array('%dates' => $dates))); \Drupal::messenger()->addStatus(t('NOTE: The following dates did not have their length changed due to scheduling conflicts: %dates', array('%dates' => $dates)));
} }
} }
/** /**
@ -184,7 +183,6 @@ function _reserve_series_delete($entity) {
// grab all reservations in this series // grab all reservations in this series
$ids = \Drupal::service('entity_type.manager') $ids = \Drupal::service('entity_type.manager')
->getStorage('reserve_reservation')->getQuery() ->getStorage('reserve_reservation')->getQuery()
->accessCheck(TRUE)
->condition('reservation_series_id', $sid) ->condition('reservation_series_id', $sid)
->execute(); ->execute();
$results = \Drupal::entityTypeManager()->getStorage('reserve_reservation')->loadMultiple($ids); $results = \Drupal::entityTypeManager()->getStorage('reserve_reservation')->loadMultiple($ids);
@ -192,5 +190,5 @@ function _reserve_series_delete($entity) {
$result->delete(); $result->delete();
} }
$title = $entity->get('name')->getString(); $title = $entity->get('name')->getString();
\Drupal::messenger()->addStatus(t('The reservation series @title was deleted.', array('@title' => $title))); \Drupal::messenger()->addStatus(t('The reservation series @title was deleted.', array('@title' => $title)));
} }

7
src/Controller/CalendarController.php

@ -1,7 +1,6 @@
<?php <?php
namespace Drupal\reserve\Controller; namespace Drupal\reserve\Controller;
use Drupal\field\Entity\FieldConfig;
use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Drupal\Core\Link; use Drupal\Core\Link;
@ -335,7 +334,7 @@ class CalendarController extends ControllerBase {
$extended = \Drupal::currentUser()->hasPermission('add reservations extended'); $extended = \Drupal::currentUser()->hasPermission('add reservations extended');
$config = \Drupal::config('reserve.settings'); $config = \Drupal::config('reserve.settings');
$category_field = reserve_category_fields($ebundle); $category_field = reserve_category_fields($ebundle);
$clearimg = '<img src="' . base_path() . \Drupal::service('extension.list.module')->getPath('reserve') . '/images/clear.png" />'; $clearimg = '<img src="' . base_path() . drupal_get_path('module', 'reserve') . '/images/clear.png" />';
$modal = ['attributes' => [ $modal = ['attributes' => [
'class' => ['use-ajax'], 'class' => ['use-ajax'],
'data-dialog-type' => 'modal', 'data-dialog-type' => 'modal',
@ -372,12 +371,12 @@ class CalendarController extends ControllerBase {
$variables['#calendar-text'] = $config->get('calendar_text'); $variables['#calendar-text'] = $config->get('calendar_text');
$variables['#reserve_room_instructions_text'] = $config->get('reserve_instructions') ? $config->get('reserve_instructions') : $variables['#reserve_room_instructions_text'] = $config->get('reserve_instructions') ? $config->get('reserve_instructions') :
t('To make a reservation, click on the desired time/day in the calendar below. You will be asked to login.'); t('To make a reservation, click on the desired time/day in the calendar below. You will be asked to login.');
$variables['#arrow'] = base_path() . \Drupal::service('extension.list.module')->getPath('reserve') . '/images/arrow-icon.png'; $variables['#arrow'] = base_path() . drupal_get_path('module', 'reserve') . '/images/arrow-icon.png';
$variables['#date'] = \Drupal::service('date.formatter')->format(strtotime($month . ' ' . $xday . ', ' . $year), 'custom', 'l, F d, Y'); $variables['#date'] = \Drupal::service('date.formatter')->format(strtotime($month . ' ' . $xday . ', ' . $year), 'custom', 'l, F d, Y');
$variables['#date_picker'] = \Drupal::formBuilder()->getForm('Drupal\reserve\Form\CalendarDatePicker'); $variables['#date_picker'] = \Drupal::formBuilder()->getForm('Drupal\reserve\Form\CalendarDatePicker');
$field = reserve_category_fields($ebundle); $field = reserve_category_fields($ebundle);
$fconfig = FieldConfig::loadByName($entity_type, $bundle, $field)->getSettings(); $fconfig = \Drupal\field\Entity\FieldConfig::loadByName($entity_type, $bundle, $field)->getSettings();
$variables['#calendar_header'] = $fconfig['calendar_header']; $variables['#calendar_header'] = $fconfig['calendar_header'];
$variables['#reservation_instructions'] = $fconfig['reservation_instructions']; $variables['#reservation_instructions'] = $fconfig['reservation_instructions'];

1
src/Form/ReserveDailyHoursForm.php

@ -5,6 +5,7 @@ namespace Drupal\reserve\Form;
use Drupal\Core\Form\ConfigFormBase; use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
module_load_include('inc', 'reserve', 'reserve.admin');
/** /**
* Class ReserveCategorySettingsForm. * Class ReserveCategorySettingsForm.

5
src/Form/ReserveDefaultHoursForm.php

@ -5,6 +5,8 @@ namespace Drupal\reserve\Form;
use Drupal\Core\Form\ConfigFormBase; use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
module_load_include('inc', 'reserve', 'reserve.admin');
/** /**
* Class ReserveCategorySettingsForm. * Class ReserveCategorySettingsForm.
* *
@ -233,6 +235,7 @@ class ReserveDefaultHoursForm extends ConfigFormBase {
*/ */
public function submitForm(array &$form, FormStateInterface $form_state) { public function submitForm(array &$form, FormStateInterface $form_state) {
$values = $form_state->getValues(); $values = $form_state->getValues();
$default_hours = array(); $default_hours = array();
if ($form_state->getTriggeringElement()['#name'] == 'save') { if ($form_state->getTriggeringElement()['#name'] == 'save') {
for ($day = 0; $day < 7; $day++) { for ($day = 0; $day < 7; $day++) {
@ -241,7 +244,7 @@ class ReserveDefaultHoursForm extends ConfigFormBase {
$default_hours[] = $values['day_' . $day]['second_shift_open_' . $day]; $default_hours[] = $values['day_' . $day]['second_shift_open_' . $day];
$default_hours[] = $values['day_' . $day]['second_shift_close_' . $day]; $default_hours[] = $values['day_' . $day]['second_shift_close_' . $day];
} }
$confirmation = RESERVE_SAVE_CONFIRMATION_MSG; $confirmation = t(RESERVE_SAVE_CONFIRMATION_MSG);
} }
if ($form_state->getTriggeringElement()['#name'] == 'reset') { if ($form_state->getTriggeringElement()['#name'] == 'reset') {
for ($day = 0; $day < 7; $day++) { for ($day = 0; $day < 7; $day++) {

6
src/Form/ReserveSettingsForm.php

@ -88,7 +88,7 @@ class ReserveSettingsForm extends ConfigFormBase {
'#type' => 'select', '#type' => 'select',
'#options' => $options, '#options' => $options,
'#default_value' => $config->get('reservation_max_length_standard') ? $config->get('reservation_max_length_standard') : 120, '#default_value' => $config->get('reservation_max_length_standard') ? $config->get('reservation_max_length_standard') : 120,
'#description' => t('The maximum amount of time (in minutes) which a reservation can be made by a user with "Create new reservations (extended)" '#description' => t('The maximum amount of time (in minutes) which a reservation can be made by a user with "Create new reservations (extended)"
privilege. Default is 120.'), privilege. Default is 120.'),
); );
@ -97,7 +97,7 @@ class ReserveSettingsForm extends ConfigFormBase {
'#type' => 'select', '#type' => 'select',
'#options' => $options, '#options' => $options,
'#default_value' => $config->get('reservation_max_length_extended') ? $config->get('reservation_max_length_extended') : 120, '#default_value' => $config->get('reservation_max_length_extended') ? $config->get('reservation_max_length_extended') : 120,
'#description' => t('The maximum amount of time (in minutes) which a reservation can be made by a user with "Create new reservations (extended)" '#description' => t('The maximum amount of time (in minutes) which a reservation can be made by a user with "Create new reservations (extended)"
privilege. Default is 120.'), privilege. Default is 120.'),
); );
@ -114,7 +114,7 @@ class ReserveSettingsForm extends ConfigFormBase {
'#title' => t('Time to show on calendar before/after open slots'), '#title' => t('Time to show on calendar before/after open slots'),
'#type' => 'select', '#type' => 'select',
'#options' => array(0 => '0 hours', 1 => t('1 hour'), 2 => t('2 hours'), '3' => t('All day')), '#options' => array(0 => '0 hours', 1 => t('1 hour'), 2 => t('2 hours'), '3' => t('All day')),
'#default_value' => $config->get('show_before_after_hours') ? $config->get('show_before_after_hours') : 3, '#default_value' => $config->get('show_before_after_hours') ? $config->get('advanced_booking_admin') : 3,
'#description' => t('The number of hours before the first and last open slots for the day that are shown on the calendar. The default is to display the entire day.'), '#description' => t('The number of hours before the first and last open slots for the day that are shown on the calendar. The default is to display the entire day.'),
); );

3
src/Plugin/Field/FieldFormatter/ReserveCategoryFormatter.php

@ -2,7 +2,6 @@
namespace Drupal\reserve\Plugin\Field\FieldFormatter; namespace Drupal\reserve\Plugin\Field\FieldFormatter;
use Drupal\reserve\Entity\ReserveCategory;
use Drupal\Core\Field\FormatterBase; use Drupal\Core\Field\FormatterBase;
use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Field\FieldItemListInterface;
@ -36,7 +35,7 @@ class ReserveCategoryFormatter extends FormatterBase {
$element = []; $element = [];
foreach ($items as $delta => $item) { foreach ($items as $delta => $item) {
$category = ReserveCategory::load($item->cid); $category = \Drupal\reserve\Entity\ReserveCategory::load($item->cid);
// Render each element as markup. // Render each element as markup.
$element[$delta] = [ $element[$delta] = [
'#type' => 'markup', '#type' => 'markup',

9
src/Plugin/Field/FieldType/ReserveCategory.php

@ -1,5 +1,5 @@
<?php <?php
namespace Drupal\reserve\Plugin\Field\FieldType; namespace Drupal\reserve\Plugin\Field\FieldType;
use Drupal\Core\Field\FieldItemBase; use Drupal\Core\Field\FieldItemBase;
@ -21,7 +21,7 @@ use Drupal\Core\TypedData\DataDefinition;
* category = @Translation("Reference"), * category = @Translation("Reference"),
* cardinality = 1, * cardinality = 1,
* ) * )
* *
*/ */
class ReserveCategory extends FieldItemBase implements FieldItemInterface { class ReserveCategory extends FieldItemBase implements FieldItemInterface {
/** /**
@ -64,8 +64,7 @@ class ReserveCategory extends FieldItemBase implements FieldItemInterface {
*/ */
public function fieldSettingsForm(array $form, FormStateInterface $form_state) { public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
// get a list of all Reserve Categories // get a list of all Reserve Categories
$ids = \Drupal::entityQuery('reserve_category')->accessCheck(TRUE) $ids = \Drupal::entityQuery('reserve_category')->sort('name', 'ASC')->execute();
->sort('name', 'ASC')->execute();
$categories = \Drupal\reserve\Entity\ReserveCategory::loadMultiple($ids); $categories = \Drupal\reserve\Entity\ReserveCategory::loadMultiple($ids);
$options = array(); $options = array();
foreach ($categories as $cat) { foreach ($categories as $cat) {
@ -114,4 +113,4 @@ class ReserveCategory extends FieldItemBase implements FieldItemInterface {
] + parent::defaultFieldSettings(); ] + parent::defaultFieldSettings();
} }
} }

8
src/Plugin/Field/FieldWidget/ReserveCategorySelect.php

@ -2,7 +2,6 @@
namespace Drupal\reserve\Plugin\Field\FieldWidget; namespace Drupal\reserve\Plugin\Field\FieldWidget;
use Drupal\reserve\Entity\ReserveCategory;
use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\WidgetBase; use Drupal\Core\Field\WidgetBase;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
@ -30,9 +29,8 @@ class ReserveCategorySelect extends WidgetBase {
// get a list of all Reserve Categories for this bundle // get a list of all Reserve Categories for this bundle
$set = $items->getSettings()['categories']; $set = $items->getSettings()['categories'];
$ids = \Drupal::entityQuery('reserve_category')->accessCheck(TRUE) $ids = \Drupal::entityQuery('reserve_category')->sort('name', 'ASC')->execute();
->sort('name', 'ASC')->execute(); $categories = \Drupal\reserve\Entity\ReserveCategory::loadMultiple($ids);
$categories = ReserveCategory::loadMultiple($ids);
$options = array(); $options = array();
foreach ($categories as $key => $cat) { foreach ($categories as $key => $cat) {
if (!in_array($key, $set)) continue; if (!in_array($key, $set)) continue;
@ -48,4 +46,4 @@ class ReserveCategorySelect extends WidgetBase {
return array('cid' => $element); return array('cid' => $element);
} }
} }

46
src/Tests/LoadTest.php

@ -0,0 +1,46 @@
<?php
namespace Drupal\reserve\Tests;
use Drupal\Core\Url;
use Drupal\simpletest\WebTestBase;
/**
* Simple test to ensure that main page loads with module enabled.
*
* @group reserve
*/
class LoadTest extends WebTestBase{
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['reserve'];
/**
* A user with permission to administer site configuration.
*
* @var \Drupal\user\UserInterface
*/
protected $user;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->user = $this->drupalCreateUser(['administer site configuration']);
$this->drupalLogin($this->user);
}
/**
* Tests that the home page loads with a 200 response.
*/
public function testLoad() {
$this->drupalGet(Url::fromRoute('<front>'));
$this->assertResponse(200);
}
}
Loading…
Cancel
Save