Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
Issue #3111024 by chr.fritsch: Remove all D8.7 and earlier deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
chrfritsch authored Feb 4, 2020
1 parent d194216 commit 0a5e55c
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 73 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ env:

before_install:
- composer global require thunder/travis

script:
- test-drupal-module
- test-drupal-project

notifications:
email: false
2 changes: 1 addition & 1 deletion nexx_integration.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Nexx video integration
type: module
description: 'Integration of nexxOMNIA and nexxPLAY'
package: Field types
core: 8.x
core_version_requirement: ^8.7.7
configure: nexx_integration.admin_settings

dependencies:
Expand Down
5 changes: 3 additions & 2 deletions nexx_integration.install
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

use Drupal\Core\Database\Database;
use Drupal\Core\File\FileSystemInterface;

/**
* Implements hook_schema().
Expand Down Expand Up @@ -46,7 +47,7 @@ function nexx_integration_schema() {
function nexx_integration_install() {
$source = drupal_get_path('module', 'nexx_integration') . '/images/icons';
$destination = \Drupal::config('media.settings')->get('icon_base_uri');
file_prepare_directory($destination, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
\Drupal::service('file_system')->prepareDirectory($destination, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS);

$files = file_scan_directory($source, '/.*\.(svg|png|jpg|jpeg|gif)$/');
foreach ($files as $file) {
Expand All @@ -57,7 +58,7 @@ function nexx_integration_install() {
// referenced somewhere else. Since showing an error that it was not
// possible to copy the files is also confusing, we silently do nothing.
if (!file_exists($destination . DIRECTORY_SEPARATOR . $file->filename)) {
file_unmanaged_copy($file->uri, $destination, FILE_EXISTS_ERROR);
\Drupal::service('file_system')->copy($file->uri, $destination, FileSystemInterface::EXISTS_ERROR);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions nexx_integration.module
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,8 @@ function nexx_integration_cron() {
// Check videos, that could be activated.
/** @var \Drupal\Core\Entity\Query\QueryInterface $ids */
$ids = $storage->getQuery()
->condition($video_field . '.validfrom_ssc', REQUEST_TIME, '<=')
->condition($video_field . '.validto_ssc', REQUEST_TIME, '>')
->condition($video_field . '.validfrom_ssc', \Drupal::time()->getRequestTime(), '<=')
->condition($video_field . '.validto_ssc', \Drupal::time()->getRequestTime(), '>')
->condition("status", FALSE)
->execute();

Expand All @@ -285,7 +285,7 @@ function nexx_integration_cron() {
/** @var \Drupal\Core\Entity\Query\QueryInterface $ids */
$ids = $storage->getQuery()
->condition($video_field . '.validto_ssc', 0, '<>')
->condition($video_field . '.validto_ssc', REQUEST_TIME, '<=')
->condition($video_field . '.validto_ssc', \Drupal::time()->getRequestTime(), '<=')
->condition("status", TRUE)
->execute();

Expand Down
2 changes: 1 addition & 1 deletion nexx_integration.services.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
services:
nexx_integration.notification:
class: Drupal\nexx_integration\NexxNotification
arguments: ['@config.factory', '@logger.factory', '@http_client', '@string_translation']
arguments: ['@config.factory', '@logger.factory', '@http_client', '@string_translation', '@messenger']

nexx_integration.videomanager:
class: Drupal\nexx_integration\VideoManagerService
Expand Down
50 changes: 21 additions & 29 deletions src/Controller/OmniaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Database\Connection;
use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\Utility\Token;
use Drupal\media\MediaInterface;
use Psr\Log\LoggerInterface;
Expand Down Expand Up @@ -35,27 +36,6 @@ class OmniaController extends ControllerBase {
*/
protected $entityTypeBundleInfo;

/**
* The media entity.
*
* @var \Drupal\media\MediaInterface
*/
protected $mediaEntity;

/**
* The media entity storage.
*
* @var \Drupal\Core\Entity\EntityStorageInterface
*/
protected $mediaEntityStorage;

/**
* The media entity definition.
*
* @var \Drupal\Core\Entity\EntityTypeInterface
*/
protected $mediaEntityDefinition;

/**
* The entity field manager.
*
Expand Down Expand Up @@ -91,6 +71,13 @@ class OmniaController extends ControllerBase {
*/
protected $nexxVideoData = [];

/**
* The file system service.
*
* @var \Drupal\Core\File\FileSystemInterface
*/
protected $fileSystem;

/**
* OmniaController constructor.
*
Expand All @@ -104,6 +91,8 @@ class OmniaController extends ControllerBase {
* The logger service.
* @param \Drupal\Core\Utility\Token $token
* Token service.
* @param \Drupal\Core\File\FileSystemInterface $file_system
* The file system service.
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException.
*/
Expand All @@ -112,13 +101,15 @@ public function __construct(
EntityTypeBundleInfoInterface $entity_type_bundle_info,
EntityFieldManagerInterface $entity_field_manager,
LoggerInterface $logger,
Token $token
Token $token,
FileSystemInterface $file_system
) {
$this->database = $database;
$this->entityTypeBundleInfo = $entity_type_bundle_info;
$this->entityFieldManager = $entity_field_manager;
$this->logger = $logger;
$this->token = $token;
$this->fileSystem = $file_system;
}

/**
Expand All @@ -130,7 +121,8 @@ public static function create(ContainerInterface $container) {
$container->get('entity_type.bundle.info'),
$container->get('entity_field.manager'),
$container->get('logger.factory')->get('nexx_integration'),
$container->get('token')
$container->get('token'),
$container->get('file_system')
);
}

Expand Down Expand Up @@ -569,8 +561,8 @@ protected function mapTeaserImage(MediaInterface $media, $teaserImageField) {
$destination_directory = dirname($destination_file);
if ($destination_directory) {
// Import file.
file_prepare_directory($destination_directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
$thumbnail = file_save_data(file_get_contents($thumb_uri), $destination_file, FILE_EXISTS_REPLACE);
$this->fileSystem->prepareDirectory($destination_directory, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS);
$thumbnail = file_save_data(file_get_contents($thumb_uri), $destination_file, FileSystemInterface::EXISTS_REPLACE);
// Add this file to thumbnail field of the nexx media entity.
$thumbnail_entity->$thumbnail_upload_field->appendItem([
'target_id' => $thumbnail->id(),
Expand Down Expand Up @@ -667,10 +659,10 @@ protected function setState(MediaInterface $media) {
);
}
else {
$this->logger->info('Unpublished video "@title" (Drupal id: @id)... States:
active:@active
isSSC:@isSSC
validfrom_ssc:@validfrom_ssc
$this->logger->info('Unpublished video "@title" (Drupal id: @id)... States:
active:@active
isSSC:@isSSC
validfrom_ssc:@validfrom_ssc
validto_ssc:@validto_ssc ',
[
'@title' => $this->nexxVideoData['title'],
Expand Down
76 changes: 51 additions & 25 deletions src/Form/SettingsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@

use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Ajax\ReplaceCommand;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Entity\EntityTypeRepositoryInterface;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Entity\EntityManagerInterface;

/**
* Class SettingsForm.
Expand All @@ -21,40 +22,65 @@
*/
class SettingsForm extends ConfigFormBase {
/**
* The entity manager service.
* The entity type manager service.
*
* @var \Drupal\Core\Entity\EntityManagerInterface
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityManager;
protected $entityTypeManager;

/**
* The display plugin manager.
* The entity type repository service.
*
* @var \Drupal\entity_embed\EntityEmbedDisplay\EntityEmbedDisplayManager
* @var \Drupal\Core\Entity\EntityTypeRepositoryInterface
*/
protected $displayPluginManager;
protected $entityTypeRepository;

/**
* {@inheritdoc}
* The entity type bundle info service.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory.
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager service.
* @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface
*/
public function __construct(ConfigFactoryInterface $config_factory, EntityManagerInterface $entity_manager) {
parent::__construct($config_factory);
$this->entityManager = $entity_manager;
}
protected $entityTypeBundleInfo;

/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('config.factory'),
$container->get('entity.manager')
);
$form = parent::create($container);
$form->setEntityTypeManager($container->get('entity_type.manager'));
$form->setEntityTypeRepository($container->get('entity_type.repository'));
$form->setEntityTypeBundleInfo($container->get('entity_type.bundle.info'));
return $form;
}

/**
* Set the entity type manager service.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* The entity type manager service.
*/
protected function setEntityTypeManager(EntityTypeManagerInterface $entityTypeManager) {
$this->entityTypeManager = $entityTypeManager;
}

/**
* Set the entity type repository service.
*
* @param \Drupal\Core\Entity\EntityTypeRepositoryInterface $entityTypeRepository
* The entity type repository service.
*/
protected function setEntityTypeRepository(EntityTypeRepositoryInterface $entityTypeRepository) {
$this->entityTypeRepository = $entityTypeRepository;
}

/**
* Set the entity type bundle info service.
*
* @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entityTypeBundleInfo
* The entity type bundle info service.
*/
protected function setEntityTypeBundleInfo(EntityTypeBundleInfoInterface $entityTypeBundleInfo) {
$this->entityTypeBundleInfo = $entityTypeBundleInfo;
}

/**
Expand Down Expand Up @@ -132,7 +158,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#suffix' => '</div>',
];

$entity_type = $this->entityManager->getDefinition('media');
$entity_type = $this->entityTypeManager->getDefinition('media');
$bundle = !empty($values['type_settings']['video_bundle']) ? $values['type_settings']['video_bundle'] : $settings->get('video_bundle');
$form['type_settings']['video_bundle'] = [
'#type' => 'select',
Expand Down Expand Up @@ -218,12 +244,12 @@ protected function getEditableConfigNames() {
* An array of entity type labels, keyed by entity type name.
*/
protected function getEntityTypeOptions() {
$options = $this->entityManager->getEntityTypeLabels(TRUE);
$options = $this->entityTypeRepository->getEntityTypeLabels(TRUE);

foreach ($options as $group => $group_types) {
foreach (array_keys($group_types) as $entity_type_id) {
// Filter out entity types that do not have a view builder class.
if (!$this->entityManager->getDefinition($entity_type_id)->hasViewBuilderClass()) {
if (!$this->entityTypeManager->getDefinition($entity_type_id)->hasViewBuilderClass()) {
unset($options[$group][$entity_type_id]);
}
}
Expand Down Expand Up @@ -268,7 +294,7 @@ protected function getEntityBundleOptions(EntityTypeInterface $entity_type) {
$bundle_options = [];
// If the entity has bundles, allow option to restrict to bundle(s).
if ($entity_type->hasKey('bundle')) {
foreach ($this->entityManager->getBundleInfo($entity_type->id()) as $bundle_id => $bundle_info) {
foreach ($this->entityTypeBundleInfo->getBundleInfo($entity_type->id()) as $bundle_id => $bundle_info) {
$bundle_options[$bundle_id] = $bundle_info['label'];
}
natsort($bundle_options);
Expand Down
16 changes: 14 additions & 2 deletions src/NexxNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\Component\Serialization\Json;
use Drupal\Core\Messenger\MessengerInterface;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
use Drupal\Core\StringTranslation\TranslationInterface;
Expand Down Expand Up @@ -40,6 +41,13 @@ class NexxNotification implements NexxNotificationInterface {
*/
protected $httpClient;

/**
* The messenger service.
*
* @var \Drupal\Core\Messenger\MessengerInterface
*/
protected $messenger;

/**
* Notify nexxOMNIA video CMS.
*
Expand All @@ -54,17 +62,21 @@ class NexxNotification implements NexxNotificationInterface {
* The HTTP client.
* @param \Drupal\Core\StringTranslation\TranslationInterface $translation
* The translation service.
* @param \Drupal\Core\Messenger\MessengerInterface $messenger
* The messenger service.
*/
public function __construct(
ConfigFactoryInterface $config_factory,
LoggerChannelFactoryInterface $logger_factory,
Client $http_client,
TranslationInterface $translation
TranslationInterface $translation,
MessengerInterface $messenger
) {
$this->config = $config_factory->get('nexx_integration.settings');
$this->logger = $logger_factory->get('nexx_integration');
$this->httpClient = $http_client;
$this->stringTranslation = $translation;
$this->messenger = $messenger;
}

/**
Expand Down Expand Up @@ -169,7 +181,7 @@ protected function notificateNexx(

if ($api_url == '' || $api_authkey == '' || $omnia_id == '') {
$this->logger->error("Missing configuration for API Url and/or Installation Code (API Key) and/or Omnia ID.");
drupal_set_message($this->t("Item wasn't exported to Nexx due to missing configuration for API Url and/or Installation Code (API Key) and/or Omnia ID."), 'error');
$this->messenger->addError($this->t("Item wasn't exported to Nexx due to missing configuration for API Url and/or Installation Code (API Key) and/or Omnia ID."));

return FALSE;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
name: Nexx video integration test module
type: module
description: 'Module used in tests for the nexx integration module'
core: 8.x
package: Testing
core_version_requirement: ^8.7.7 || ^9

dependencies:
- drupal:file
Expand Down
Loading

0 comments on commit 0a5e55c

Please sign in to comment.