From a4c03be4b89c692fe77247aa17d583d230b82fbe Mon Sep 17 00:00:00 2001 From: Christian Fritsch Date: Wed, 22 Mar 2023 10:13:04 +0100 Subject: [PATCH] Drupal 10 compatibility (#87) Co-authored-by: Christian Fritsch --- dcx_integration.info.yml | 2 +- .../dcx_article_archive/dcx_article_archive.info.yml | 2 +- .../dcx_article_import/dcx_article_import.info.yml | 2 +- modules/dcx_collections/dcx_collections.info.yml | 2 +- modules/dcx_dropzone_ui/dcx_dropzone_ui.info.yml | 2 +- .../dcx_entity_browser/dcx_entity_browser.info.yml | 2 +- .../dcx_media_image_clone.info.yml | 2 +- modules/dcx_migration/dcx_migration.info.yml | 2 +- modules/dcx_notification/dcx_notification.info.yml | 2 +- .../dcx_track_media_usage.info.yml | 2 +- .../dcx_unpublish_media/dcx_unpublish_media.info.yml | 2 +- .../dcx_unpublish_media/dcx_unpublish_media.module | 4 ++-- .../src/EventSubscriber/RequestSubscriber.php | 4 +++- src/Asset/Image.php | 2 +- tests/src/Kernel/AssetGenerationTest.php | 2 +- tests/src/Kernel/AssetTest.php | 9 ++++----- tests/src/Kernel/DcxJsonClientIntegrationTest.php | 2 +- tests/src/Unit/DcxJsonClientTest.php | 12 ++++++------ 18 files changed, 29 insertions(+), 28 deletions(-) diff --git a/dcx_integration.info.yml b/dcx_integration.info.yml index b9db037..1ffea1e 100644 --- a/dcx_integration.info.yml +++ b/dcx_integration.info.yml @@ -1,5 +1,5 @@ name: DC-X integration type: module description: 'Integration of DC-X digital asset management.' -core_version_requirement: ^8.7.7 || ^9 +core_version_requirement: ^8.7.7 || ^9 || ^10 package: dcx diff --git a/modules/dcx_article_archive/dcx_article_archive.info.yml b/modules/dcx_article_archive/dcx_article_archive.info.yml index 47b6f57..c36e8c6 100644 --- a/modules/dcx_article_archive/dcx_article_archive.info.yml +++ b/modules/dcx_article_archive/dcx_article_archive.info.yml @@ -1,7 +1,7 @@ name: DC-X Article Archive type: module description: Archive Articles to DC-X -core_version_requirement: ^8.7.7 || ^9 +core_version_requirement: ^8.7.7 || ^9 || ^10 package: dcx dependencies: - dcx_integration:dcx_integration diff --git a/modules/dcx_article_import/dcx_article_import.info.yml b/modules/dcx_article_import/dcx_article_import.info.yml index 9945c97..aee5870 100644 --- a/modules/dcx_article_import/dcx_article_import.info.yml +++ b/modules/dcx_article_import/dcx_article_import.info.yml @@ -1,7 +1,7 @@ name: DC-X Article Import type: module description: Allow importing DC-X story documents to article nodes. -core_version_requirement: ^8.7.7 || ^9 +core_version_requirement: ^8.7.7 || ^9 || ^10 package: dcx dependencies: - dcx_integration:dcx_integration diff --git a/modules/dcx_collections/dcx_collections.info.yml b/modules/dcx_collections/dcx_collections.info.yml index 0c224af..f85e22c 100644 --- a/modules/dcx_collections/dcx_collections.info.yml +++ b/modules/dcx_collections/dcx_collections.info.yml @@ -1,7 +1,7 @@ name: DC-X Collections type: module description: Integrates DC-X collections to entity browser -core_version_requirement: ^8.7.7 || ^9 +core_version_requirement: ^8.7.7 || ^9 || ^10 package: Custom dependencies: - dcx_integration:dcx_migration diff --git a/modules/dcx_dropzone_ui/dcx_dropzone_ui.info.yml b/modules/dcx_dropzone_ui/dcx_dropzone_ui.info.yml index bbb89f3..31651ca 100644 --- a/modules/dcx_dropzone_ui/dcx_dropzone_ui.info.yml +++ b/modules/dcx_dropzone_ui/dcx_dropzone_ui.info.yml @@ -1,7 +1,7 @@ name: DC-X Dropzone UI type: module description: 'Dropzone Element for DCX DnD' -core_version_requirement: ^8 || ^9 +core_version_requirement: ^8.7.7 || ^9 || ^10 package: dcx dependencies: - dcx_integration:dcx_migration diff --git a/modules/dcx_entity_browser/dcx_entity_browser.info.yml b/modules/dcx_entity_browser/dcx_entity_browser.info.yml index 7b989fd..6b14b79 100644 --- a/modules/dcx_entity_browser/dcx_entity_browser.info.yml +++ b/modules/dcx_entity_browser/dcx_entity_browser.info.yml @@ -1,7 +1,7 @@ name: DC-X Entity Browser type: module description: 'Entity Browser integration for dcx' -core_version_requirement: ^8 || ^9 +core_version_requirement: ^8.7.7 || ^9 || ^10 package: dcx dependencies: diff --git a/modules/dcx_media_image_clone/dcx_media_image_clone.info.yml b/modules/dcx_media_image_clone/dcx_media_image_clone.info.yml index 191b0e5..49272ad 100644 --- a/modules/dcx_media_image_clone/dcx_media_image_clone.info.yml +++ b/modules/dcx_media_image_clone/dcx_media_image_clone.info.yml @@ -1,7 +1,7 @@ name: DC-X media image clone type: module description: Allow cloning media image entities and keep track of the clones regarding DC-X. -core_version_requirement: ^8.7.7 || ^9 +core_version_requirement: ^8.7.7 || ^9 || ^10 package: dcx dependencies: - dcx_integration:dcx_migration diff --git a/modules/dcx_migration/dcx_migration.info.yml b/modules/dcx_migration/dcx_migration.info.yml index 39ac20d..1de1534 100644 --- a/modules/dcx_migration/dcx_migration.info.yml +++ b/modules/dcx_migration/dcx_migration.info.yml @@ -1,7 +1,7 @@ name: DC-X Migration type: module description: 'Migration of data from DC-X digital asset management.' -core_version_requirement: ^8 || ^9 +core_version_requirement: ^8.7.7 || ^9 || ^10 package: dcx dependencies: - dcx_integration:dcx_integration diff --git a/modules/dcx_notification/dcx_notification.info.yml b/modules/dcx_notification/dcx_notification.info.yml index 8240c1b..00e15f5 100644 --- a/modules/dcx_notification/dcx_notification.info.yml +++ b/modules/dcx_notification/dcx_notification.info.yml @@ -1,7 +1,7 @@ name: DC-X notification type: module description: Provides a notification callback to be triggered by DC-X on change of relevant documents. -core_version_requirement: ^8.7.7 || ^9 +core_version_requirement: ^8.7.7 || ^9 || ^10 package: dcx dependencies: - dcx_integration:dcx_migration diff --git a/modules/dcx_track_media_usage/dcx_track_media_usage.info.yml b/modules/dcx_track_media_usage/dcx_track_media_usage.info.yml index 36f6a59..28590f0 100644 --- a/modules/dcx_track_media_usage/dcx_track_media_usage.info.yml +++ b/modules/dcx_track_media_usage/dcx_track_media_usage.info.yml @@ -1,7 +1,7 @@ name: DC-X Track Media Usage type: module description: Provides usage tracking of DC-X media an nodes -core_version_requirement: ^8.7.7 || ^9 +core_version_requirement: ^8.7.7 || ^9 || ^10 package: dcx dependencies: - dcx_integration:dcx_integration diff --git a/modules/dcx_unpublish_media/dcx_unpublish_media.info.yml b/modules/dcx_unpublish_media/dcx_unpublish_media.info.yml index ca70f36..dee27e9 100644 --- a/modules/dcx_unpublish_media/dcx_unpublish_media.info.yml +++ b/modules/dcx_unpublish_media/dcx_unpublish_media.info.yml @@ -1,7 +1,7 @@ name: DC-X Unpublish Media type: module description: 'Handels the behavior if a media is unpublished' -core_version_requirement: ^8 || ^9 +core_version_requirement: ^8.7.7 || ^9 || ^10 package: dcx dependencies: - drupal:media (>= 8.4) diff --git a/modules/dcx_unpublish_media/dcx_unpublish_media.module b/modules/dcx_unpublish_media/dcx_unpublish_media.module index 0f03fed..509a5da 100644 --- a/modules/dcx_unpublish_media/dcx_unpublish_media.module +++ b/modules/dcx_unpublish_media/dcx_unpublish_media.module @@ -35,7 +35,7 @@ function dcx_unpublish_media_media_update(MediaInterface $entity) { // Do not care about image styles here. File move takes care of this by // invoking hook image_file_move(). - file_move($file, $target_fileuri); + \Drupal::service('file.repository')->move($file, $target_fileuri); } elseif ($entity->status->value && !$entity->original->status->value) { $target_fileuri = str_replace('private://', 'public://', $file->getFileUri()); @@ -44,7 +44,7 @@ function dcx_unpublish_media_media_update(MediaInterface $entity) { if (!is_dir($target_dir)) { mkdir($target_dir); } - file_move($file, $target_fileuri); + \Drupal::service('file.repository')->move($file, $target_fileuri); /** @var \Drupal\Core\Cache\CacheTagsInvalidatorInterface $cache */ $cache = \Drupal::service('cache_tags.invalidator'); diff --git a/modules/dcx_unpublish_media/src/EventSubscriber/RequestSubscriber.php b/modules/dcx_unpublish_media/src/EventSubscriber/RequestSubscriber.php index 52b1b51..ecff4a9 100644 --- a/modules/dcx_unpublish_media/src/EventSubscriber/RequestSubscriber.php +++ b/modules/dcx_unpublish_media/src/EventSubscriber/RequestSubscriber.php @@ -5,7 +5,7 @@ use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\StreamWrapper\PublicStream; use Symfony\Component\EventDispatcher\EventSubscriberInterface; -use Symfony\Component\EventDispatcher\Event; +use Symfony\Contracts\EventDispatcher\Event; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\Response; @@ -71,6 +71,7 @@ public function kernelRequest(Event $event) { $query = $this->entityTypeManager->getStorage('file')->getQuery(); $query->condition('filename', $filename); + $query->accessCheck(FALSE); $fids = $query->execute(); if ($fids) { @@ -82,6 +83,7 @@ public function kernelRequest(Event $event) { $query = $this->entityTypeManager->getStorage('media')->getQuery(); $query->condition("$field.target_id", current($fids)); + $query->accessCheck(FALSE); $mids = $query->execute(); if ($mids) { diff --git a/src/Asset/Image.php b/src/Asset/Image.php index e36efe8..1c08bb1 100644 --- a/src/Asset/Image.php +++ b/src/Asset/Image.php @@ -52,7 +52,7 @@ class Image extends BaseAsset { */ public function __construct(array $data) { parent::__construct($data, self::$mandatoryAttributes, self::$optionalAttributes); - $mimeType = \Drupal::service('file.mime_type.guesser')->guess($data['url']); + $mimeType = \Drupal::service('file.mime_type.guesser')->guessMimeType($data['url']); if (!in_array($mimeType, static::$allowedMimeTypes)) { throw new IllegalAttributeException($data['url']); } diff --git a/tests/src/Kernel/AssetGenerationTest.php b/tests/src/Kernel/AssetGenerationTest.php index 2f791ec..c91995d 100644 --- a/tests/src/Kernel/AssetGenerationTest.php +++ b/tests/src/Kernel/AssetGenerationTest.php @@ -18,7 +18,7 @@ class AssetGenerationTest extends KernelTestBase { /** * */ - public function setUp() { + public function setUp(): void { parent::setUp(); $user = $this->createMock('\Drupal\Core\Session\AccountProxyInterface'); diff --git a/tests/src/Kernel/AssetTest.php b/tests/src/Kernel/AssetTest.php index f1c2b1c..99e696e 100644 --- a/tests/src/Kernel/AssetTest.php +++ b/tests/src/Kernel/AssetTest.php @@ -5,7 +5,6 @@ use Drupal\dcx_integration\Asset\Image; use Drupal\dcx_integration\Asset\Article; use Drupal\KernelTests\KernelTestBase; -use Drupal\Tests\UnitTestCase; /** * Description of AssetTest. @@ -25,7 +24,7 @@ public function testCreateImage__mandatory_attr() { } $asset = new Image($data); - $this->assertArraySubset($data, $asset->data(), "Mandatory attributes suffice to create an Image"); + $this->assertEquals($data, $asset->data(), "Mandatory attributes suffice to create an Image"); } /** @@ -38,7 +37,7 @@ public function testCreateImage__optional_attr() { } $asset = new Image($data); - $this->assertArraySubset($data, $asset->data(), "Mandatory and optional attributes are able to create an Image"); + $this->assertEquals($data, $asset->data(), "Mandatory and optional attributes are able to create an Image"); } /** @@ -81,7 +80,7 @@ public function testCreateArticle__mandatory_attr() { } $asset = new Article($data); - $this->assertArraySubset($data, $asset->data(), "Mandatory attributes suffice to create an Article"); + $this->assertEquals($data, $asset->data(), "Mandatory attributes suffice to create an Article"); } /** @@ -94,7 +93,7 @@ public function testCreateArticle__optional_attr() { } $asset = new Article($data); - $this->assertArraySubset($data, $asset->data(), "Mandatory and optional attributes are able to create an Article"); + $this->assertEquals($data, $asset->data(), "Mandatory and optional attributes are able to create an Article"); } /** diff --git a/tests/src/Kernel/DcxJsonClientIntegrationTest.php b/tests/src/Kernel/DcxJsonClientIntegrationTest.php index 83614d2..0d3b9a4 100644 --- a/tests/src/Kernel/DcxJsonClientIntegrationTest.php +++ b/tests/src/Kernel/DcxJsonClientIntegrationTest.php @@ -32,7 +32,7 @@ class DcxJsonClientIntegrationTest extends KernelTestBase { /** * {@inheritdoc} */ - public function setUp() { + public function setUp(): void { parent::setUp(); $siteSettings = ['mail' => 'admin@admin.de', 'name' => 'Integration Test']; diff --git a/tests/src/Unit/DcxJsonClientTest.php b/tests/src/Unit/DcxJsonClientTest.php index 82de4c5..bad2a26 100644 --- a/tests/src/Unit/DcxJsonClientTest.php +++ b/tests/src/Unit/DcxJsonClientTest.php @@ -21,7 +21,7 @@ class DcxJsonClientTest extends UnitTestCase { /** * */ - public function setUp() { + public function setUp(): void { $jsonclientsettings = ['publication' => 'dummy_publication']; $config_factory = $this->getConfigFactoryStub(['dcx_integration.jsonclientsettings' => $jsonclientsettings]); $user = $this->createMock('\Drupal\Core\Session\AccountProxyInterface'); @@ -42,7 +42,7 @@ public function setUp() { */ public function testGetJson_noparams() { $this->client->getJson('dcxapi:id'); - list($url, $params,) = $this->api_client->args; + [$url, $params,] = $this->api_client->args; $this->assertEquals($this->api_client->method, 'get', 'getObject method of API client is called.'); $this->assertEquals($url, 'id', 'Client disposes "dcxapi:" part of the id.'); $this->assertNotEmpty($params, 'If no params are given, default params are passed to the API client.'); @@ -53,8 +53,8 @@ public function testGetJson_noparams() { */ public function testGetJson_custom_params() { $this->client->getJson('dcxapi:id', ['params']); - list(, $params,) = $this->api_client->args; - $this->assertArrayEquals(['params'], $params, 'If params are given, they are passed to the API client'); + [, $params,] = $this->api_client->args; + $this->assertEquals(['params'], $params, 'If params are given, they are passed to the API client'); } /** @@ -200,9 +200,9 @@ public function testArchiveArticle_exisitingArticle() { public function testPubinfoOnPath_noResults() { $this->api_client->expected_response_body = ['entries' => []]; $pubinfos = $this->client->pubinfoOnPath('node/1', 'article'); - $this->assertArrayEquals([], $pubinfos); + $this->assertEquals([], $pubinfos); $this->assertEquals($this->api_client->method, 'get', 'getObject is called when retrieving pubinfo data'); - list($url) = $this->api_client->args; + [$url] = $this->api_client->args; $this->assertEquals($url, 'pubinfo', 'url "pubinfo is requested"'); }