Browse Source

initial work on d9 port

d9
ppound 4 years ago
parent
commit
51e96315c9
  1. 37
      reserve.inc
  2. 1
      reserve.info.yml
  3. 24
      reserve.series.inc
  4. 10
      src/Controller/CalendarController.php
  5. 12
      src/Controller/ReservePermissions.php
  6. 2
      src/Form/CalendarDatePicker.php
  7. 4
      src/Form/ReserveCategoryForm.php
  8. 2
      src/Form/ReserveDailyHoursForm.php
  9. 4
      src/Form/ReserveDefaultHoursForm.php
  10. 4
      src/Form/ReserveReservationForm.php
  11. 2
      src/Form/ReserveSettingsForm.php
  12. 6
      src/ReserveCategoryListBuilder.php
  13. 6
      src/ReserveReservationListBuilder.php

37
reserve.inc

@ -25,11 +25,13 @@ function reserve_categories($ebundle = null) {
$ids = array_filter($fconfig['categories']);
}
else {
$ids = Drupal::service('entity.query')
->get('reserve_category')
->condition('status', TRUE)
$query = \Drupal::service('entity_type.manager')->getStorage('reserve_category')->getQuery();
$ids = $query->condition('status', TRUE)->execute();
//$ids = Drupal::service('entity.query')
//->get('reserve_category')
//->condition('status', TRUE)
//->sort('reserve_display_order', 'ASC')
->execute();
//->execute();
}
$cats = \Drupal::entityTypeManager()->getStorage('reserve_category')->loadMultiple($ids);
@ -59,9 +61,11 @@ 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);
//$query = Drupal::service('entity.query')
// ->get($entity_type)
// ->condition('status', TRUE);
if ($entity_type != $bundle) {
$query->condition('type', $bundle);
@ -805,9 +809,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()
//$query = Drupal::service('entity.query')
->condition('reservation_date', $date . '%', 'LIKE')
->condition('reservation_time', $start_time)
->condition('reservable_id', $rid)
@ -936,8 +939,8 @@ function reserve_daily_max_exceeded($yyyy_mmdd) {
$record_count = 0;
if ($user->uid) {
$ids = \Drupal::service('entity.query')
->get('reserve_reservation')
$ids = \Drupal::service('entity_type.manager')->getStorage('reserve_reservation')->getQuery()
//$ids = \Drupal::service('entity.query')
->condition('user_id', $user->id)
->condition('reservation_date', 'value', $yyyy_mmdd . '%', 'like')
->execute();
@ -970,9 +973,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()
//$ids = \Drupal::service('entity.query')
// ->get('reserve_reservation')
->condition('user_id', $user->id())
->condition('reservation_date', $earliest_date, '>=')
->condition('reservation_date', $latest_date, '<=')
@ -1032,7 +1035,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 +1053,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) {

1
reserve.info.yml

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

24
reserve.series.inc

@ -85,12 +85,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)));
}
}
@ -126,8 +126,9 @@ function reserve_reserve_reservation_update($entity) {
$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()
//$ids = \Drupal::service('entity.query')
// ->get('reserve_reservation')
->condition('status', TRUE)
->condition('reservation_series_id', $sid)
->condition('id', $entity->id(), '!=')
@ -156,10 +157,10 @@ 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 +180,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()
//$ids = \Drupal::service('entity.query')
// ->get('reserve_reservation')
->condition('reservation_series_id', $sid)
->execute();
$results = \Drupal::entityTypeManager()->getStorage('reserve_reservation')->loadMultiple($ids);
@ -188,5 +190,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)));
}

10
src/Controller/CalendarController.php

@ -57,7 +57,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 '';
}
@ -171,8 +171,9 @@ class CalendarController extends ControllerBase {
}
$results = array();
$ids = \Drupal::service('entity.query')
->get('reserve_reservation')
$ids = \Drupal::service('entity_type.manager')->getStorage('reserve_reservation')->getQuery()
//$ids = \Drupal::service('entity.query')
// ->get('reserve_reservation')
->condition('status', TRUE)
->condition('reservation_date', $yyyy_mmdd . '%', 'like')
->condition('reservation_ebundle', $ebundle)
@ -357,7 +358,8 @@ class CalendarController extends ControllerBase {
$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['#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');
$field = reserve_category_fields($ebundle);

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(),
]));
}

2
src/Form/ReserveDailyHoursForm.php

@ -245,6 +245,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);
}
}

4
src/Form/ReserveDefaultHoursForm.php

@ -296,13 +296,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(),
]));
}

2
src/Form/ReserveSettingsForm.php

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

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

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

Loading…
Cancel
Save