Browse Source

port to D9

4.0.x-roblib
Peter Lindstrom 3 years ago
parent
commit
14f35af9c0
  1. 70
      reservation.inc
  2. 50
      reserve.inc
  3. 2
      reserve.info.yml
  4. 28
      reserve.series.inc
  5. 24
      src/Controller/CalendarController.php
  6. 12
      src/Controller/ReservePermissions.php
  7. 2
      src/Form/CalendarDatePicker.php
  8. 4
      src/Form/ReserveCategoryForm.php
  9. 2
      src/Form/ReserveDailyHoursForm.php
  10. 4
      src/Form/ReserveDefaultHoursForm.php
  11. 4
      src/Form/ReserveReservationForm.php
  12. 2
      src/Form/ReserveSettingsForm.php
  13. 6
      src/ReserveCategoryListBuilder.php
  14. 3
      src/ReserveReservationAccessControlHandler.php
  15. 6
      src/ReserveReservationListBuilder.php

70
reservation.inc

@ -18,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;
@ -28,6 +28,22 @@ function reserve_form_reserve_reservation_form_alter(array &$form, FormStateInte
$path_args = explode('/', $_GET['path'] ); $path_args = explode('/', $_GET['path'] );
$length = 30 * $_GET['count']; $length = 30 * $_GET['count'];
}; };
$user = \Drupal::currentUser();
$user_roles = $user->getRoles();
//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.
if (in_array('administrator', $user_roles)) {
$book_extended = TRUE;
}
//Allow perm 'add reservations extended' to add as many as needed.
$roles_permissions = user_role_permissions($user_roles);
foreach ($roles_permissions as $role_key => $permissions) {
if (in_array('add reservations extended', $permissions)) {
$book_extended = TRUE;
}
}
//if (user_access('administer site configuration') && isset($_GET['edit']) && $_GET['edit'] == 'standard') { //if (user_access('administer site configuration') && isset($_GET['edit']) && $_GET['edit'] == 'standard') {
// return; // return;
@ -61,9 +77,38 @@ function reserve_form_reserve_reservation_form_alter(array &$form, FormStateInte
$year = reserve_which_year($month, $day); $year = reserve_which_year($month, $day);
$yyyymmdd = date('Y-m-d', strtotime($year . '-' . $month . '-' . $day)); $yyyymmdd = date('Y-m-d', strtotime($year . '-' . $month . '-' . $day));
$d = $yyyymmdd . ' 00:00:00'; $d = $yyyymmdd . ' 00:00:00';
}
$entity = entity_load($entity_type, $eid); 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;
}
$config = \Drupal::config('reserve.settings');
$max_per_user = $config->get('reservations_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;
}
}
$entity = \Drupal::entityTypeManager()->getStorage($entity_type)->load($eid);
$bundle = $entity->bundle(); $bundle = $entity->bundle();
$date = date('l, M d, Y', strtotime($d)); $date = date('l, M d, Y', strtotime($d));
$time = reserve_display_time($t); $time = reserve_display_time($t);
@ -96,12 +141,17 @@ function reserve_form_reserve_reservation_form_alter(array &$form, FormStateInte
$form['reservable_content_type']['#access'] = false; $form['reservable_content_type']['#access'] = false;
// in prep for having better lockout of having slot taken by another user; let's also hide Length // in prep for having better lockout of having slot taken by another user; let's also hide Length
$form['reservation_length']['#access'] = false; // Lets not hide the length so mobile users can pick a length.
//$form['reservation_length']['#access'] = false;
// hide other fields we don't want to show // hide other fields we don't want to show
$form['user_id']['#access'] = false; $form['user_id']['#access'] = false;
$form['reservation_series_id']['#access'] = false; $form['reservation_series_id']['#access'] = false;
$form['reservation_ebundle']['#access'] = false; $form['reservation_ebundle']['#access'] = false;
if(!$book_extended){
$form['reservation_repeat_type']['#access'] = FALSE;
$form['reservation_repeat_until']['#access'] = FALSE;
}
} }
// if we are editing; let's do some extra things: // if we are editing; let's do some extra things:
@ -222,7 +272,7 @@ function reserve_form_reserve_reservation_form_alter(array &$form, FormStateInte
*/ */
function reserve_form_reserve_reservation_delete_form_alter(array &$form, FormStateInterface $form_state) { function reserve_form_reserve_reservation_delete_form_alter(array &$form, FormStateInterface $form_state) {
// Retrieve an array which contains the path pieces. // Retrieve an array which contains the path pieces.
$refer_path = $_SERVER[HTTP_REFERER]; $refer_path = $_SERVER['HTTP_REFERER'];
$path_args = explode('/', $refer_path); $path_args = explode('/', $refer_path);
$month = $path_args[6]; $month = $path_args[6];
@ -231,12 +281,18 @@ function reserve_form_reserve_reservation_delete_form_alter(array &$form, FormSt
$year = reserve_which_year($month, $day); $year = reserve_which_year($month, $day);
$yyyymmdd = date('Y-m-d', strtotime($year . '-' . $month . '-' . $day)); $yyyymmdd = date('Y-m-d', strtotime($year . '-' . $month . '-' . $day));
$form['ebundle'] = ['#type' => 'hidden', '#value' => $ebundle]; $form['ebundle'] = ['#type' => 'hidden', '#value' => $ebundle];
$form['month'] = ['#type' => 'hidden', '#value' => date('m', strtotime($yyyymmdd))]; $form['month'] = ['#type' => 'hidden', '#value' => date('m', strtotime($yyyymmdd))];
$form['day'] = ['#type' => 'hidden', '#value' => date('d', strtotime($yyyymmdd))]; $form['day'] = ['#type' => 'hidden', '#value' => date('d', strtotime($yyyymmdd))];
$form['actions']['submit']['#submit'][] = 'reserve_return_to_home_page';
}
$form['actions']['submit']['#submit'][] = 'reserve_return_to_reservations_page'; /**
* Custom submit handler for login form.
*/
function reserve_return_to_home_page($form, FormStateInterface $form_state) {
$url = Url::fromRoute('<front>');
$form_state->setRedirectUrl($url);
} }
/** /**

50
reserve.inc

@ -25,11 +25,9 @@ function reserve_categories($ebundle = null) {
$ids = array_filter($fconfig['categories']); $ids = array_filter($fconfig['categories']);
} }
else { else {
$ids = Drupal::service('entity.query') $query = \Drupal::service('entity_type.manager')
->get('reserve_category') ->getStorage('reserve_category')->getQuery();
->condition('status', TRUE) $ids = $query->condition('status', TRUE)->execute();
//->sort('reserve_display_order', 'ASC')
->execute();
} }
$cats = \Drupal::entityTypeManager()->getStorage('reserve_category')->loadMultiple($ids); $cats = \Drupal::entityTypeManager()->getStorage('reserve_category')->loadMultiple($ids);
@ -59,9 +57,9 @@ function reserve_categories($ebundle = null) {
function reserve_entities($ebundle) { function reserve_entities($ebundle) {
$entity_type = ebundle_split($ebundle, 'type'); $entity_type = ebundle_split($ebundle, 'type');
$bundle = ebundle_split($ebundle, 'bundle'); $bundle = ebundle_split($ebundle, 'bundle');
$query = Drupal::service('entity.query') $query = \Drupal::service('entity_type.manager')
->get($entity_type) ->getStorage($entity_type)->getQuery();
->condition('status', TRUE); $query->condition('status', TRUE);
if ($entity_type != $bundle) { if ($entity_type != $bundle) {
$query->condition('type', $bundle); $query->condition('type', $bundle);
@ -805,9 +803,8 @@ function reserve_valid_lengths($rid, $ebundle, $yyyy_mmdd, $time, $id = NULL, $a
$start_time = $search_item['start_time']; $start_time = $search_item['start_time'];
$conflicts_found = false; $conflicts_found = false;
$query = \Drupal::service('entity_type.manager')
$query = Drupal::service('entity.query') ->getStorage('reserve_reservation')->getQuery()
->get('reserve_reservation')
->condition('reservation_date', $date . '%', 'LIKE') ->condition('reservation_date', $date . '%', 'LIKE')
->condition('reservation_time', $start_time) ->condition('reservation_time', $start_time)
->condition('reservable_id', $rid) ->condition('reservable_id', $rid)
@ -926,24 +923,21 @@ 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) {
global $user; $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) {
return FALSE; return FALSE;
} }
$record_count = 0; $record_count = 0;
if ($user->uid) { if ($user->id()) {
$ids = \Drupal::service('entity.query') $ids = \Drupal::service('entity_type.manager')
->get('reserve_reservation') ->getStorage('reserve_reservation')->getQuery()
->condition('user_id', $user->id) ->condition('user_id', $user->id())
->condition('reservation_date', 'value', $yyyy_mmdd . '%', 'like') ->condition('reservation_date', $yyyy_mmdd . '%', 'like')
->execute(); ->execute();
$record_count = count($ids); $record_count = count($ids);
} }
if ($record_count < $max) { if ($record_count < $max) {
return FALSE; return FALSE;
} }
@ -970,9 +964,8 @@ function reserve_user_reservations() {
if ($user->id()) { if ($user->id()) {
$earliest_date = date('Y-m-d', strtotime(date('Y-m-d'))); $earliest_date = date('Y-m-d', strtotime(date('Y-m-d')));
$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.query') ->getStorage('reserve_reservation')->getQuery()
->get('reserve_reservation')
->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, '<=')
@ -1032,7 +1025,7 @@ function reserve_yyyymmdd($month, $day) {
*/ */
function reserve_get_reserve_bundles() { function reserve_get_reserve_bundles() {
$bundles = array(); $bundles = array();
$fieldmap = \Drupal::entityManager()->getFieldMap(); $fieldmap = \Drupal::service('entity_field.manager')->getFieldMap();
foreach ($fieldmap as $entity_type => $typedef) { foreach ($fieldmap as $entity_type => $typedef) {
foreach ($typedef as $field) { foreach ($typedef as $field) {
if ($field['type'] == 'reserve_category') { if ($field['type'] == 'reserve_category') {
@ -1050,7 +1043,7 @@ function reserve_get_reserve_bundles() {
* OR specific field name if $ebundle is provided (e.g. node.room) * OR specific field name if $ebundle is provided (e.g. node.room)
*/ */
function reserve_category_fields($ebundle = NULL) { function reserve_category_fields($ebundle = NULL) {
$fieldmap = \Drupal::entityManager()->getFieldMap(); $fieldmap = \Drupal::service('entity_field.manager')->getFieldMap();
$fields = []; $fields = [];
foreach ($fieldmap as $entity_type => $typedef) { foreach ($fieldmap as $entity_type => $typedef) {
foreach ($typedef as $name => $field) { foreach ($typedef as $name => $field) {
@ -1071,8 +1064,9 @@ function reserve_category_fields($ebundle = NULL) {
function ebundle_split($ebundle, $part) { function ebundle_split($ebundle, $part) {
$ebits = explode('.', $ebundle); $ebits = explode('.', $ebundle);
if ($part == 'type') return $ebits[0]; if ($part == 'type' && isset($ebits[0])) return $ebits[0];
if ($part == 'bundle') return $ebits[1]; if ($part == 'bundle' && isset($ebits[1])) return $ebits[1];
return NULL;
} }
/* /*
@ -1112,7 +1106,7 @@ function reserve_which_year($month, $day) {
* used for Allowed Values for Reservation.reservable_content_type field * used for Allowed Values for Reservation.reservable_content_type field
*/ */
function reserve_site_entity_types() { function reserve_site_entity_types() {
$types = \Drupal::entityManager()->getEntityTypeLabels(TRUE); $types = \Drupal::service('entity_type.repository')->getEntityTypeLabels(TRUE);
return $types['Content']; return $types['Content'];
} }

2
reserve.info.yml

@ -1,8 +1,8 @@
name: Reserve name: Reserve
type: module type: module
description: Reservation system. description: Reservation system.
core: 8.x
package: Reserve package: Reserve
core_version_requirement: ^8 || ^9
dependencies: dependencies:
- drupal:views - drupal:views
- drupal:options - drupal:options

28
reserve.series.inc

@ -36,7 +36,8 @@ function reserve_reserve_reservation_insert($entity) {
$length = $entity->reservation_length->getString(); $length = $entity->reservation_length->getString();
$rid = $entity->reservable_id->getString(); $rid = $entity->reservable_id->getString();
$rtype = $entity->reservable_content_type->getString(); $rtype = $entity->reservable_content_type->getString();
$ebundle = $rtype . '.' . entity_load($rtype, $rid)->bundle(); $ebundle = $rtype . '.' . \Drupal::entityTypeManager()
->getStorage($rtype)->load($rid)->bundle();
$day = date('l', strtotime($start)); $day = date('l', strtotime($start));
$msg = ''; $msg = '';
@ -85,12 +86,12 @@ function reserve_reserve_reservation_insert($entity) {
// lets spit out some useful msgs // lets spit out some useful msgs
// first clear the msg stating we just created the reservation entity // first clear the msg stating we just created the reservation entity
drupal_get_messages('status'); \Drupal::messenger()->addStatus('status');
drupal_set_message(t('Your reservation series has been booked.')); \Drupal::messenger()->addStatus(t('Your reservation series has been booked.'));
drupal_set_message($msg); \Drupal::messenger()->addStatus($msg);
if (count($failed)) { if (count($failed)) {
$dates = Markup::create('<br>' . implode('<br>', $failed)); $dates = Markup::create('<br>' . implode('<br>', $failed));
drupal_set_message(t('The following dates were not booked due to scheduling conflicts: %dates', array('%dates' => $dates)), 'warning'); \Drupal::messenger()->addWarning(t('The following dates were not booked due to scheduling conflicts: %dates', array('%dates' => $dates)));
} }
} }
@ -122,12 +123,13 @@ function reserve_reserve_reservation_update($entity) {
$length = $entity->reservation_length->getString(); $length = $entity->reservation_length->getString();
$rid = $entity->reservable_id->getString(); $rid = $entity->reservable_id->getString();
$rtype = $entity->reservable_content_type->getString(); $rtype = $entity->reservable_content_type->getString();
$ebundle = $rtype . '.' . entity_load($rtype, $rid)->bundle(); $ebundle = $rtype . '.' . \Drupal::entityTypeManager()
->getStorage($rtype)->load($rid)->bundle();
$private = $entity->reservation_private->getString(); $private = $entity->reservation_private->getString();
// 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.query') $ids = \Drupal::service('entity_type.manager')
->get('reserve_reservation') ->getStorage('reserve_reservation')->getQuery()
->condition('status', TRUE) ->condition('status', TRUE)
->condition('reservation_series_id', $sid) ->condition('reservation_series_id', $sid)
->condition('id', $entity->id(), '!=') ->condition('id', $entity->id(), '!=')
@ -156,10 +158,10 @@ function reserve_reserve_reservation_update($entity) {
} }
// lets spit out some useful msgs // lets spit out some useful msgs
drupal_set_message(t('Your reservation series has been modified.')); \Drupal::messenger()->addStatus(t('Your reservation series has been modified.'));
if (count($failed)) { if (count($failed)) {
$dates = Markup::create('<br>' . implode('<br>', $failed)); $dates = Markup::create('<br>' . implode('<br>', $failed));
drupal_set_message(t('NOTE: The following dates did not have their length changed due to scheduling conflicts: %dates', array('%dates' => $dates)), 'warning'); \Drupal::messenger()->addStatus(t('NOTE: The following dates did not have their length changed due to scheduling conflicts: %dates', array('%dates' => $dates)));
} }
} }
@ -179,8 +181,8 @@ function reserve_reserve_reservation_delete($entity) {
function _reserve_series_delete($entity) { function _reserve_series_delete($entity) {
$sid = $entity->get('reservation_series_id')->getString(); $sid = $entity->get('reservation_series_id')->getString();
// grab all reservations in this series // grab all reservations in this series
$ids = \Drupal::service('entity.query') $ids = \Drupal::service('entity_type.manager')
->get('reserve_reservation') ->getStorage('reserve_reservation')->getQuery()
->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);
@ -188,5 +190,5 @@ function _reserve_series_delete($entity) {
$result->delete(); $result->delete();
} }
$title = $entity->get('name')->getString(); $title = $entity->get('name')->getString();
drupal_set_message(t('The reservation series @title was deleted.', array('@title' => $title))); \Drupal::messenger()->addStatus(t('The reservation series @title was deleted.', array('@title' => $title)));
} }

24
src/Controller/CalendarController.php

@ -36,13 +36,17 @@ class CalendarController extends ControllerBase {
public function calendarTitle($ebundle) { public function calendarTitle($ebundle) {
$bundle = ebundle_split($ebundle, 'bundle'); $bundle = ebundle_split($ebundle, 'bundle');
return t('@bundle Calendar', array('@bundle' => ucwords($bundle))); $type = ebundle_split($ebundle, 'type');
$bundles = \Drupal::service('entity_type.bundle.info')->getBundleInfo($type);
$titlePrefix = isset($bundles[$bundle]) ? $bundles[$bundle]['label'] : $bundle;
return t('@bundle Calendar', array('@bundle' => ucwords($titlePrefix)));
} }
private function getBundleCalendar($ebundle, $selected_month = null, $selected_day = null) { private function getBundleCalendar($ebundle, $selected_month = null, $selected_day = null) {
$config = \Drupal::config('reserve.settings'); $config = \Drupal::config('reserve.settings');
// likely no need for this as not used anywhere else; but maybe for external modules // likely no need for this as not used anywhere else; but maybe for external modules
global $yyyy_mmdd; global $yyyy_mmdd;
//$entity_type = ebundle_split($ebundle, 'type'); //$entity_type = ebundle_split($ebundle, 'type');
//$bundle = ebundle_split($ebundle, 'bundle'); //$bundle = ebundle_split($ebundle, 'bundle');
@ -57,7 +61,7 @@ class CalendarController extends ControllerBase {
// if no Categories left; we should not bother with the rest of this // if no Categories left; we should not bother with the rest of this
if (!count($categories)) { if (!count($categories)) {
drupal_set_message(t('There are no configured Reserve Categories. Please contact the System Administrator'), 'warning'); \Drupal::messenger()->addWarning(t('There are no configured Reserve Categories. Please contact the System Administrator'));
return ''; return '';
} }
@ -67,15 +71,22 @@ class CalendarController extends ControllerBase {
// Determine which day has been selected by the user. If the user has entered a url that specifies a day outside of the // Determine which day has been selected by the user. If the user has entered a url that specifies a day outside of the
// allowable reservation window, then set the current day as the selected day. // allowable reservation window, then set the current day as the selected day.
$yyyy_mmdd = $dates[0]['yyyymmdd']; $yyyy_mmdd = $dates[0]['yyyymmdd'];
$day_selected = false;
foreach ($dates as $day) { foreach ($dates as $day) {
if ($day['selected']) { if ($day['selected']) {
$yyyy_mmdd = $day['yyyymmdd']; $yyyy_mmdd = $day['yyyymmdd'];
$day_selected = TRUE;
} }
} }
if ($yyyy_mmdd == $dates[0]['yyyymmdd']) { if ($yyyy_mmdd == $dates[0]['yyyymmdd']) {
$dates[0]['selected'] = TRUE; $dates[0]['selected'] = TRUE;
$dates[0]['today'] = TRUE; $dates[0]['today'] = TRUE;
} }
if(!$day_selected) {
\Drupal::messenger()->addWarning(t('You have chosen a date to far in the '
. 'future. Please choose a date within 14 days of today. The Calendar'
. ' view below has defaulted to todays date.'));
}
// a bit hacky; but we need to store what the calendar is using for its date so we can use this in theme functions later // a bit hacky; but we need to store what the calendar is using for its date so we can use this in theme functions later
//$_SESSION['reservations_current_day'] = $yyyy_mmdd; //$_SESSION['reservations_current_day'] = $yyyy_mmdd;
@ -171,8 +182,8 @@ class CalendarController extends ControllerBase {
} }
$results = array(); $results = array();
$ids = \Drupal::service('entity.query') $ids = \Drupal::service('entity_type.manager')
->get('reserve_reservation') ->getStorage('reserve_reservation')->getQuery()
->condition('status', TRUE) ->condition('status', TRUE)
->condition('reservation_date', $yyyy_mmdd . '%', 'like') ->condition('reservation_date', $yyyy_mmdd . '%', 'like')
->condition('reservation_ebundle', $ebundle) ->condition('reservation_ebundle', $ebundle)
@ -357,7 +368,7 @@ class CalendarController extends ControllerBase {
$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_get_path('module', 'reserve') . '/images/arrow-icon.png'; $variables['#arrow'] = base_path() . drupal_get_path('module', 'reserve') . '/images/arrow-icon.png';
$variables['#date'] = format_date(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);
@ -494,7 +505,8 @@ class CalendarController extends ControllerBase {
// The time slot has a reservation that can be edited by the current user. // The time slot has a reservation that can be edited by the current user.
if ($id = $reservations[$rid][$time]['id']) { if ($id = $reservations[$rid][$time]['id']) {
$reservation = entity_load('reserve_reservation', $id); $reservation = \Drupal::entityTypeManager()
->getStorage('reserve_reservation')->load($id);
$viewable_class = $reservation->access('update') ? 'viewable' : ''; $viewable_class = $reservation->access('update') ? 'viewable' : '';
if ($viewable_class == 'viewable') { if ($viewable_class == 'viewable') {
$options = array_merge_recursive($modal, array( $options = array_merge_recursive($modal, array(

12
src/Controller/ReservePermissions.php

@ -4,7 +4,7 @@
namespace Drupal\reserve\Controller; namespace Drupal\reserve\Controller;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\StringTranslationTrait;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
@ -13,19 +13,19 @@ class ReservePermissions implements ContainerInjectionInterface {
use StringTranslationTrait; use StringTranslationTrait;
/** /**
* The entity manager. * The entity type manager.
* *
* @var \Drupal\Core\Entity\EntityManagerInterface * @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/ */
protected $entityManager; protected $entityManager;
/** /**
* Constructs a TaxonomyViewsIntegratorPermissions instance. * Constructs a TaxonomyViewsIntegratorPermissions instance.
* *
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_manager
* The entity manager. * The entity manager.
*/ */
public function __construct(EntityManagerInterface $entity_manager) { public function __construct(EntityTypeManagerInterface $entity_manager) {
$this->entityManager = $entity_manager; $this->entityManager = $entity_manager;
} }
@ -33,7 +33,7 @@ class ReservePermissions implements ContainerInjectionInterface {
* {@inheritdoc} * {@inheritdoc}
*/ */
public static function create(ContainerInterface $container) { public static function create(ContainerInterface $container) {
return new static($container->get('entity.manager')); return new static($container->get('entity_type.manager'));
} }
/** /**

2
src/Form/CalendarDatePicker.php

@ -49,7 +49,7 @@ class CalendarDatePicker extends FormBase {
public function submitForm(array &$form, FormStateInterface $form_state) { public function submitForm(array &$form, FormStateInterface $form_state) {
// Display result. // Display result.
foreach ($form_state->getValues() as $key => $value) { foreach ($form_state->getValues() as $key => $value) {
drupal_set_message($key . ': ' . $value); \Drupal::messenger()->addStatus($key . ': ' . $value);
} }
} }

4
src/Form/ReserveCategoryForm.php

@ -34,13 +34,13 @@ class ReserveCategoryForm extends ContentEntityForm {
switch ($status) { switch ($status) {
case SAVED_NEW: case SAVED_NEW:
drupal_set_message($this->t('Created the %label Reservation Category.', [ \Drupal::messenger()->addStatus($this->t('Created the %label Reservation Category.', [
'%label' => $entity->label(), '%label' => $entity->label(),
])); ]));
break; break;
default: default:
drupal_set_message($this->t('Saved the %label Reservation Category.', [ \Drupal::messenger()->addStatus($this->t('Saved the %label Reservation Category.', [
'%label' => $entity->label(), '%label' => $entity->label(),
])); ]));
} }

2
src/Form/ReserveDailyHoursForm.php

@ -245,6 +245,6 @@ class ReserveDailyHoursForm extends ConfigFormBase {
$this->config('reserve.monthly_hours') $this->config('reserve.monthly_hours')
->set($yyyy_mm, $updated_mo_hours) ->set($yyyy_mm, $updated_mo_hours)
->save(); ->save();
drupal_set_message($confirmation); \Drupal::messenger()->addStatus($confirmation);
} }
} }

4
src/Form/ReserveDefaultHoursForm.php

@ -296,13 +296,13 @@ class ReserveDefaultHoursForm extends ConfigFormBase {
$this->config('reserve.default_hours') $this->config('reserve.default_hours')
->set('data', $default_hours) ->set('data', $default_hours)
->save(); ->save();
drupal_set_message($confirmation); \Drupal::messenger()->addStatus ($confirmation);
// save updated monthly override hours // save updated monthly override hours
$this->config('reserve.monthly_hours') $this->config('reserve.monthly_hours')
->set('data', $monthly_hours) ->set('data', $monthly_hours)
->save(); ->save();
drupal_set_message(t('Daily overrides updated with new defaults.')); \Drupal::messenger()->addStatus(t('Daily overrides updated with new defaults.'));
} }
} }

4
src/Form/ReserveReservationForm.php

@ -34,13 +34,13 @@ class ReserveReservationForm extends ContentEntityForm {
switch ($status) { switch ($status) {
case SAVED_NEW: case SAVED_NEW:
drupal_set_message($this->t('Created the %label Reservation.', [ \Drupal::messenger()->addStatus ($this->t('Created the %label Reservation.', [
'%label' => $entity->label(), '%label' => $entity->label(),
])); ]));
break; break;
default: default:
drupal_set_message($this->t('Saved the %label Reservation.', [ \Drupal::messenger()->addStatus($this->t('Saved the %label Reservation.', [
'%label' => $entity->label(), '%label' => $entity->label(),
])); ]));
} }

2
src/Form/ReserveSettingsForm.php

@ -177,7 +177,7 @@ class ReserveSettingsForm extends ConfigFormBase {
$this->config('reserve.settings')->set($key, $value); $this->config('reserve.settings')->set($key, $value);
} }
$this->config('reserve.settings')->save(); $this->config('reserve.settings')->save();
drupal_set_message(RESERVE_SAVE_CONFIRMATION_MSG); \Drupal::messenger()->addStatus(RESERVE_SAVE_CONFIRMATION_MSG);
} }
} }

6
src/ReserveCategoryListBuilder.php

@ -6,6 +6,7 @@ use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityListBuilder; use Drupal\Core\Entity\EntityListBuilder;
use Drupal\Core\Routing\LinkGeneratorTrait; use Drupal\Core\Routing\LinkGeneratorTrait;
use Drupal\Core\Url; use Drupal\Core\Url;
use Drupal\Core\Link;
/** /**
* Defines a class to build a listing of reservation categories. * Defines a class to build a listing of reservation categories.
@ -14,7 +15,6 @@ use Drupal\Core\Url;
*/ */
class ReserveCategoryListBuilder extends EntityListBuilder { class ReserveCategoryListBuilder extends EntityListBuilder {
use LinkGeneratorTrait;
/** /**
* {@inheritdoc} * {@inheritdoc}
@ -31,14 +31,14 @@ class ReserveCategoryListBuilder extends EntityListBuilder {
public function buildRow(EntityInterface $entity) { public function buildRow(EntityInterface $entity) {
/* @var $entity \Drupal\reserve\Entity\ReserveCategory */ /* @var $entity \Drupal\reserve\Entity\ReserveCategory */
$row['id'] = $entity->id(); $row['id'] = $entity->id();
$row['name'] = $this->l( $row['name'] = Link::fromTextAndUrl(
$entity->label(), $entity->label(),
new Url( new Url(
'entity.reserve_category.edit_form', array( 'entity.reserve_category.edit_form', array(
'reserve_category' => $entity->id(), 'reserve_category' => $entity->id(),
) )
) )
); )->toString();
return $row + parent::buildRow($entity); return $row + parent::buildRow($entity);
} }

3
src/ReserveReservationAccessControlHandler.php

@ -36,6 +36,9 @@ class ReserveReservationAccessControlHandler extends EntityAccessControlHandler
case 'delete': case 'delete':
$access = AccessResult::allowedIfHasPermission($account, 'delete any reservation'); $access = AccessResult::allowedIfHasPermission($account, 'delete any reservation');
if (!$access->isAllowed() && $account->hasPermission('delete own reservation')) {
$access = $access->orIf(AccessResult::allowedIf($account->id() == $entity->getOwnerId())->cachePerUser()->addCacheableDependency($entity));
}
break; break;
// Unknown operation, no opinion. // Unknown operation, no opinion.

6
src/ReserveReservationListBuilder.php

@ -6,6 +6,7 @@ use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityListBuilder; use Drupal\Core\Entity\EntityListBuilder;
use Drupal\Core\Routing\LinkGeneratorTrait; use Drupal\Core\Routing\LinkGeneratorTrait;
use Drupal\Core\Url; use Drupal\Core\Url;
use Drupal\Core\Link;
/** /**
* Defines a class to build a listing of reservations. * Defines a class to build a listing of reservations.
@ -14,7 +15,6 @@ use Drupal\Core\Url;
*/ */
class ReserveReservationListBuilder extends EntityListBuilder { class ReserveReservationListBuilder extends EntityListBuilder {
use LinkGeneratorTrait;
/** /**
* {@inheritdoc} * {@inheritdoc}
@ -31,14 +31,14 @@ class ReserveReservationListBuilder extends EntityListBuilder {
public function buildRow(EntityInterface $entity) { public function buildRow(EntityInterface $entity) {
/* @var $entity \Drupal\reserve\Entity\ReserveReservation */ /* @var $entity \Drupal\reserve\Entity\ReserveReservation */
$row['id'] = $entity->id(); $row['id'] = $entity->id();
$row['name'] = $this->l( $row['name'] = Link::fromTextAndUrl(
$entity->label(), $entity->label(),
new Url( new Url(
'entity.reserve_reservation.edit_form', array( 'entity.reserve_reservation.edit_form', array(
'reserve_reservation' => $entity->id(), 'reserve_reservation' => $entity->id(),
) )
) )
); )->toString();
return $row + parent::buildRow($entity); return $row + parent::buildRow($entity);
} }

Loading…
Cancel
Save