Compare commits

..

No commits in common. 'd10-dev' and '8.x-1.x' have entirely different histories.

  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: allowed_values:
- -
value: 30 value: 30
label: '30' label: 30
- -
value: 60 value: 60
label: '60' label: 60
- -
value: 90 value: 90
label: '90' label: 90
- -
value: 180 value: 180
label: '180' label: 180
- -
value: 360 value: 360
label: '360' label: 360
module: options module: options
locked: true locked: true
cardinality: 1 cardinality: 1

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

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

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

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

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

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

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

@ -17,7 +17,7 @@ dependencies:
- reserve - reserve
- views_bulk_operations - views_bulk_operations
_core: _core:
default_config_hash: Fpw3XOpA8QhT5E7YrASas4PrG75lo7-SVSpwa9dvMYA default_config_hash: qtxsAzivRyJgkwE59iiTdA2ucLdj2OtA9MwdI-OUYzI
id: reservations id: reservations
label: Reservations label: Reservations
module: views module: views
@ -25,14 +25,165 @@ description: ''
tag: '' tag: ''
base_table: reserve_reservation_field_data base_table: reserve_reservation_field_data
base_field: id base_field: id
core: 8.x
display: display:
default: default:
display_plugin: default
id: default id: default
display_title: Master display_title: Master
display_plugin: default
position: 0 position: 0
display_options: display_options:
title: 'My Rese' 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
fields: fields:
views_bulk_operations_bulk_form: views_bulk_operations_bulk_form:
id: views_bulk_operations_bulk_form id: views_bulk_operations_bulk_form
@ -41,8 +192,7 @@ display:
relationship: none relationship: none
group_type: group group_type: group
admin_label: '' admin_label: ''
plugin_id: views_bulk_operations_bulk_form label: ''
label: 'Views bulk operations'
exclude: false exclude: false
alter: alter:
alter_text: false alter_text: false
@ -75,7 +225,7 @@ display:
element_class: '' element_class: ''
element_label_type: '' element_label_type: ''
element_label_class: '' element_label_class: ''
element_label_colon: true element_label_colon: false
element_wrapper_type: '' element_wrapper_type: ''
element_wrapper_class: '' element_wrapper_class: ''
element_default_classes: true element_default_classes: true
@ -88,11 +238,16 @@ display:
form_step: true form_step: true
buttons: false buttons: false
action_title: Action action_title: Action
clear_on_exposed: true
force_selection_info: false
selected_actions: selected_actions:
- views_bulk_edit: views_bulk_edit
action_id: views_bulk_operations_delete_entity 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
name: name:
id: name id: name
table: reserve_reservation_field_data table: reserve_reservation_field_data
@ -100,9 +255,6 @@ display:
relationship: none relationship: none
group_type: group group_type: group
admin_label: '' admin_label: ''
entity_type: null
entity_field: name
plugin_id: field
label: Group label: Group
exclude: false exclude: false
alter: alter:
@ -158,6 +310,9 @@ display:
multi_type: separator multi_type: separator
separator: ', ' separator: ', '
field_api_classes: false field_api_classes: false
entity_type: null
entity_field: name
plugin_id: field
reservation_date: reservation_date:
id: reservation_date id: reservation_date
table: reserve_reservation__reservation_date table: reserve_reservation__reservation_date
@ -165,7 +320,6 @@ display:
relationship: none relationship: none
group_type: group group_type: group
admin_label: '' admin_label: ''
plugin_id: field
label: When label: When
exclude: false exclude: false
alter: alter:
@ -222,6 +376,7 @@ display:
multi_type: separator multi_type: separator
separator: ', ' separator: ', '
field_api_classes: false field_api_classes: false
plugin_id: field
reservation_time: reservation_time:
id: reservation_time id: reservation_time
table: reserve_reservation__reservation_time table: reserve_reservation__reservation_time
@ -229,7 +384,6 @@ display:
relationship: none relationship: none
group_type: group group_type: group
admin_label: '' admin_label: ''
plugin_id: field
label: '' label: ''
exclude: false exclude: false
alter: alter:
@ -285,6 +439,7 @@ display:
multi_type: separator multi_type: separator
separator: ', ' separator: ', '
field_api_classes: false field_api_classes: false
plugin_id: field
reservation_length: reservation_length:
id: reservation_length id: reservation_length
table: reserve_reservation__reservation_length table: reserve_reservation__reservation_length
@ -292,7 +447,6 @@ display:
relationship: none relationship: none
group_type: group group_type: group
admin_label: '' admin_label: ''
plugin_id: field
label: '' label: ''
exclude: false exclude: false
alter: alter:
@ -347,6 +501,7 @@ display:
multi_type: separator multi_type: separator
separator: ', ' separator: ', '
field_api_classes: false field_api_classes: false
plugin_id: field
reservation_private: reservation_private:
id: reservation_private id: reservation_private
table: reserve_reservation__reservation_private table: reserve_reservation__reservation_private
@ -354,7 +509,6 @@ display:
relationship: none relationship: none
group_type: group group_type: group
admin_label: '' admin_label: ''
plugin_id: field
label: Private label: Private
exclude: false exclude: false
alter: alter:
@ -400,8 +554,8 @@ display:
type: boolean type: boolean
settings: settings:
format: default format: default
format_custom_false: ''
format_custom_true: '' format_custom_true: ''
format_custom_false: ''
group_column: value group_column: value
group_columns: { } group_columns: { }
group_rows: true group_rows: true
@ -412,6 +566,7 @@ display:
multi_type: separator multi_type: separator
separator: ', ' separator: ', '
field_api_classes: false field_api_classes: false
plugin_id: field
reservation_repeat_type: reservation_repeat_type:
id: reservation_repeat_type id: reservation_repeat_type
table: reserve_reservation__reservation_repeat_type table: reserve_reservation__reservation_repeat_type
@ -419,7 +574,6 @@ display:
relationship: none relationship: none
group_type: group group_type: group
admin_label: '' admin_label: ''
plugin_id: field
label: Repeating label: Repeating
exclude: false exclude: false
alter: alter:
@ -474,6 +628,7 @@ display:
multi_type: separator multi_type: separator
separator: ', ' separator: ', '
field_api_classes: false field_api_classes: false
plugin_id: field
reservation_repeat_until: reservation_repeat_until:
id: reservation_repeat_until id: reservation_repeat_until
table: reserve_reservation__reservation_repeat_until table: reserve_reservation__reservation_repeat_until
@ -481,7 +636,6 @@ display:
relationship: none relationship: none
group_type: group group_type: group
admin_label: '' admin_label: ''
plugin_id: field
label: '' label: ''
exclude: false exclude: false
alter: alter:
@ -538,6 +692,7 @@ display:
multi_type: separator multi_type: separator
separator: ', ' separator: ', '
field_api_classes: false field_api_classes: false
plugin_id: field
reservable_content_type: reservable_content_type:
id: reservable_content_type id: reservable_content_type
table: reserve_reservation__reservable_content_type table: reserve_reservation__reservable_content_type
@ -545,7 +700,6 @@ display:
relationship: none relationship: none
group_type: group group_type: group
admin_label: '' admin_label: ''
plugin_id: field
label: 'Reservation Type' label: 'Reservation Type'
exclude: false exclude: false
alter: alter:
@ -600,6 +754,7 @@ display:
multi_type: separator multi_type: separator
separator: ', ' separator: ', '
field_api_classes: false field_api_classes: false
plugin_id: field
reservation_ebundle: reservation_ebundle:
id: reservation_ebundle id: reservation_ebundle
table: reserve_reservation__reservation_ebundle table: reserve_reservation__reservation_ebundle
@ -607,7 +762,6 @@ display:
relationship: none relationship: none
group_type: group group_type: group
admin_label: '' admin_label: ''
plugin_id: field
label: Ebundle label: Ebundle
exclude: false exclude: false
alter: alter:
@ -663,6 +817,7 @@ display:
multi_type: separator multi_type: separator
separator: ', ' separator: ', '
field_api_classes: false field_api_classes: false
plugin_id: field
operations: operations:
id: operations id: operations
table: reserve_reservation table: reserve_reservation
@ -670,8 +825,6 @@ display:
relationship: none relationship: none
group_type: group group_type: group
admin_label: '' admin_label: ''
entity_type: reserve_reservation
plugin_id: entity_operations
label: Operations label: Operations
exclude: false exclude: false
alter: alter:
@ -714,73 +867,8 @@ display:
empty_zero: false empty_zero: false
hide_alter_empty: true hide_alter_empty: true
destination: true destination: true
pager: entity_type: reserve_reservation
type: full plugin_id: entity_operations
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: filters:
name: name:
id: name id: name
@ -789,9 +877,6 @@ display:
relationship: none relationship: none
group_type: group group_type: group
admin_label: '' admin_label: ''
entity_type: reserve_reservation
entity_field: name
plugin_id: string
operator: contains operator: contains
value: '' value: ''
group: 1 group: 1
@ -802,8 +887,6 @@ display:
description: '' description: ''
use_operator: false use_operator: false
operator: name_op operator: name_op
operator_limit_selection: false
operator_list: { }
identifier: name identifier: name
required: false required: false
remember: false remember: false
@ -824,6 +907,9 @@ display:
default_group: All default_group: All
default_group_multiple: { } default_group_multiple: { }
group_items: { } group_items: { }
entity_type: reserve_reservation
entity_field: name
plugin_id: string
reservation_date_value: reservation_date_value:
id: reservation_date_value id: reservation_date_value
table: reserve_reservation__reservation_date table: reserve_reservation__reservation_date
@ -831,7 +917,6 @@ display:
relationship: none relationship: none
group_type: group group_type: group
admin_label: '' admin_label: ''
plugin_id: datetime
operator: '=' operator: '='
value: value:
min: '' min: ''
@ -846,8 +931,6 @@ display:
description: '' description: ''
use_operator: false use_operator: false
operator: reservation_date_value_op operator: reservation_date_value_op
operator_limit_selection: false
operator_list: { }
identifier: reservation_date_value identifier: reservation_date_value
required: false required: false
remember: false remember: false
@ -868,122 +951,45 @@ display:
default_group: All default_group: All
default_group_multiple: { } default_group_multiple: { }
group_items: { } 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: filter_groups:
operator: OR operator: OR
groups: groups:
1: AND 1: AND
style: title: 'My Rese'
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: cache_metadata:
max-age: 0 max-age: 0
contexts: contexts:
@ -1001,26 +1007,26 @@ display:
- 'config:field.storage.reserve_reservation.reservation_repeat_until' - 'config:field.storage.reserve_reservation.reservation_repeat_until'
- 'config:field.storage.reserve_reservation.reservation_time' - 'config:field.storage.reserve_reservation.reservation_time'
page_1: page_1:
display_plugin: page
id: page_1 id: page_1
display_title: 'Manage (admin)' display_title: 'Manage (admin)'
display_plugin: page
position: 1 position: 1
display_options: display_options:
title: 'Manage Reservations'
defaults:
title: false
display_description: ''
display_extenders: { } display_extenders: { }
path: admin/structure/reservations/reserve_reservations/manage-reservations path: admin/structure/reservations/reserve_reservations/manage-reservations
menu: menu:
type: normal type: normal
title: 'Manage Reservations' title: 'Manage Reservations'
description: '' description: ''
weight: 0
expanded: false expanded: false
menu_name: admin
parent: entity.reserve_reservation.collection parent: entity.reserve_reservation.collection
weight: 0
context: '0' context: '0'
menu_name: admin
display_description: ''
title: 'Manage Reservations'
defaults:
title: false
cache_metadata: cache_metadata:
max-age: 0 max-age: 0
contexts: contexts:
@ -1038,12 +1044,14 @@ display:
- 'config:field.storage.reserve_reservation.reservation_repeat_until' - 'config:field.storage.reserve_reservation.reservation_repeat_until'
- 'config:field.storage.reserve_reservation.reservation_time' - 'config:field.storage.reserve_reservation.reservation_time'
page_2: page_2:
display_plugin: page
id: page_2 id: page_2
display_title: 'My Reservations' display_title: 'My Reservations'
display_plugin: page
position: 2 position: 2
display_options: display_options:
title: 'My Reservations' display_extenders: { }
display_description: ''
path: reserve/%ebundle/my-reservations
arguments: arguments:
reservation_ebundle_value: reservation_ebundle_value:
id: reservation_ebundle_value id: reservation_ebundle_value
@ -1052,7 +1060,6 @@ display:
relationship: none relationship: none
group_type: group group_type: group
admin_label: '' admin_label: ''
plugin_id: string
default_action: default default_action: default
exception: exception:
value: all value: all
@ -1068,8 +1075,8 @@ display:
summary_options: summary_options:
base_path: '' base_path: ''
count: true count: true
override: false
items_per_page: 25 items_per_page: 25
override: false
summary: summary:
sort_order: asc sort_order: asc
number_of_records: 0 number_of_records: 0
@ -1085,6 +1092,7 @@ display:
path_case: none path_case: none
transform_dash: false transform_dash: false
break_phrase: false break_phrase: false
plugin_id: string
user_id: user_id:
id: user_id id: user_id
table: reserve_reservation_field_data table: reserve_reservation_field_data
@ -1092,9 +1100,6 @@ display:
relationship: none relationship: none
group_type: group group_type: group
admin_label: '' admin_label: ''
entity_type: reserve_reservation
entity_field: user_id
plugin_id: numeric
default_action: default default_action: default
exception: exception:
value: all value: all
@ -1108,8 +1113,8 @@ display:
summary_options: summary_options:
base_path: '' base_path: ''
count: true count: true
override: false
items_per_page: 25 items_per_page: 25
override: false
summary: summary:
sort_order: asc sort_order: asc
number_of_records: 0 number_of_records: 0
@ -1121,21 +1126,22 @@ display:
validate_options: { } validate_options: { }
break_phrase: false break_phrase: false
not: false not: false
entity_type: reserve_reservation
entity_field: user_id
plugin_id: numeric
defaults: defaults:
title: false
arguments: false arguments: false
display_description: '' title: false
display_extenders: { }
path: reserve/%ebundle/my-reservations
menu: menu:
type: tab type: tab
title: 'My Reservations' title: 'My Reservations'
description: '' description: ''
weight: 0
expanded: false expanded: false
menu_name: main
parent: '' parent: ''
weight: 0
context: '0' context: '0'
menu_name: main
title: 'My Reservations'
cache_metadata: cache_metadata:
max-age: 0 max-age: 0
contexts: contexts:

77
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
@ -29,22 +28,6 @@ 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;
@ -78,20 +61,9 @@ 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';
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);
$entity = entity_load($entity_type, $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);
@ -99,10 +71,9 @@ function reserve_form_reserve_reservation_form_alter(array &$form, FormStateInte
$bundleName = $bundle_info[$entity->getEntityTypeId()][$entity->bundle()]['label']; $bundleName = $bundle_info[$entity->getEntityTypeId()][$entity->bundle()]['label'];
// 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']['#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));
@ -125,17 +96,12 @@ 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
// Lets not hide the length so mobile users can pick a length. $form['reservation_length']['#access'] = false;
//$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:
@ -158,7 +124,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 +132,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']);
@ -256,7 +222,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];
@ -265,33 +231,12 @@ 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);
}
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;
} }
/** /**
@ -304,4 +249,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);
} }

72
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,15 @@ 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') $ids = Drupal::service('entity.query')
->getStorage('reserve_category')->getQuery(); ->get('reserve_category')
$ids = $query->condition('status', TRUE)->accessCheck(FALSE)->execute(); ->condition('status', TRUE)
//->sort('reserve_display_order', 'ASC')
->execute();
} }
$cats = \Drupal::entityTypeManager()->getStorage('reserve_category')->loadMultiple($ids); $cats = \Drupal::entityTypeManager()->getStorage('reserve_category')->loadMultiple($ids);
@ -58,16 +59,16 @@ 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_type.manager') $query = Drupal::service('entity.query')
->getStorage($entity_type)->getQuery(); ->get($entity_type)
$query->condition('status', TRUE); ->condition('status', TRUE);
if ($entity_type != $bundle) { if ($entity_type != $bundle) {
$query->condition('type', $bundle); $query->condition('type', $bundle);
} }
//->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);
@ -278,7 +279,7 @@ function reserve_hours($option = NULL) {
} }
// convert display to 24:00 format if required // convert display to 24:00 format if required
if ($config->get('hour_format') == 1) { if ($config->get('reserve_hour_format')) {
$display = date('H:i', strtotime($display)); $display = date('H:i', strtotime($display));
} }
@ -354,8 +355,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 +698,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 +707,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;
} }
@ -803,8 +805,9 @@ 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')
->getStorage('reserve_reservation')->getQuery() $query = Drupal::service('entity.query')
->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)
@ -923,22 +926,24 @@ 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(); global $user;
$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->id()) { if ($user->uid) {
$ids = \Drupal::service('entity_type.manager') $ids = \Drupal::service('entity.query')
->getStorage('reserve_reservation')->getQuery() ->get('reserve_reservation')
->accessCheck(FALSE) ->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;
} }
@ -965,9 +970,9 @@ 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')
->getStorage('reserve_reservation')->getQuery() $ids = \Drupal::service('entity.query')
->accessCheck(TRUE) ->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, '<=')
@ -1027,7 +1032,7 @@ function reserve_yyyymmdd($month, $day) {
*/ */
function reserve_get_reserve_bundles() { function reserve_get_reserve_bundles() {
$bundles = array(); $bundles = array();
$fieldmap = \Drupal::service('entity_field.manager')->getFieldMap(); $fieldmap = \Drupal::entityManager()->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') {
@ -1045,7 +1050,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::service('entity_field.manager')->getFieldMap(); $fieldmap = \Drupal::entityManager()->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) {
@ -1066,9 +1071,8 @@ 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' && isset($ebits[0])) return $ebits[0]; if ($part == 'type') return $ebits[0];
if ($part == 'bundle' && isset($ebits[1])) return $ebits[1]; if ($part == 'bundle') return $ebits[1];
return NULL;
} }
/* /*
@ -1093,7 +1097,7 @@ function reserve_which_year($month, $day) {
// determine if this year or next year // determine if this year or next year
$yearnow = date('Y'); $yearnow = date('Y');
$absdaynow = date('z'); $absdaynow = date('z');
$absdaydefault = date('z', mktime(0, 0, 0, (int)$month, (int)$day, $yearnow)); $absdaydefault = date('z', mktime(0, 0, 0, $month, $day, $yearnow));
if ($absdaynow > $absdaydefault) { if ($absdaynow > $absdaydefault) {
$year = $yearnow + 1; $year = $yearnow + 1;
} }
@ -1108,7 +1112,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::service('entity_type.repository')->getEntityTypeLabels(TRUE); $types = \Drupal::entityManager()->getEntityTypeLabels(TRUE);
return $types['Content']; return $types['Content'];
} }
@ -1125,4 +1129,4 @@ function reserve_get_ebundle_category_field($ebundle) {
return $field; return $field;
} }
} }
} }

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: ^9.5 || ^10
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;

44
reserve.series.inc

@ -1,4 +1,4 @@
<?php <?php
/** /**
* Reservation CRUD for supporting Series * Reservation CRUD for supporting Series
@ -36,10 +36,9 @@ 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 . '.' . \Drupal::entityTypeManager() $ebundle = $rtype . '.' . entity_load($rtype, $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 +47,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 +69,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)) {
@ -86,12 +85,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::messenger()->addStatus('status'); drupal_get_messages('status');
\Drupal::messenger()->addStatus(t('Your reservation series has been booked.')); drupal_set_message(t('Your reservation series has been booked.'));
\Drupal::messenger()->addStatus($msg); drupal_set_message($msg);
if (count($failed)) { if (count($failed)) {
$dates = Markup::create('<br>' . implode('<br>', $failed)); $dates = Markup::create('<br>' . implode('<br>', $failed));
\Drupal::messenger()->addWarning(t('The following dates were not booked due to scheduling conflicts: %dates', array('%dates' => $dates))); drupal_set_message(t('The following dates were not booked due to scheduling conflicts: %dates', array('%dates' => $dates)), 'warning');
} }
} }
@ -111,26 +110,24 @@ 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();
$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 . '.' . \Drupal::entityTypeManager() $ebundle = $rtype . '.' . entity_load($rtype, $rid)->bundle();
->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_type.manager') $ids = \Drupal::service('entity.query')
->getStorage('reserve_reservation')->getQuery() ->get('reserve_reservation')
->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(), '!=')
@ -159,11 +156,11 @@ function reserve_reserve_reservation_update($entity) {
} }
// lets spit out some useful msgs // lets spit out some useful msgs
\Drupal::messenger()->addStatus(t('Your reservation series has been modified.')); drupal_set_message(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::messenger()->addStatus(t('NOTE: The following dates did not have their length changed due to scheduling conflicts: %dates', array('%dates' => $dates))); drupal_set_message(t('NOTE: The following dates did not have their length changed due to scheduling conflicts: %dates', array('%dates' => $dates)), 'warning');
} }
} }
/** /**
@ -182,9 +179,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_type.manager') $ids = \Drupal::service('entity.query')
->getStorage('reserve_reservation')->getQuery() ->get('reserve_reservation')
->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 +188,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_set_message(t('The reservation series @title was deleted.', array('@title' => $title)));
} }

41
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;
@ -37,17 +36,13 @@ class CalendarController extends ControllerBase {
public function calendarTitle($ebundle) { public function calendarTitle($ebundle) {
$bundle = ebundle_split($ebundle, 'bundle'); $bundle = ebundle_split($ebundle, 'bundle');
$type = ebundle_split($ebundle, 'type'); return t('@bundle Calendar', array('@bundle' => ucwords($bundle)));
$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');
@ -62,7 +57,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::messenger()->addWarning(t('There are no configured Reserve Categories. Please contact the System Administrator')); drupal_set_message(t('There are no configured Reserve Categories. Please contact the System Administrator'), 'warning');
return ''; return '';
} }
@ -72,22 +67,15 @@ 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;
@ -183,8 +171,8 @@ class CalendarController extends ControllerBase {
} }
$results = array(); $results = array();
$ids = \Drupal::service('entity_type.manager') $ids = \Drupal::service('entity.query')
->getStorage('reserve_reservation')->getQuery() ->get('reserve_reservation')
->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)
@ -235,13 +223,9 @@ class CalendarController extends ControllerBase {
// add in pre/post buffer for setup/takedown (rev 7.x-1.3+) // 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 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 // - if we don't have admin rights; we also mark it as booked so no one can book in these slots
$preslots = 0; $category = $categories[$entities[$rid]->$category_field->getString()];
$postslots = 0; $preslots = $category['prebuffer'] / 30;
if(isset($entities[$rid])) { $postslots = $category['postbuffer'] / 30;
$category = $categories[$entities[$rid]->$category_field->getString()];
$preslots = $category['prebuffer'] / 30;
$postslots = $category['postbuffer'] / 30;
}
$startkey = array_search($reservations[$rid][$time]['time'], $times); $startkey = array_search($reservations[$rid][$time]['time'], $times);
$endkey = $startkey + $time_slots; $endkey = $startkey + $time_slots;
$k = $startkey - $preslots; $k = $startkey - $preslots;
@ -335,7 +319,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 +356,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'] = format_date(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'];
@ -510,8 +494,7 @@ 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 = \Drupal::entityTypeManager() $reservation = entity_load('reserve_reservation', $id);
->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\EntityTypeManagerInterface; use Drupal\Core\Entity\EntityManagerInterface;
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 type manager. * The entity manager.
* *
* @var \Drupal\Core\Entity\EntityTypeManagerInterface * @var \Drupal\Core\Entity\EntityManagerInterface
*/ */
protected $entityManager; protected $entityManager;
/** /**
* Constructs a TaxonomyViewsIntegratorPermissions instance. * Constructs a TaxonomyViewsIntegratorPermissions instance.
* *
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_manager * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager. * The entity manager.
*/ */
public function __construct(EntityTypeManagerInterface $entity_manager) { public function __construct(EntityManagerInterface $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_type.manager')); return new static($container->get('entity.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::messenger()->addStatus($key . ': ' . $value); drupal_set_message($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::messenger()->addStatus($this->t('Created the %label Reservation Category.', [ drupal_set_message($this->t('Created the %label Reservation Category.', [
'%label' => $entity->label(), '%label' => $entity->label(),
])); ]));
break; break;
default: default:
\Drupal::messenger()->addStatus($this->t('Saved the %label Reservation Category.', [ drupal_set_message($this->t('Saved the %label Reservation Category.', [
'%label' => $entity->label(), '%label' => $entity->label(),
])); ]));
} }

3
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.
@ -244,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::messenger()->addStatus($confirmation); drupal_set_message($confirmation);
} }
} }

9
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++) {
@ -293,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::messenger()->addStatus ($confirmation); drupal_set_message($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::messenger()->addStatus(t('Daily overrides updated with new defaults.')); drupal_set_message(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::messenger()->addStatus ($this->t('Created the %label Reservation.', [ drupal_set_message($this->t('Created the %label Reservation.', [
'%label' => $entity->label(), '%label' => $entity->label(),
])); ]));
break; break;
default: default:
\Drupal::messenger()->addStatus($this->t('Saved the %label Reservation.', [ drupal_set_message($this->t('Saved the %label Reservation.', [
'%label' => $entity->label(), '%label' => $entity->label(),
])); ]));
} }

8
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.'),
); );
@ -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::messenger()->addStatus(RESERVE_SAVE_CONFIRMATION_MSG); drupal_set_message(RESERVE_SAVE_CONFIRMATION_MSG);
} }
} }

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);
} }
} }

6
src/ReserveCategoryListBuilder.php

@ -6,7 +6,6 @@ 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.
@ -15,6 +14,7 @@ use Drupal\Core\Link;
*/ */
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'] = Link::fromTextAndUrl( $row['name'] = $this->l(
$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,9 +36,6 @@ 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,7 +6,6 @@ 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.
@ -15,6 +14,7 @@ use Drupal\Core\Link;
*/ */
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'] = Link::fromTextAndUrl( $row['name'] = $this->l(
$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);
} }

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