diff --git a/reserve.inc b/reserve.inc index efa7c6b..2f159e1 100644 --- a/reserve.inc +++ b/reserve.inc @@ -1,4 +1,5 @@ getSettings(); + $fconfig = FieldConfig::loadByName($entity_type, $bundle, $field)->getSettings(); $ids = array_filter($fconfig['categories']); } else { @@ -353,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]; @@ -696,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'], @@ -705,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; } @@ -923,7 +923,7 @@ 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) { - $user = \Drupal::currentUser(); + $user = \Drupal::currentUser(); $config = \Drupal::config('reserve.settings'); $max = $config->get('reservations_per_day'); if (!$max) { diff --git a/reserve.info.yml b/reserve.info.yml index 6975375..87d3ad7 100644 --- a/reserve.info.yml +++ b/reserve.info.yml @@ -2,7 +2,7 @@ name: Reserve type: module description: Reservation system. package: Reserve -core_version_requirement: ^8 || ^9 +core_version_requirement: ^9.5 || ^10 dependencies: - drupal:views - drupal:options diff --git a/reserve.module b/reserve.module index d7713b8..137c534 100644 --- a/reserve.module +++ b/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; diff --git a/src/Controller/CalendarController.php b/src/Controller/CalendarController.php index 5db5e14..56aeac3 100644 --- a/src/Controller/CalendarController.php +++ b/src/Controller/CalendarController.php @@ -1,6 +1,7 @@ hasPermission('add reservations extended'); $config = \Drupal::config('reserve.settings'); $category_field = reserve_category_fields($ebundle); - $clearimg = ''; + $clearimg = ''; $modal = ['attributes' => [ 'class' => ['use-ajax'], 'data-dialog-type' => 'modal', @@ -371,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['#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']; diff --git a/src/Form/ReserveDailyHoursForm.php b/src/Form/ReserveDailyHoursForm.php index a380586..0dec99f 100644 --- a/src/Form/ReserveDailyHoursForm.php +++ b/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. diff --git a/src/Form/ReserveDefaultHoursForm.php b/src/Form/ReserveDefaultHoursForm.php index 98b744c..cb35b0c 100644 --- a/src/Form/ReserveDefaultHoursForm.php +++ b/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++) { diff --git a/src/Form/ReserveSettingsForm.php b/src/Form/ReserveSettingsForm.php index 701523b..393ab73 100644 --- a/src/Form/ReserveSettingsForm.php +++ b/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.'), ); diff --git a/src/Plugin/Field/FieldFormatter/ReserveCategoryFormatter.php b/src/Plugin/Field/FieldFormatter/ReserveCategoryFormatter.php index 7eb2f30..b19fa81 100644 --- a/src/Plugin/Field/FieldFormatter/ReserveCategoryFormatter.php +++ b/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', diff --git a/src/Plugin/Field/FieldWidget/ReserveCategorySelect.php b/src/Plugin/Field/FieldWidget/ReserveCategorySelect.php index 7644242..7b73085 100644 --- a/src/Plugin/Field/FieldWidget/ReserveCategorySelect.php +++ b/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; @@ -30,7 +31,7 @@ class ReserveCategorySelect extends WidgetBase { $set = $items->getSettings()['categories']; $ids = \Drupal::entityQuery('reserve_category')->sort('name', 'ASC')->execute(); - $categories = \Drupal\reserve\Entity\ReserveCategory::loadMultiple($ids); + $categories = ReserveCategory::loadMultiple($ids); $options = array(); foreach ($categories as $key => $cat) { if (!in_array($key, $set)) continue; diff --git a/src/Tests/LoadTest.php b/src/Tests/LoadTest.php deleted file mode 100644 index f4fb0fd..0000000 --- a/src/Tests/LoadTest.php +++ /dev/null @@ -1,46 +0,0 @@ -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('')); - $this->assertResponse(200); - } - -}