Skip to content

Commit

Permalink
Drupal 9 compatibility fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladyslav Solodovnyk committed Sep 21, 2021
1 parent 692f453 commit 12d3c53
Show file tree
Hide file tree
Showing 48 changed files with 257 additions and 233 deletions.
17 changes: 4 additions & 13 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,17 @@
"license": "GPL-2.0+",
"require": {
"cweagans/composer-patches": "~1.0",
"drupal/panelizer": "4.1",
"drupal/panelizer": "^4.4",
"drupal/panels": "^4.6",
"drupal/ckeditor_font": "^1.0",
"drupal/dynamic_entity_reference": "^1.7",
"drupal/duration_field": "^1.6"
"drupal/duration_field": "^2.0"
},
"minimum-stability": "dev",
"repositories": [
{
"type": "composer",
"url": "https://packages.drupal.org/8"
}
],
"extra": {
"patches": {
"drupal/duration_field": {
"2978206 - Undefined index: #states in drupal_process_states()": "https://www.drupal.org/files/issues/2018-06-08/2978206-2.patch"
},
"drupal/panels": {
"2895962 - Add \"methods\" to Panels IPE routes to support Drupal 8.4.0 / Symfony 3.x": "https://www.drupal.org/files/issues/panels-deprecate-method.patch"
}
}
}
]
}
3 changes: 2 additions & 1 deletion modules/ds_datetime_range/ds_datetime_range.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: Digital Signage Datetime Range
type: module
description: Datetime Range cusomizations.
core: 8.x
core_version_requirement: ^8 || ^9
package: "OpenY: Digital Signage"
dependencies:
- datetime_range
- drupal:datetime_range
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ name: Open Y Digital Signage Alerts
type: module
description: Digital Signage Alerts.
core: 8.x
core_version_requirement: ^8 || ^9
package: "OpenY: Digital Signage"
dependencies:
- openy_digital_signage_screen
- openy_node_alert
- openy_node_alert:openy_node_alert
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ name: OpenY Digital Signage GroupEx Pro Classes Schedule
type: module
description: OpenY Digital Signage GroupEx Pro Classes Schedule.
core: 8.x
core_version_requirement: ^8 || ^9
package: "OpenY: Digital Signage"
dependencies:
- openy_digital_signage_classes_schedule
- openy_digital_signage_room
- ymca_mappings
- ymca_groupex
- openy_digital_signage_room:openy_digital_signage_room
- ymca_mappings:ymca_mappings
- ymca_groupex:ymca_groupex
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Url;
use Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface;
use Drupal\openy_digital_signage_groupex_schedule\OpenYSessionsGroupExFetcher;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
Expand Down Expand Up @@ -47,7 +48,7 @@ public static function create(ContainerInterface $container) {
public function importSessions() {
$locations = $this->groupExFetcher->getLocations();
if (empty($locations)) {
drupal_set_message($this->t('Locations are not set in GroupEx Pro settings. Please specify locations you want to use and try again.'), 'error');
$this->messenger()->addError($this->t('Locations are not set in GroupEx Pro settings. Please specify locations you want to use and try again.'));
$url = new Url('entity.openy_ds_classes_session.collection');
return new RedirectResponse($url->toString());
}
Expand Down Expand Up @@ -113,7 +114,7 @@ public static function checkDeleted(&$context) {
$context['results']['to_be_deleted'] = [];
$date = new \DateTime();
$date->setTime(0, 0, 0);
$context['sandbox']['datetime'] = $date->format(DATETIME_DATETIME_STORAGE_FORMAT);
$context['sandbox']['datetime'] = $date->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT);

$query = \Drupal::entityQuery('openy_ds_classes_groupex_session')
->condition('date_time.value', $context['sandbox']['datetime'], '>')
Expand Down Expand Up @@ -268,7 +269,7 @@ public static function finishBatch($success, $results, $operations) {
else {
$message = t('Finished with an error.');
}
drupal_set_message($message);
\Drupal::messenger()->addMessage($message);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Drupal\openy_digital_signage_groupex_schedule;

use Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface;
use Drupal\ymca_groupex\GroupexRequestTrait;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
Expand Down Expand Up @@ -147,7 +148,7 @@ public function checkDeleted($feed, $location_id) {

$date = new \DateTime();
$date->setTime(0, 0, 0);
$formatted = $date->format(DATETIME_DATETIME_STORAGE_FORMAT);
$formatted = $date->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT);

/* @var \Drupal\ymca_mappings\Entity\Mapping $location */
$location = $this->locationRepository->load($location_id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ name: OpenY Digital Signage Personify Classes Schedule
type: module
description: OpenY Digital Signage Personify Schedule.
core: 8.x
core_version_requirement: ^8 || ^9
package: "OpenY: Digital Signage"
dependencies:
- openy_digital_signage_classes_schedule
- openy_digital_signage_room
- ymca_mappings
- ymca_personify
- openy_digital_signage_room:openy_digital_signage_room
- ymca_mappings:ymca_mappings
- ymca_personify:ymca_personify
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use Drupal\Core\Link;
use Drupal\Core\Url;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface;
use Drupal\openy_digital_signage_classes_schedule\Entity\OpenYClassesSession;
use Drupal\openy_digital_signage_personify_schedule\Entity\OpenYClassesPersonifySession;
use Drupal\openy_digital_signage_room\Entity\OpenYRoom;
Expand Down Expand Up @@ -178,8 +179,8 @@ function openy_digital_signage_personify_build_session_datetime(OpenYClassesPers
$end_date->setTimezone(new \DateTimeZone('UTC'));

return [
'start' => $start_date->format(DATETIME_DATETIME_STORAGE_FORMAT),
'end' => $end_date->format(DATETIME_DATETIME_STORAGE_FORMAT),
'start' => $start_date->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT),
'end' => $end_date->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT),
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Url;
use Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface;
use Drupal\openy_digital_signage_personify_schedule\Entity\OpenYClassesPersonifySession;
use Drupal\openy_digital_signage_personify_schedule\OpenYSessionsPersonifyFetcher;
use Symfony\Component\DependencyInjection\ContainerInterface;
Expand Down Expand Up @@ -48,7 +49,7 @@ public static function create(ContainerInterface $container) {
public function importSessions() {
$locations = $this->personifyFetcher->getLocations();
if (empty($locations)) {
drupal_set_message($this->t('Locations are not set in Personify settings. Please specify locations you want to use and try again.'), 'error');
$this->messenger()->addError($this->t('Locations are not set in Personify settings. Please specify locations you want to use and try again.'));
$url = new Url('entity.openy_ds_classes_session.collection');
return new RedirectResponse($url->toString());
}
Expand Down Expand Up @@ -112,7 +113,7 @@ public static function checkDeleted(&$context) {
$context['results']['to_be_deleted'] = [];
$date = new \DateTime();
$date->setTimestamp(REQUEST_TIME);
$context['sandbox']['datetime'] = $date->format(DATETIME_DATETIME_STORAGE_FORMAT);
$context['sandbox']['datetime'] = $date->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT);

$query = \Drupal::entityQuery('openy_ds_class_personify_session')
->condition('date.value', $context['sandbox']['datetime'], '<')
Expand Down Expand Up @@ -262,7 +263,7 @@ public static function finishBatch($success, $results, $operations) {
else {
$message = t('Finished with an error.');
}
drupal_set_message($message);
\Drupal::messenger()->addMessage($message);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface;
use Drupal\openy_digital_signage_personify_schedule\Entity\OpenYClassesPersonifySession;
use Drupal\ymca_mappings\LocationMappingRepository;
use Drupal\ymca_personify\PersonifyApi;
Expand Down Expand Up @@ -156,7 +157,7 @@ public function checkDeleted($feed) {

$date = new \DateTime();
$date->setTimestamp(REQUEST_TIME);
$formatted = $date->format(DATETIME_DATETIME_STORAGE_FORMAT);
$formatted = $date->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT);

$locations = $this->getLocations();
if (empty($locations)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ name: Digital Signage Classes Schedule
type: module
description: Digital Signage Classes Schedule.
core: 8.x
core_version_requirement: ^8 || ^9
package: "OpenY: Digital Signage"
dependencies:
- ds_datetime_range
- openy_digital_signage_room
- ds_datetime_range:ds_datetime_range
- openy_digital_signage_room:openy_digital_signage_room
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
services:
openy_digital_signage_classes_schedule.manager:
class: Drupal\openy_digital_signage_classes_schedule\OpenYClassesScheduleManager
arguments: ['@entity.manager', '@entity.query', '@logger.factory']
arguments: ['@entity_type.manager', '@logger.factory']
openy_digital_signage_classes_schedule.cron:
class: Drupal\openy_digital_signage_classes_schedule\OpenYClassesScheduleCron
arguments: ['@config.factory', '@entity_type.manager', '@logger.factory']
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ public function save(array $form, FormStateInterface $form_state) {

switch ($status) {
case SAVED_NEW:
drupal_set_message($this->t('Digital Signage Classes Session %label has been created.', [
$this->messenger()->addMessage($this->t('Digital Signage Classes Session %label has been created.', [
'%label' => $entity->label(),
]));
break;

default:
drupal_set_message($this->t('Digital Signage Classes Session %label has been saved.', [
$this->messenger()->addMessage($this->t('Digital Signage Classes Session %label has been saved.', [
'%label' => $entity->label(),
]));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function save(array $form, FormStateInterface $form_state) {
switch ($status) {
default:
case SAVED_NEW:
drupal_set_message($this->t('Digital Signage Classes Session %label has been overridden.', [
$this->messenger()->addMessage($this->t('Digital Signage Classes Session %label has been overridden.', [
'%label' => $this->entity->label(),
]));
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Drupal\Core\Entity\EntityTypeManager;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\Query\QueryFactory;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;

/**
Expand All @@ -25,13 +24,6 @@ class OpenYClassesScheduleManager implements OpenYClassesScheduleManagerInterfac
*/
const STORAGE = 'openy_ds_classes_session';

/**
* The query factory.
*
* @var QueryFactory
*/
protected $entityQuery;

/**
* The entity type manager.
*
Expand All @@ -56,8 +48,7 @@ class OpenYClassesScheduleManager implements OpenYClassesScheduleManagerInterfac
/**
* Constructor.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager, QueryFactory $entity_query, LoggerChannelFactoryInterface $logger_factory) {
$this->entityQuery = $entity_query;
public function __construct(EntityTypeManagerInterface $entity_type_manager, LoggerChannelFactoryInterface $logger_factory) {
$this->entityTypeManager = $entity_type_manager;
$this->logger = $logger_factory->get(self::CHANNEL);
$this->storage = $this->entityTypeManager->getStorage(self::STORAGE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ content:
type: duration_widget
weight: 3
region: content
settings:
duration: ''
settings: { }
third_party_settings: { }
media:
type: entity_browser_entity_reference
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ name: Open Y Digital Signage Playlists
type: module
description: Add Playlists to Open Y Digital Signage.
core: 8.x
core_version_requirement: ^8 || ^9
package: "OpenY: Digital Signage"
dependencies:
- openy_digital_signage_schedule
- datetime
- duration_field
- drupal:datetime
- drupal:duration_field
- drupal:media (>= 8.4)
- openy_media_image
- entity_browser
- openy_digital_signage_schedule
- openy_digital_signage_screen
- openy_ds_media_library
- openy_media_image:openy_media_image
- entity_browser:entity_browser
- openy_digital_signage_schedule:openy_digital_signage_schedule
- openy_digital_signage_screen:openy_digital_signage_screen
- openy_ds_media_library:openy_ds_media_library
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Update and install hooks.
*/

use Drupal\openy_digital_signage_playlist\Entity\OpenYPlaylistItem;
use Drupal\user\Entity\Role;

/**
Expand Down Expand Up @@ -49,3 +50,54 @@ function openy_digital_signage_playlist_install() {
function openy_digital_signage_playlist_update_8001(&$sandbox) {
openy_digital_signage_playlist_install();
}

/**
* Update duration field definition.
*/
function openy_digital_signage_playlist_update_8002(&$sandbox) {
$definition_manager = \Drupal::entityDefinitionUpdateManager();
$field_name = 'duration';
$entity_type_id = 'openy_ds_playlist_item';

// Ignore entity manager caches.
$entity_type_manager = \Drupal::entityTypeManager();
$entity_type_manager->useCaches(FALSE);

$database = \Drupal::database();
$duration_service = \Drupal::service('duration_field.service');

// Get the existing database value from the field table.
$values = $database->select($entity_type_id, 'fieldtable')
->fields('fieldtable', [
'id',
$field_name,
])
->execute()
->fetchAllKeyed();

// Clear out the values.
$database->update($entity_type_id)
->fields([$field_name => NULL])
->execute();

// Uninstall the field.
$field_storage_definition = $definition_manager->getFieldStorageDefinition($field_name, $entity_type_id);
$definition_manager->uninstallFieldStorageDefinition($field_storage_definition);

$entity_type = $entity_type_manager->getDefinition($entity_type_id);
$fields = OpenYPlaylistItem::baseFieldDefinitions($entity_type);

// Install the new definition.
$definition_manager->installFieldStorageDefinition($field_name, $entity_type_id, 'openy_digital_signage_playlist', $fields[$field_name]);

// Restore the values.
foreach ($values as $id => $value) {
$database->update($entity_type_id)
->fields([
$field_name . '__duration' => $value,
$field_name . '__seconds' => $duration_service->getSecondsFromDurationString($value),
])
->condition('id', $id)
->execute();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public function getItemType() {
public function getExpireStatus() {
$date_end = $this->get('date_end')->date;
$time_end = $this->get('time_end')->date;
$default_timezone = drupal_get_user_timezone();
$default_timezone = date_default_timezone_get();
$current_date = new DrupalDateTime('now', $default_timezone);

if (!$date_end) {
Expand Down Expand Up @@ -305,14 +305,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields['duration'] = BaseFieldDefinition::create('duration')
->setLabel(t('Duration'))
->setSettings([
'granularity' => [
'year' => FALSE,
'month' => FALSE,
'day' => FALSE,
'hour' => TRUE,
'minute' => TRUE,
'second' => TRUE,
],
'granularity' => 'h:i:s',
])
->setDisplayOptions('view', [
'label' => 'visible',
Expand Down
Loading

0 comments on commit 12d3c53

Please sign in to comment.