Compare commits

..

12 Commits

  1. 10
      config/install/field.storage.reserve_category.reserve_maxadv_ext.yml
  2. 10
      config/install/field.storage.reserve_category.reserve_maxadv_std.yml
  3. 10
      config/install/field.storage.reserve_category.reserve_minadv_ext.yml
  4. 10
      config/install/field.storage.reserve_category.reserve_minadv_std.yml
  5. 470
      config/install/views.view.reservations.yml
  6. 77
      reservation.inc
  7. 72
      reserve.inc
  8. 2
      reserve.info.yml
  9. 6
      reserve.module
  10. 44
      reserve.series.inc
  11. 41
      src/Controller/CalendarController.php
  12. 12
      src/Controller/ReservePermissions.php
  13. 2
      src/Form/CalendarDatePicker.php
  14. 4
      src/Form/ReserveCategoryForm.php
  15. 3
      src/Form/ReserveDailyHoursForm.php
  16. 9
      src/Form/ReserveDefaultHoursForm.php
  17. 4
      src/Form/ReserveReservationForm.php
  18. 8
      src/Form/ReserveSettingsForm.php
  19. 3
      src/Plugin/Field/FieldFormatter/ReserveCategoryFormatter.php
  20. 9
      src/Plugin/Field/FieldType/ReserveCategory.php
  21. 8
      src/Plugin/Field/FieldWidget/ReserveCategorySelect.php
  22. 6
      src/ReserveCategoryListBuilder.php
  23. 3
      src/ReserveReservationAccessControlHandler.php
  24. 6
      src/ReserveReservationListBuilder.php
  25. 46
      src/Tests/LoadTest.php

10
config/install/field.storage.reserve_category.reserve_maxadv_ext.yml

@ -12,19 +12,19 @@ settings:
allowed_values:
-
value: 30
label: 30
label: '30'
-
value: 60
label: 60
label: '60'
-
value: 90
label: 90
label: '90'
-
value: 180
label: 180
label: '180'
-
value: 360
label: 360
label: '360'
module: options
locked: true
cardinality: 1

10
config/install/field.storage.reserve_category.reserve_maxadv_std.yml

@ -12,19 +12,19 @@ settings:
allowed_values:
-
value: 7
label: 7
label: '7'
-
value: 14
label: 14
label: '14'
-
value: 30
label: 30
label: '30'
-
value: 60
label: 60
label: '60'
-
value: 90
label: 90
label: '90'
module: options
locked: true
cardinality: 1

10
config/install/field.storage.reserve_category.reserve_minadv_ext.yml

@ -12,19 +12,19 @@ settings:
allowed_values:
-
value: 0
label: 0
label: '0'
-
value: 1
label: 1
label: '1'
-
value: 7
label: 7
label: '7'
-
value: 14
label: 14
label: '14'
-
value: 30
label: 30
label: '30'
module: options
locked: true
cardinality: 1

10
config/install/field.storage.reserve_category.reserve_minadv_std.yml

@ -12,19 +12,19 @@ settings:
allowed_values:
-
value: 0
label: 0
label: '0'
-
value: 1
label: 1
label: '1'
-
value: 7
label: 7
label: '7'
-
value: 14
label: 14
label: '14'
-
value: 30
label: 30
label: '30'
module: options
locked: true
cardinality: 1

470
config/install/views.view.reservations.yml

@ -17,7 +17,7 @@ dependencies:
- reserve
- views_bulk_operations
_core:
default_config_hash: qtxsAzivRyJgkwE59iiTdA2ucLdj2OtA9MwdI-OUYzI
default_config_hash: Fpw3XOpA8QhT5E7YrASas4PrG75lo7-SVSpwa9dvMYA
id: reservations
label: Reservations
module: views
@ -25,165 +25,14 @@ description: ''
tag: ''
base_table: reserve_reservation_field_data
base_field: id
core: 8.x
display:
default:
display_plugin: default
id: default
display_title: Master
display_plugin: default
position: 0
display_options:
access:
type: none
options: { }
cache:
type: tag
options: { }
query:
type: views_query
options:
disable_sql_rewrite: false
distinct: false
replica: false
query_comment: ''
query_tags: { }
exposed_form:
type: basic
options:
submit_button: Apply
reset_button: false
reset_button_label: Reset
exposed_sorts_label: 'Sort by'
expose_sort_order: true
sort_asc_label: Asc
sort_desc_label: Desc
pager:
type: full
options:
items_per_page: 40
offset: 0
id: 0
total_pages: null
tags:
previous: ‹‹
next: ››
first: '« First'
last: 'Last »'
expose:
items_per_page: false
items_per_page_label: 'Items per page'
items_per_page_options: '5, 10, 25, 50'
items_per_page_options_all: false
items_per_page_options_all_label: '- All -'
offset: false
offset_label: Offset
quantity: 9
style:
type: table
options:
grouping: { }
row_class: ''
default_row_class: true
override: true
sticky: false
caption: ''
summary: ''
description: ''
columns:
views_bulk_operations_bulk_form: views_bulk_operations_bulk_form
name: name
reservation_date: reservation_date
reservation_time: reservation_date
reservation_length: reservation_date
reservation_private: reservation_private
reservation_repeat_type: reservation_repeat_type
reservation_repeat_until: reservation_repeat_type
reservable_content_type: reservable_content_type
reservation_ebundle: reservable_content_type
operations: operations
info:
views_bulk_operations_bulk_form:
align: ''
separator: ''
empty_column: false
responsive: ''
name:
sortable: true
default_sort_order: asc
align: ''
separator: ''
empty_column: false
responsive: ''
reservation_date:
sortable: true
default_sort_order: asc
align: ''
separator: ' '
empty_column: false
responsive: ''
reservation_time:
sortable: false
default_sort_order: asc
align: ''
separator: ''
empty_column: false
responsive: ''
reservation_length:
sortable: false
default_sort_order: asc
align: ''
separator: ''
empty_column: false
responsive: ''
reservation_private:
sortable: false
default_sort_order: asc
align: ''
separator: ''
empty_column: false
responsive: ''
reservation_repeat_type:
sortable: true
default_sort_order: asc
align: ''
separator: ''
empty_column: false
responsive: ''
reservation_repeat_until:
sortable: false
default_sort_order: asc
align: ''
separator: ''
empty_column: false
responsive: ''
reservable_content_type:
sortable: true
default_sort_order: asc
align: ''
separator: '<br>'
empty_column: false
responsive: ''
reservation_ebundle:
sortable: false
default_sort_order: asc
align: ''
separator: ''
empty_column: false
responsive: ''
operations:
align: ''
separator: ''
empty_column: false
responsive: ''
default: '-1'
empty_table: false
row:
type: fields
options:
inline: { }
separator: ''
hide_empty: false
default_field_elements: true
title: 'My Rese'
fields:
views_bulk_operations_bulk_form:
id: views_bulk_operations_bulk_form
@ -192,7 +41,8 @@ display:
relationship: none
group_type: group
admin_label: ''
label: ''
plugin_id: views_bulk_operations_bulk_form
label: 'Views bulk operations'
exclude: false
alter:
alter_text: false
@ -225,7 +75,7 @@ display:
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: false
element_label_colon: true
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
@ -238,16 +88,11 @@ display:
form_step: true
buttons: false
action_title: Action
clear_on_exposed: true
force_selection_info: false
selected_actions:
views_bulk_edit: views_bulk_edit
views_bulk_operations_delete_entity: views_bulk_operations_delete_entity
preconfiguration:
views_bulk_edit:
label_override: ''
get_bundles_from_results: 1
views_bulk_operations_delete_entity:
label_override: ''
plugin_id: views_bulk_operations_bulk_form
-
action_id: views_bulk_operations_delete_entity
name:
id: name
table: reserve_reservation_field_data
@ -255,6 +100,9 @@ display:
relationship: none
group_type: group
admin_label: ''
entity_type: null
entity_field: name
plugin_id: field
label: Group
exclude: false
alter:
@ -310,9 +158,6 @@ display:
multi_type: separator
separator: ', '
field_api_classes: false
entity_type: null
entity_field: name
plugin_id: field
reservation_date:
id: reservation_date
table: reserve_reservation__reservation_date
@ -320,6 +165,7 @@ display:
relationship: none
group_type: group
admin_label: ''
plugin_id: field
label: When
exclude: false
alter:
@ -376,7 +222,6 @@ display:
multi_type: separator
separator: ', '
field_api_classes: false
plugin_id: field
reservation_time:
id: reservation_time
table: reserve_reservation__reservation_time
@ -384,6 +229,7 @@ display:
relationship: none
group_type: group
admin_label: ''
plugin_id: field
label: ''
exclude: false
alter:
@ -439,7 +285,6 @@ display:
multi_type: separator
separator: ', '
field_api_classes: false
plugin_id: field
reservation_length:
id: reservation_length
table: reserve_reservation__reservation_length
@ -447,6 +292,7 @@ display:
relationship: none
group_type: group
admin_label: ''
plugin_id: field
label: ''
exclude: false
alter:
@ -501,7 +347,6 @@ display:
multi_type: separator
separator: ', '
field_api_classes: false
plugin_id: field
reservation_private:
id: reservation_private
table: reserve_reservation__reservation_private
@ -509,6 +354,7 @@ display:
relationship: none
group_type: group
admin_label: ''
plugin_id: field
label: Private
exclude: false
alter:
@ -554,8 +400,8 @@ display:
type: boolean
settings:
format: default
format_custom_true: ''
format_custom_false: ''
format_custom_true: ''
group_column: value
group_columns: { }
group_rows: true
@ -566,7 +412,6 @@ display:
multi_type: separator
separator: ', '
field_api_classes: false
plugin_id: field
reservation_repeat_type:
id: reservation_repeat_type
table: reserve_reservation__reservation_repeat_type
@ -574,6 +419,7 @@ display:
relationship: none
group_type: group
admin_label: ''
plugin_id: field
label: Repeating
exclude: false
alter:
@ -628,7 +474,6 @@ display:
multi_type: separator
separator: ', '
field_api_classes: false
plugin_id: field
reservation_repeat_until:
id: reservation_repeat_until
table: reserve_reservation__reservation_repeat_until
@ -636,6 +481,7 @@ display:
relationship: none
group_type: group
admin_label: ''
plugin_id: field
label: ''
exclude: false
alter:
@ -692,7 +538,6 @@ display:
multi_type: separator
separator: ', '
field_api_classes: false
plugin_id: field
reservable_content_type:
id: reservable_content_type
table: reserve_reservation__reservable_content_type
@ -700,6 +545,7 @@ display:
relationship: none
group_type: group
admin_label: ''
plugin_id: field
label: 'Reservation Type'
exclude: false
alter:
@ -754,7 +600,6 @@ display:
multi_type: separator
separator: ', '
field_api_classes: false
plugin_id: field
reservation_ebundle:
id: reservation_ebundle
table: reserve_reservation__reservation_ebundle
@ -762,6 +607,7 @@ display:
relationship: none
group_type: group
admin_label: ''
plugin_id: field
label: Ebundle
exclude: false
alter:
@ -817,7 +663,6 @@ display:
multi_type: separator
separator: ', '
field_api_classes: false
plugin_id: field
operations:
id: operations
table: reserve_reservation
@ -825,6 +670,8 @@ display:
relationship: none
group_type: group
admin_label: ''
entity_type: reserve_reservation
plugin_id: entity_operations
label: Operations
exclude: false
alter:
@ -867,8 +714,73 @@ display:
empty_zero: false
hide_alter_empty: true
destination: true
entity_type: reserve_reservation
plugin_id: entity_operations
pager:
type: full
options:
offset: 0
items_per_page: 40
total_pages: null
id: 0
tags:
next: ››
previous: ‹‹
first: '« First'
last: 'Last »'
expose:
items_per_page: false
items_per_page_label: 'Items per page'
items_per_page_options: '5, 10, 25, 50'
items_per_page_options_all: false
items_per_page_options_all_label: '- All -'
offset: false
offset_label: Offset
quantity: 9
exposed_form:
type: basic
options:
submit_button: Apply
reset_button: false
reset_button_label: Reset
exposed_sorts_label: 'Sort by'
expose_sort_order: true
sort_asc_label: Asc
sort_desc_label: Desc
access:
type: none
options: { }
cache:
type: tag
options: { }
empty:
area:
id: area
table: views
field: area
relationship: none
group_type: group
admin_label: ''
plugin_id: text
empty: true
content:
value: 'The are no reservations.'
format: basic_html
tokenize: false
sorts:
reservation_date_value:
id: reservation_date_value
table: reserve_reservation__reservation_date
field: reservation_date_value
relationship: none
group_type: group
admin_label: ''
plugin_id: datetime
order: ASC
expose:
label: ''
field_identifier: reservation_date_value
exposed: false
granularity: second
arguments: { }
filters:
name:
id: name
@ -877,6 +789,9 @@ display:
relationship: none
group_type: group
admin_label: ''
entity_type: reserve_reservation
entity_field: name
plugin_id: string
operator: contains
value: ''
group: 1
@ -887,6 +802,8 @@ display:
description: ''
use_operator: false
operator: name_op
operator_limit_selection: false
operator_list: { }
identifier: name
required: false
remember: false
@ -907,9 +824,6 @@ display:
default_group: All
default_group_multiple: { }
group_items: { }
entity_type: reserve_reservation
entity_field: name
plugin_id: string
reservation_date_value:
id: reservation_date_value
table: reserve_reservation__reservation_date
@ -917,6 +831,7 @@ display:
relationship: none
group_type: group
admin_label: ''
plugin_id: datetime
operator: '='
value:
min: ''
@ -931,6 +846,8 @@ display:
description: ''
use_operator: false
operator: reservation_date_value_op
operator_limit_selection: false
operator_list: { }
identifier: reservation_date_value
required: false
remember: false
@ -951,45 +868,122 @@ display:
default_group: All
default_group_multiple: { }
group_items: { }
plugin_id: datetime
sorts:
reservation_date_value:
id: reservation_date_value
table: reserve_reservation__reservation_date
field: reservation_date_value
relationship: none
group_type: group
admin_label: ''
order: ASC
exposed: false
expose:
label: ''
granularity: second
plugin_id: datetime
header: { }
footer: { }
empty:
area:
id: area
table: views
field: area
relationship: none
group_type: group
admin_label: ''
empty: true
tokenize: false
content:
value: 'The are no reservations.'
format: basic_html
plugin_id: text
relationships: { }
arguments: { }
display_extenders: { }
filter_groups:
operator: OR
groups:
1: AND
title: 'My Rese'
style:
type: table
options:
grouping: { }
row_class: ''
default_row_class: true
columns:
name: name
reservation_date: reservation_date
reservation_time: reservation_date
reservation_length: reservation_date
reservation_private: reservation_private
reservation_repeat_type: reservation_repeat_type
reservation_repeat_until: reservation_repeat_type
reservable_content_type: reservable_content_type
reservation_ebundle: reservable_content_type
operations: operations
default: '-1'
info:
name:
sortable: true
default_sort_order: asc
align: ''
separator: ''
empty_column: false
responsive: ''
reservation_date:
sortable: true
default_sort_order: asc
align: ''
separator: ' '
empty_column: false
responsive: ''
reservation_time:
sortable: false
default_sort_order: asc
align: ''
separator: ''
empty_column: false
responsive: ''
reservation_length:
sortable: false
default_sort_order: asc
align: ''
separator: ''
empty_column: false
responsive: ''
reservation_private:
sortable: false
default_sort_order: asc
align: ''
separator: ''
empty_column: false
responsive: ''
reservation_repeat_type:
sortable: true
default_sort_order: asc
align: ''
separator: ''
empty_column: false
responsive: ''
reservation_repeat_until:
sortable: false
default_sort_order: asc
align: ''
separator: ''
empty_column: false
responsive: ''
reservable_content_type:
sortable: true
default_sort_order: asc
align: ''
separator: '<br>'
empty_column: false
responsive: ''
reservation_ebundle:
sortable: false
default_sort_order: asc
align: ''
separator: ''
empty_column: false
responsive: ''
operations:
align: ''
separator: ''
empty_column: false
responsive: ''
override: true
sticky: false
summary: ''
empty_table: false
caption: ''
description: ''
row:
type: fields
options:
default_field_elements: true
inline: { }
separator: ''
hide_empty: false
query:
type: views_query
options:
query_comment: ''
disable_sql_rewrite: false
distinct: false
replica: false
query_tags: { }
relationships: { }
header: { }
footer: { }
display_extenders: { }
cache_metadata:
max-age: 0
contexts:
@ -1007,26 +1001,26 @@ display:
- 'config:field.storage.reserve_reservation.reservation_repeat_until'
- 'config:field.storage.reserve_reservation.reservation_time'
page_1:
display_plugin: page
id: page_1
display_title: 'Manage (admin)'
display_plugin: page
position: 1
display_options:
title: 'Manage Reservations'
defaults:
title: false
display_description: ''
display_extenders: { }
path: admin/structure/reservations/reserve_reservations/manage-reservations
menu:
type: normal
title: 'Manage Reservations'
description: ''
weight: 0
expanded: false
menu_name: admin
parent: entity.reserve_reservation.collection
weight: 0
context: '0'
menu_name: admin
display_description: ''
title: 'Manage Reservations'
defaults:
title: false
cache_metadata:
max-age: 0
contexts:
@ -1044,14 +1038,12 @@ display:
- 'config:field.storage.reserve_reservation.reservation_repeat_until'
- 'config:field.storage.reserve_reservation.reservation_time'
page_2:
display_plugin: page
id: page_2
display_title: 'My Reservations'
display_plugin: page
position: 2
display_options:
display_extenders: { }
display_description: ''
path: reserve/%ebundle/my-reservations
title: 'My Reservations'
arguments:
reservation_ebundle_value:
id: reservation_ebundle_value
@ -1060,6 +1052,7 @@ display:
relationship: none
group_type: group
admin_label: ''
plugin_id: string
default_action: default
exception:
value: all
@ -1075,8 +1068,8 @@ display:
summary_options:
base_path: ''
count: true
items_per_page: 25
override: false
items_per_page: 25
summary:
sort_order: asc
number_of_records: 0
@ -1092,7 +1085,6 @@ display:
path_case: none
transform_dash: false
break_phrase: false
plugin_id: string
user_id:
id: user_id
table: reserve_reservation_field_data
@ -1100,6 +1092,9 @@ display:
relationship: none
group_type: group
admin_label: ''
entity_type: reserve_reservation
entity_field: user_id
plugin_id: numeric
default_action: default
exception:
value: all
@ -1113,8 +1108,8 @@ display:
summary_options:
base_path: ''
count: true
items_per_page: 25
override: false
items_per_page: 25
summary:
sort_order: asc
number_of_records: 0
@ -1126,22 +1121,21 @@ display:
validate_options: { }
break_phrase: false
not: false
entity_type: reserve_reservation
entity_field: user_id
plugin_id: numeric
defaults:
arguments: false
title: false
arguments: false
display_description: ''
display_extenders: { }
path: reserve/%ebundle/my-reservations
menu:
type: tab
title: 'My Reservations'
description: ''
weight: 0
expanded: false
menu_name: main
parent: ''
weight: 0
context: '0'
menu_name: main
title: 'My Reservations'
cache_metadata:
max-age: 0
contexts:

77
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
@ -28,6 +29,22 @@ function reserve_form_reserve_reservation_form_alter(array &$form, FormStateInte
$path_args = explode('/', $_GET['path'] );
$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') {
// return;
@ -61,9 +78,20 @@ function reserve_form_reserve_reservation_form_alter(array &$form, FormStateInte
$year = reserve_which_year($month, $day);
$yyyymmdd = date('Y-m-d', strtotime($year . '-' . $month . '-' . $day));
$d = $yyyymmdd . ' 00:00:00';
}
$entity = entity_load($entity_type, $eid);
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);
}
$config = \Drupal::config('reserve.settings');
$max_per_user = $config->get('reservations_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);
}
}
$entity = \Drupal::entityTypeManager()->getStorage($entity_type)->load($eid);
$bundle = $entity->bundle();
$date = date('l, M d, Y', strtotime($d));
$time = reserve_display_time($t);
@ -71,9 +99,10 @@ function reserve_form_reserve_reservation_form_alter(array &$form, FormStateInte
$bundleName = $bundle_info[$entity->getEntityTypeId()][$entity->bundle()]['label'];
// set default Group Name as name of current user
$form['name']['widget'][0]['value']['#default_value'] = $form['name']['widget'][0]['value']['#default_value'] ?
$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'] :
\Drupal::currentUser()->getDisplayName();
\Drupal::currentUser()->getDisplayName();*/
// set values taken from URL
$form['reservation_date']['widget'][0]['value']['#default_value'] = DrupalDateTime::createFromTimestamp(strtotime($yyyymmdd));
@ -96,12 +125,17 @@ function reserve_form_reserve_reservation_form_alter(array &$form, FormStateInte
$form['reservable_content_type']['#access'] = false;
// 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
$form['user_id']['#access'] = false;
$form['reservation_series_id']['#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:
@ -124,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');
@ -132,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']);
@ -222,7 +256,7 @@ function reserve_form_reserve_reservation_form_alter(array &$form, FormStateInte
*/
function reserve_form_reserve_reservation_delete_form_alter(array &$form, FormStateInterface $form_state) {
// Retrieve an array which contains the path pieces.
$refer_path = $_SERVER[HTTP_REFERER];
$refer_path = $_SERVER['HTTP_REFERER'];
$path_args = explode('/', $refer_path);
$month = $path_args[6];
@ -231,12 +265,33 @@ function reserve_form_reserve_reservation_delete_form_alter(array &$form, FormSt
$year = reserve_which_year($month, $day);
$yyyymmdd = date('Y-m-d', strtotime($year . '-' . $month . '-' . $day));
$form['ebundle'] = ['#type' => 'hidden', '#value' => $ebundle];
$form['month'] = ['#type' => 'hidden', '#value' => date('m', 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);
}
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;
}
/**
@ -249,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);
}
}

72
reserve.inc

@ -1,4 +1,5 @@
<?php
use Drupal\field\Entity\FieldConfig;
/**
* @file
* Classes and general Room Reservations helper functions.
@ -21,15 +22,13 @@ function reserve_categories($ebundle = null) {
$entity_type = ebundle_split($ebundle, 'type');
$bundle = ebundle_split($ebundle, 'bundle');
$field = reserve_category_fields($ebundle);
$fconfig = \Drupal\field\Entity\FieldConfig::loadByName($entity_type, $bundle, $field)->getSettings();
$fconfig = FieldConfig::loadByName($entity_type, $bundle, $field)->getSettings();
$ids = array_filter($fconfig['categories']);
}
else {
$ids = Drupal::service('entity.query')
->get('reserve_category')
->condition('status', TRUE)
//->sort('reserve_display_order', 'ASC')
->execute();
$query = \Drupal::service('entity_type.manager')
->getStorage('reserve_category')->getQuery();
$ids = $query->condition('status', TRUE)->accessCheck(FALSE)->execute();
}
$cats = \Drupal::entityTypeManager()->getStorage('reserve_category')->loadMultiple($ids);
@ -59,16 +58,16 @@ function reserve_categories($ebundle = null) {
function reserve_entities($ebundle) {
$entity_type = ebundle_split($ebundle, 'type');
$bundle = ebundle_split($ebundle, 'bundle');
$query = Drupal::service('entity.query')
->get($entity_type)
->condition('status', TRUE);
$query = \Drupal::service('entity_type.manager')
->getStorage($entity_type)->getQuery();
$query->condition('status', TRUE);
if ($entity_type != $bundle) {
$query->condition('type', $bundle);
}
//->sort('reservations_display_order', 'ASC')
$ids = $query->execute();
$ids = $query->accessCheck(FALSE)->execute();
$entities = \Drupal::entityTypeManager()->getStorage($entity_type)->loadMultiple($ids);
@ -279,7 +278,7 @@ function reserve_hours($option = NULL) {
}
// convert display to 24:00 format if required
if ($config->get('reserve_hour_format')) {
if ($config->get('hour_format') == 1) {
$display = date('H:i', strtotime($display));
}
@ -355,8 +354,8 @@ function reserve_facility_hours($date, $reset = FALSE) {
$year = substr($month, 0, 4);
$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_close = $mo_hours[$start + 2];
$second_shift_open = $mo_hours[$start + 3];
@ -698,7 +697,7 @@ function reserve_start_conflicts($room, $yyyy_mmdd, $time) {
)
";
$conflicts_found = FALSE;
$conflicts_found = db_query($sql, array(
$conflicts_found = \Drupal::database()->query($sql, array(
':room' => $room,
':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'],
@ -707,8 +706,7 @@ function reserve_start_conflicts($room, $yyyy_mmdd, $time) {
':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'],
':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;
}
@ -805,9 +803,8 @@ function reserve_valid_lengths($rid, $ebundle, $yyyy_mmdd, $time, $id = NULL, $a
$start_time = $search_item['start_time'];
$conflicts_found = false;
$query = Drupal::service('entity.query')
->get('reserve_reservation')
$query = \Drupal::service('entity_type.manager')
->getStorage('reserve_reservation')->getQuery()
->condition('reservation_date', $date . '%', 'LIKE')
->condition('reservation_time', $start_time)
->condition('reservable_id', $rid)
@ -926,24 +923,22 @@ function reserve_valid_lengths($rid, $ebundle, $yyyy_mmdd, $time, $id = NULL, $a
* FALSE - the maximum has not been exceeded.
*/
function reserve_daily_max_exceeded($yyyy_mmdd) {
global $user;
$user = \Drupal::currentUser();
$config = \Drupal::config('reserve.settings');
$max = $config->get('reservations_per_day');
if (!$max) {
return FALSE;
}
$record_count = 0;
if ($user->uid) {
$ids = \Drupal::service('entity.query')
->get('reserve_reservation')
->condition('user_id', $user->id)
->condition('reservation_date', 'value', $yyyy_mmdd . '%', 'like')
if ($user->id()) {
$ids = \Drupal::service('entity_type.manager')
->getStorage('reserve_reservation')->getQuery()
->accessCheck(FALSE)
->condition('user_id', $user->id())
->condition('reservation_date', $yyyy_mmdd . '%', 'like')
->execute();
$record_count = count($ids);
}
if ($record_count < $max) {
return FALSE;
}
@ -970,9 +965,9 @@ function reserve_user_reservations() {
if ($user->id()) {
$earliest_date = date('Y-m-d', strtotime(date('Y-m-d')));
$latest_date = date('Y-m-d', strtotime("now +13 days"));
$ids = \Drupal::service('entity.query')
->get('reserve_reservation')
$ids = \Drupal::service('entity_type.manager')
->getStorage('reserve_reservation')->getQuery()
->accessCheck(TRUE)
->condition('user_id', $user->id())
->condition('reservation_date', $earliest_date, '>=')
->condition('reservation_date', $latest_date, '<=')
@ -1032,7 +1027,7 @@ function reserve_yyyymmdd($month, $day) {
*/
function reserve_get_reserve_bundles() {
$bundles = array();
$fieldmap = \Drupal::entityManager()->getFieldMap();
$fieldmap = \Drupal::service('entity_field.manager')->getFieldMap();
foreach ($fieldmap as $entity_type => $typedef) {
foreach ($typedef as $field) {
if ($field['type'] == 'reserve_category') {
@ -1050,7 +1045,7 @@ function reserve_get_reserve_bundles() {
* OR specific field name if $ebundle is provided (e.g. node.room)
*/
function reserve_category_fields($ebundle = NULL) {
$fieldmap = \Drupal::entityManager()->getFieldMap();
$fieldmap = \Drupal::service('entity_field.manager')->getFieldMap();
$fields = [];
foreach ($fieldmap as $entity_type => $typedef) {
foreach ($typedef as $name => $field) {
@ -1071,8 +1066,9 @@ function reserve_category_fields($ebundle = NULL) {
function ebundle_split($ebundle, $part) {
$ebits = explode('.', $ebundle);
if ($part == 'type') return $ebits[0];
if ($part == 'bundle') return $ebits[1];
if ($part == 'type' && isset($ebits[0])) return $ebits[0];
if ($part == 'bundle' && isset($ebits[1])) return $ebits[1];
return NULL;
}
/*
@ -1097,7 +1093,7 @@ function reserve_which_year($month, $day) {
// determine if this year or next year
$yearnow = date('Y');
$absdaynow = date('z');
$absdaydefault = date('z', mktime(0, 0, 0, $month, $day, $yearnow));
$absdaydefault = date('z', mktime(0, 0, 0, (int)$month, (int)$day, $yearnow));
if ($absdaynow > $absdaydefault) {
$year = $yearnow + 1;
}
@ -1112,7 +1108,7 @@ function reserve_which_year($month, $day) {
* used for Allowed Values for Reservation.reservable_content_type field
*/
function reserve_site_entity_types() {
$types = \Drupal::entityManager()->getEntityTypeLabels(TRUE);
$types = \Drupal::service('entity_type.repository')->getEntityTypeLabels(TRUE);
return $types['Content'];
}
@ -1129,4 +1125,4 @@ function reserve_get_ebundle_category_field($ebundle) {
return $field;
}
}
}
}

2
reserve.info.yml

@ -1,8 +1,8 @@
name: Reserve
type: module
description: Reservation system.
core: 8.x
package: Reserve
core_version_requirement: ^9.5 || ^10
dependencies:
- drupal:views
- 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_RESET_CONFIRMATION_MSG', t('Configuration settings have been reset to their default values'));
module_load_include('inc', 'reserve', 'reserve');
module_load_include('inc', 'reserve', 'reserve.series');
module_load_include('inc', 'reserve', 'reservation');
include(dirname(__FILE__) . '/reserve.inc');
include(dirname(__FILE__) . '/reserve.series.inc');
include(dirname(__FILE__) . '/reservation.inc');
$GLOBALS['debug'] = false;

44
reserve.series.inc

@ -1,4 +1,4 @@
<?php
<?php
/**
* Reservation CRUD for supporting Series
@ -36,9 +36,10 @@ function reserve_reserve_reservation_insert($entity) {
$length = $entity->reservation_length->getString();
$rid = $entity->reservable_id->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));
$msg = '';
switch ($repeat_type) {
// every day until....
@ -47,7 +48,7 @@ function reserve_reserve_reservation_insert($entity) {
$back = '-1 day';
$msg = t('You have booked every day from %start until %end', array('%start' => $start_yyyy_mm_dd, '%end' => $end));
break;
// this day of the week until..
case 2:
$skip = '+7 day';
@ -69,7 +70,7 @@ function reserve_reserve_reservation_insert($entity) {
$failed = array();
while (strtotime($date) <= strtotime($back, strtotime($end))) {
$date = date('Y-m-d', strtotime($skip, strtotime($date)));
// 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
if (reserve_is_slot_free($rid, $ebundle, $date, $time, $length)) {
@ -85,12 +86,12 @@ function reserve_reserve_reservation_insert($entity) {
// lets spit out some useful msgs
// first clear the msg stating we just created the reservation entity
drupal_get_messages('status');
drupal_set_message(t('Your reservation series has been booked.'));
drupal_set_message($msg);
\Drupal::messenger()->addStatus('status');
\Drupal::messenger()->addStatus(t('Your reservation series has been booked.'));
\Drupal::messenger()->addStatus($msg);
if (count($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)));
}
}
@ -110,24 +111,26 @@ function reserve_reserve_reservation_update($entity) {
}
$sid = $entity->reservation_series_id->getString();
// if not part of a Series or special single only url -> do nothing
if (!$sid || isset($_GET['single'])) {
return;
}
// reservation details
$start = $entity->reservation_date->getString();
$time = $entity->reservation_time->getString();
$length = $entity->reservation_length->getString();
$rid = $entity->reservable_id->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();
// grab all reservations in this series except the one being submitted
$ids = \Drupal::service('entity.query')
->get('reserve_reservation')
$ids = \Drupal::service('entity_type.manager')
->getStorage('reserve_reservation')->getQuery()
->accessCheck(TRUE)
->condition('status', TRUE)
->condition('reservation_series_id', $sid)
->condition('id', $entity->id(), '!=')
@ -156,11 +159,11 @@ function reserve_reserve_reservation_update($entity) {
}
// 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)) {
$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 +182,9 @@ function reserve_reserve_reservation_delete($entity) {
function _reserve_series_delete($entity) {
$sid = $entity->get('reservation_series_id')->getString();
// grab all reservations in this series
$ids = \Drupal::service('entity.query')
->get('reserve_reservation')
$ids = \Drupal::service('entity_type.manager')
->getStorage('reserve_reservation')->getQuery()
->accessCheck(TRUE)
->condition('reservation_series_id', $sid)
->execute();
$results = \Drupal::entityTypeManager()->getStorage('reserve_reservation')->loadMultiple($ids);
@ -188,5 +192,5 @@ function _reserve_series_delete($entity) {
$result->delete();
}
$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)));
}

41
src/Controller/CalendarController.php

@ -1,6 +1,7 @@
<?php
namespace Drupal\reserve\Controller;
use Drupal\field\Entity\FieldConfig;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Drupal\Core\Link;
@ -36,13 +37,17 @@ class CalendarController extends ControllerBase {
public function calendarTitle($ebundle) {
$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) {
$config = \Drupal::config('reserve.settings');
// likely no need for this as not used anywhere else; but maybe for external modules
global $yyyy_mmdd;
//$entity_type = ebundle_split($ebundle, 'type');
//$bundle = ebundle_split($ebundle, 'bundle');
@ -57,7 +62,7 @@ class CalendarController extends ControllerBase {
// if no Categories left; we should not bother with the rest of this
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 '';
}
@ -67,15 +72,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
// allowable reservation window, then set the current day as the selected day.
$yyyy_mmdd = $dates[0]['yyyymmdd'];
$day_selected = false;
foreach ($dates as $day) {
if ($day['selected']) {
$yyyy_mmdd = $day['yyyymmdd'];
$day_selected = TRUE;
}
}
if ($yyyy_mmdd == $dates[0]['yyyymmdd']) {
$dates[0]['selected'] = 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
//$_SESSION['reservations_current_day'] = $yyyy_mmdd;
@ -171,8 +183,8 @@ class CalendarController extends ControllerBase {
}
$results = array();
$ids = \Drupal::service('entity.query')
->get('reserve_reservation')
$ids = \Drupal::service('entity_type.manager')
->getStorage('reserve_reservation')->getQuery()
->condition('status', TRUE)
->condition('reservation_date', $yyyy_mmdd . '%', 'like')
->condition('reservation_ebundle', $ebundle)
@ -223,9 +235,13 @@ class CalendarController extends ControllerBase {
// add in pre/post buffer for setup/takedown (rev 7.x-1.3+)
// - if the slot is part of buffer we add "setup" to class
// - if we don't have admin rights; we also mark it as booked so no one can book in these slots
$category = $categories[$entities[$rid]->$category_field->getString()];
$preslots = $category['prebuffer'] / 30;
$postslots = $category['postbuffer'] / 30;
$preslots = 0;
$postslots = 0;
if(isset($entities[$rid])) {
$category = $categories[$entities[$rid]->$category_field->getString()];
$preslots = $category['prebuffer'] / 30;
$postslots = $category['postbuffer'] / 30;
}
$startkey = array_search($reservations[$rid][$time]['time'], $times);
$endkey = $startkey + $time_slots;
$k = $startkey - $preslots;
@ -319,7 +335,7 @@ class CalendarController extends ControllerBase {
$extended = \Drupal::currentUser()->hasPermission('add reservations extended');
$config = \Drupal::config('reserve.settings');
$category_field = reserve_category_fields($ebundle);
$clearimg = '<img src="' . base_path() . drupal_get_path('module', 'reserve') . '/images/clear.png" />';
$clearimg = '<img src="' . base_path() . \Drupal::service('extension.list.module')->getPath('reserve') . '/images/clear.png" />';
$modal = ['attributes' => [
'class' => ['use-ajax'],
'data-dialog-type' => 'modal',
@ -356,12 +372,12 @@ class CalendarController extends ControllerBase {
$variables['#calendar-text'] = $config->get('calendar_text');
$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.');
$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['#arrow'] = base_path() . \Drupal::service('extension.list.module')->getPath('reserve') . '/images/arrow-icon.png';
$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');
$field = reserve_category_fields($ebundle);
$fconfig = \Drupal\field\Entity\FieldConfig::loadByName($entity_type, $bundle, $field)->getSettings();
$fconfig = FieldConfig::loadByName($entity_type, $bundle, $field)->getSettings();
$variables['#calendar_header'] = $fconfig['calendar_header'];
$variables['#reservation_instructions'] = $fconfig['reservation_instructions'];
@ -494,7 +510,8 @@ class CalendarController extends ControllerBase {
// The time slot has a reservation that can be edited by the current user.
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' : '';
if ($viewable_class == 'viewable') {
$options = array_merge_recursive($modal, array(

12
src/Controller/ReservePermissions.php

@ -4,7 +4,7 @@
namespace Drupal\reserve\Controller;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;
@ -13,19 +13,19 @@ class ReservePermissions implements ContainerInjectionInterface {
use StringTranslationTrait;
/**
* The entity manager.
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityManagerInterface
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityManager;
/**
* Constructs a TaxonomyViewsIntegratorPermissions instance.
*
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_manager
* The entity manager.
*/
public function __construct(EntityManagerInterface $entity_manager) {
public function __construct(EntityTypeManagerInterface $entity_manager) {
$this->entityManager = $entity_manager;
}
@ -33,7 +33,7 @@ class ReservePermissions implements ContainerInjectionInterface {
* {@inheritdoc}
*/
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) {
// Display result.
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) {
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(),
]));
break;
default:
drupal_set_message($this->t('Saved the %label Reservation Category.', [
\Drupal::messenger()->addStatus($this->t('Saved the %label Reservation Category.', [
'%label' => $entity->label(),
]));
}

3
src/Form/ReserveDailyHoursForm.php

@ -5,7 +5,6 @@ namespace Drupal\reserve\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
module_load_include('inc', 'reserve', 'reserve.admin');
/**
* Class ReserveCategorySettingsForm.
@ -245,6 +244,6 @@ class ReserveDailyHoursForm extends ConfigFormBase {
$this->config('reserve.monthly_hours')
->set($yyyy_mm, $updated_mo_hours)
->save();
drupal_set_message($confirmation);
\Drupal::messenger()->addStatus($confirmation);
}
}

9
src/Form/ReserveDefaultHoursForm.php

@ -5,8 +5,6 @@ namespace Drupal\reserve\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
module_load_include('inc', 'reserve', 'reserve.admin');
/**
* Class ReserveCategorySettingsForm.
*
@ -235,7 +233,6 @@ class ReserveDefaultHoursForm extends ConfigFormBase {
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$values = $form_state->getValues();
$default_hours = array();
if ($form_state->getTriggeringElement()['#name'] == 'save') {
for ($day = 0; $day < 7; $day++) {
@ -244,7 +241,7 @@ class ReserveDefaultHoursForm extends ConfigFormBase {
$default_hours[] = $values['day_' . $day]['second_shift_open_' . $day];
$default_hours[] = $values['day_' . $day]['second_shift_close_' . $day];
}
$confirmation = t(RESERVE_SAVE_CONFIRMATION_MSG);
$confirmation = RESERVE_SAVE_CONFIRMATION_MSG;
}
if ($form_state->getTriggeringElement()['#name'] == 'reset') {
for ($day = 0; $day < 7; $day++) {
@ -296,13 +293,13 @@ class ReserveDefaultHoursForm extends ConfigFormBase {
$this->config('reserve.default_hours')
->set('data', $default_hours)
->save();
drupal_set_message($confirmation);
\Drupal::messenger()->addStatus ($confirmation);
// save updated monthly override hours
$this->config('reserve.monthly_hours')
->set('data', $monthly_hours)
->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) {
case SAVED_NEW:
drupal_set_message($this->t('Created the %label Reservation.', [
\Drupal::messenger()->addStatus ($this->t('Created the %label Reservation.', [
'%label' => $entity->label(),
]));
break;
default:
drupal_set_message($this->t('Saved the %label Reservation.', [
\Drupal::messenger()->addStatus($this->t('Saved the %label Reservation.', [
'%label' => $entity->label(),
]));
}

8
src/Form/ReserveSettingsForm.php

@ -88,7 +88,7 @@ class ReserveSettingsForm extends ConfigFormBase {
'#type' => 'select',
'#options' => $options,
'#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.'),
);
@ -97,7 +97,7 @@ class ReserveSettingsForm extends ConfigFormBase {
'#type' => 'select',
'#options' => $options,
'#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.'),
);
@ -114,7 +114,7 @@ class ReserveSettingsForm extends ConfigFormBase {
'#title' => t('Time to show on calendar before/after open slots'),
'#type' => 'select',
'#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('advanced_booking_admin') : 3,
'#default_value' => $config->get('show_before_after_hours') ? $config->get('show_before_after_hours') : 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.'),
);
@ -177,7 +177,7 @@ class ReserveSettingsForm extends ConfigFormBase {
$this->config('reserve.settings')->set($key, $value);
}
$this->config('reserve.settings')->save();
drupal_set_message(RESERVE_SAVE_CONFIRMATION_MSG);
\Drupal::messenger()->addStatus(RESERVE_SAVE_CONFIRMATION_MSG);
}
}

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

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

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

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

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

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

6
src/ReserveCategoryListBuilder.php

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

3
src/ReserveReservationAccessControlHandler.php

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

46
src/Tests/LoadTest.php

@ -1,46 +0,0 @@
<?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