From 99663b74a6e1072a09916cb0ce7259888c23d80e Mon Sep 17 00:00:00 2001 From: Joe Corall Date: Mon, 28 Oct 2024 10:09:51 -0400 Subject: [PATCH 01/10] Add Drupal 11 support --- .github/workflows/build-3.x.yml | 8 ++++++-- jsonld.info.yml | 2 +- src/Normalizer/ContentEntityNormalizer.php | 2 +- src/Normalizer/EntityReferenceItemNormalizer.php | 2 +- src/Normalizer/FieldItemNormalizer.php | 2 +- src/Normalizer/FieldNormalizer.php | 2 +- src/Normalizer/FileEntityNormalizer.php | 2 +- tests/json_alter_normalize_hooks.info.yml | 2 +- 8 files changed, 13 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build-3.x.yml b/.github/workflows/build-3.x.yml index 6850f13..70c9a5e 100644 --- a/.github/workflows/build-3.x.yml +++ b/.github/workflows/build-3.x.yml @@ -22,8 +22,12 @@ jobs: strategy: matrix: php-versions: ["8.1", "8.2", "8.3"] - drupal-version: ["10.2.x", "10.3.x", "10.4.x-dev"] - + drupal-version: ["10.2.x", "10.3.x", "10.4.x-dev", "11.0.x"] + exclude: + - drupal-version: "11.0.x" + php-versions: "8.1" + - drupal-version: "11.0.x" + php-versions: "8.2" env: DRUPAL_VERSION: ${{ matrix.drupal-version }} SCRIPT_DIR: ${{ github.workspace }}/islandora_ci diff --git a/jsonld.info.yml b/jsonld.info.yml index 8fd21d4..dbd8b18 100644 --- a/jsonld.info.yml +++ b/jsonld.info.yml @@ -2,7 +2,7 @@ name: 'JSON-LD' type: module description: 'Serializes entities to JSON-LD / LDP for the Islandora Project' package: Web services -core_version_requirement: ^10 +core_version_requirement: ^10 || ^11 dependencies: - drupal:serialization - hal:hal diff --git a/src/Normalizer/ContentEntityNormalizer.php b/src/Normalizer/ContentEntityNormalizer.php index bd8ce60..5b06725 100644 --- a/src/Normalizer/ContentEntityNormalizer.php +++ b/src/Normalizer/ContentEntityNormalizer.php @@ -77,7 +77,7 @@ public function __construct(LinkManagerInterface $link_manager, /** * {@inheritdoc} */ - public function normalize($entity, $format = NULL, array $context = []) { + public function normalize($entity, $format = NULL, array $context = []): array|bool|string|int|float|null|\ArrayObject { // We need to make sure that this only runs for JSON-LD. // @todo check $format before going RDF crazy diff --git a/src/Normalizer/EntityReferenceItemNormalizer.php b/src/Normalizer/EntityReferenceItemNormalizer.php index e504661..2646a40 100644 --- a/src/Normalizer/EntityReferenceItemNormalizer.php +++ b/src/Normalizer/EntityReferenceItemNormalizer.php @@ -55,7 +55,7 @@ public function __construct(LinkManagerInterface $link_manager, /** * {@inheritdoc} */ - public function normalize($field_item, $format = NULL, array $context = []) { + public function normalize($field_item, $format = NULL, array $context = []): array|bool|string|int|float|null|\ArrayObject { /** @var \Drupal\Core\Field\FieldItemInterface $field_item */ $target_entity = $field_item->get('entity')->getValue(); diff --git a/src/Normalizer/FieldItemNormalizer.php b/src/Normalizer/FieldItemNormalizer.php index efaecd5..276652a 100644 --- a/src/Normalizer/FieldItemNormalizer.php +++ b/src/Normalizer/FieldItemNormalizer.php @@ -38,7 +38,7 @@ public function __construct(JsonldContextGeneratorInterface $jsonld_context) { /** * {@inheritdoc} */ - public function normalize($field_item, $format = NULL, array $context = []) { + public function normalize($field_item, $format = NULL, array $context = []): array|bool|string|int|float|null|\ArrayObject { // @todo Understand Drupal complex fields to RDF mapping // Fields can be complex, with multiple subfields diff --git a/src/Normalizer/FieldNormalizer.php b/src/Normalizer/FieldNormalizer.php index e2a8eaf..39c4d17 100644 --- a/src/Normalizer/FieldNormalizer.php +++ b/src/Normalizer/FieldNormalizer.php @@ -21,7 +21,7 @@ class FieldNormalizer extends NormalizerBase { /** * {@inheritdoc} */ - public function normalize($field, $format = NULL, array $context = []) { + public function normalize($field, $format = NULL, array $context = []): array|bool|string|int|float|null|\ArrayObject { $normalized_field_items = []; diff --git a/src/Normalizer/FileEntityNormalizer.php b/src/Normalizer/FileEntityNormalizer.php index 356f169..5a4d40d 100644 --- a/src/Normalizer/FileEntityNormalizer.php +++ b/src/Normalizer/FileEntityNormalizer.php @@ -67,7 +67,7 @@ public function __construct(EntityTypeManagerInterface $entity_manager, /** * {@inheritdoc} */ - public function normalize($entity, $format = NULL, array $context = []) { + public function normalize($entity, $format = NULL, array $context = []): array|bool|string|int|float|null|\ArrayObject { $data = parent::normalize($entity, $format, $context); // Replace the file url with a full url for the file. diff --git a/tests/json_alter_normalize_hooks.info.yml b/tests/json_alter_normalize_hooks.info.yml index 5b4d1d0..4630f27 100644 --- a/tests/json_alter_normalize_hooks.info.yml +++ b/tests/json_alter_normalize_hooks.info.yml @@ -1,6 +1,6 @@ name: 'Jsonld hook tests' type: module package: Testing -core_version_requirement: ^8 || ^9 +core_version_requirement: ^8 || ^9 || ^10 || ^11 dependencies: - jsonld From 28a78140976556f9d6160d7a61ed2ff9388a8df2 Mon Sep 17 00:00:00 2001 From: Joe Corall Date: Mon, 28 Oct 2024 10:15:37 -0400 Subject: [PATCH 02/10] Update build-3.x.yml --- .github/workflows/build-3.x.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build-3.x.yml b/.github/workflows/build-3.x.yml index 70c9a5e..87cf853 100644 --- a/.github/workflows/build-3.x.yml +++ b/.github/workflows/build-3.x.yml @@ -23,11 +23,11 @@ jobs: matrix: php-versions: ["8.1", "8.2", "8.3"] drupal-version: ["10.2.x", "10.3.x", "10.4.x-dev", "11.0.x"] - exclude: - - drupal-version: "11.0.x" - php-versions: "8.1" - - drupal-version: "11.0.x" - php-versions: "8.2" + exclude: + - drupal-version: "11.0.x" + php-versions: "8.1" + - drupal-version: "11.0.x" + php-versions: "8.2" env: DRUPAL_VERSION: ${{ matrix.drupal-version }} SCRIPT_DIR: ${{ github.workspace }}/islandora_ci From d3ef0c22e5801ee0821f59b59738e75b8217e291 Mon Sep 17 00:00:00 2001 From: Joe Corall Date: Mon, 28 Oct 2024 10:18:04 -0400 Subject: [PATCH 03/10] verbose no longer support in phpunit --- .github/workflows/build-3.x.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-3.x.yml b/.github/workflows/build-3.x.yml index 87cf853..23df7e1 100644 --- a/.github/workflows/build-3.x.yml +++ b/.github/workflows/build-3.x.yml @@ -112,4 +112,4 @@ jobs: - name: PHPUNIT tests run: | cd $DRUPAL_DIR/web/core - $DRUPAL_DIR/vendor/bin/phpunit --verbose --debug + $DRUPAL_DIR/vendor/bin/phpunit --debug From 704592fe177690e941d4ca5736422be81e6e98ee Mon Sep 17 00:00:00 2001 From: Joe Corall Date: Mon, 28 Oct 2024 11:02:53 -0400 Subject: [PATCH 04/10] Remove drupal/core dependency --- composer.json | 1 - 1 file changed, 1 deletion(-) diff --git a/composer.json b/composer.json index ed38a9d..cb89f9e 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,6 @@ "islandora/jsonld": "self.version" }, "require" : { - "drupal/core": "^10", "drupal/hal": "^1||^2", "drupal/rdf": "^2.1" }, From 01114411a9c1fcfc0f01f256d7b6113a63dc5887 Mon Sep 17 00:00:00 2001 From: Joe Corall Date: Mon, 28 Oct 2024 11:06:43 -0400 Subject: [PATCH 05/10] Drop <=10.2 support --- .github/workflows/build-3.x.yml | 2 +- composer.json | 2 +- jsonld.info.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-3.x.yml b/.github/workflows/build-3.x.yml index 23df7e1..2759ce2 100644 --- a/.github/workflows/build-3.x.yml +++ b/.github/workflows/build-3.x.yml @@ -22,7 +22,7 @@ jobs: strategy: matrix: php-versions: ["8.1", "8.2", "8.3"] - drupal-version: ["10.2.x", "10.3.x", "10.4.x-dev", "11.0.x"] + drupal-version: ["10.3.x", "10.4.x-dev", "11.0.x"] exclude: - drupal-version: "11.0.x" php-versions: "8.1" diff --git a/composer.json b/composer.json index cb89f9e..7a57292 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ }, "require" : { "drupal/hal": "^1||^2", - "drupal/rdf": "^2.1" + "drupal/rdf": "^3.0@beta" }, "require-dev": { "phpunit/phpunit": "^8", diff --git a/jsonld.info.yml b/jsonld.info.yml index dbd8b18..6d4101e 100644 --- a/jsonld.info.yml +++ b/jsonld.info.yml @@ -2,7 +2,7 @@ name: 'JSON-LD' type: module description: 'Serializes entities to JSON-LD / LDP for the Islandora Project' package: Web services -core_version_requirement: ^10 || ^11 +core_version_requirement: ^10.3 || ^11 dependencies: - drupal:serialization - hal:hal From a1d4e02e4487d3828c2537e43b5776eee62e8753 Mon Sep 17 00:00:00 2001 From: Joe Corall Date: Mon, 28 Oct 2024 12:40:44 -0400 Subject: [PATCH 06/10] compatible with Symfony\Component\Serializer\Normalizer\DenormalizerInterface::denormalize --- src/Normalizer/ContentEntityNormalizer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Normalizer/ContentEntityNormalizer.php b/src/Normalizer/ContentEntityNormalizer.php index 5b06725..55ffa10 100644 --- a/src/Normalizer/ContentEntityNormalizer.php +++ b/src/Normalizer/ContentEntityNormalizer.php @@ -195,7 +195,7 @@ public function normalize($entity, $format = NULL, array $context = []): array|b /** * {@inheritdoc} */ - public function denormalize($data, $class, $format = NULL, array $context = []) { + public function denormalize(mixed $data, string $class, ?string $format = NULL, array $context = []) : mixed { // Get type, necessary for determining which bundle to create. if (!isset($data['_links']['type'])) { From 511bbe53142b50bc299c74e8ad3d1ac3357ac8b8 Mon Sep 17 00:00:00 2001 From: Joe Corall Date: Mon, 28 Oct 2024 12:47:01 -0400 Subject: [PATCH 07/10] moar normalizer compatability --- src/Normalizer/FieldItemNormalizer.php | 2 +- src/Normalizer/FieldNormalizer.php | 2 +- src/Normalizer/FileEntityNormalizer.php | 2 +- src/Normalizer/NormalizerBase.php | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Normalizer/FieldItemNormalizer.php b/src/Normalizer/FieldItemNormalizer.php index 276652a..1922297 100644 --- a/src/Normalizer/FieldItemNormalizer.php +++ b/src/Normalizer/FieldItemNormalizer.php @@ -138,7 +138,7 @@ public function normalize($field_item, $format = NULL, array $context = []): arr /** * {@inheritdoc} */ - public function denormalize($data, $class, $format = NULL, array $context = []) { + public function denormalize(mixed $data, string $class, ?string $format = NULL, array $context = []) : mixed { if (!isset($context['target_instance'])) { throw new InvalidArgumentException('$context[\'target_instance\'] must be set to denormalize with the FieldItemNormalizer'); diff --git a/src/Normalizer/FieldNormalizer.php b/src/Normalizer/FieldNormalizer.php index 39c4d17..96153c3 100644 --- a/src/Normalizer/FieldNormalizer.php +++ b/src/Normalizer/FieldNormalizer.php @@ -62,7 +62,7 @@ public function normalize($field, $format = NULL, array $context = []): array|bo /** * {@inheritdoc} */ - public function denormalize($data, $class, $format = NULL, array $context = []) { + public function denormalize(mixed $data, string $class, ?string $format = NULL, array $context = []) : mixed { if (!isset($context['target_instance'])) { throw new InvalidArgumentException('$context[\'target_instance\'] must be set to denormalize with the FieldNormalizer'); diff --git a/src/Normalizer/FileEntityNormalizer.php b/src/Normalizer/FileEntityNormalizer.php index 5a4d40d..9d7cc74 100644 --- a/src/Normalizer/FileEntityNormalizer.php +++ b/src/Normalizer/FileEntityNormalizer.php @@ -79,7 +79,7 @@ public function normalize($entity, $format = NULL, array $context = []): array|b /** * {@inheritdoc} */ - public function denormalize($data, $class, $format = NULL, array $context = []) { + public function denormalize(mixed $data, string $class, ?string $format = NULL, array $context = []) : mixed { $file_data = (string) $this->httpClient->get($data['uri'][0]['value'])->getBody(); diff --git a/src/Normalizer/NormalizerBase.php b/src/Normalizer/NormalizerBase.php index 65802fb..64c794c 100644 --- a/src/Normalizer/NormalizerBase.php +++ b/src/Normalizer/NormalizerBase.php @@ -20,7 +20,7 @@ abstract class NormalizerBase extends SerializationNormalizerBase implements Den /** * {@inheritdoc} */ - public function supportsNormalization($data, string $format = NULL, array $context = []): bool { + public function supportsNormalization(mixed $data, ?string $format = NULL, array $context = []): bool { return in_array($format, $this->formats) && parent::supportsNormalization($data, $format); } @@ -28,7 +28,7 @@ public function supportsNormalization($data, string $format = NULL, array $conte /** * {@inheritdoc} */ - public function supportsDenormalization($data, string $type, string $format = NULL, array $context = []): bool { + public function supportsDenormalization($data, string $type, ?string $format = NULL, array $context = []): bool { if (in_array($format, $this->formats) && (class_exists($this->supportedInterfaceOrClass) || interface_exists($this->supportedInterfaceOrClass))) { $target = new \ReflectionClass($type); From 01f52574bd963dbab1642bd6b213f15e257abcec Mon Sep 17 00:00:00 2001 From: Joe Corall Date: Mon, 28 Oct 2024 12:56:27 -0400 Subject: [PATCH 08/10] Remove installSchema per https://www.drupal.org/node/3349345 --- tests/src/Kernel/JsonldKernelTestBase.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/src/Kernel/JsonldKernelTestBase.php b/tests/src/Kernel/JsonldKernelTestBase.php index 13d05b4..0e4ec39 100644 --- a/tests/src/Kernel/JsonldKernelTestBase.php +++ b/tests/src/Kernel/JsonldKernelTestBase.php @@ -116,8 +116,6 @@ protected function setUp() : void { $class = get_parent_class($class); } - $this->installSchema('system', ['sequences']); - $types = ['schema:Thing']; $created_mapping = [ 'properties' => ['schema:dateCreated'], From 8a43ba88c29e8d896c97b7cb10a1daa8c6ebb0f3 Mon Sep 17 00:00:00 2001 From: Joe Corall Date: Tue, 29 Oct 2024 11:21:23 -0400 Subject: [PATCH 09/10] Add Drupal 11 getSupportedTypes on normalizers --- src/Normalizer/ContentEntityNormalizer.php | 10 ++++++++++ src/Normalizer/EntityReferenceItemNormalizer.php | 10 ++++++++++ src/Normalizer/FieldItemNormalizer.php | 9 +++++++++ src/Normalizer/FieldNormalizer.php | 9 +++++++++ src/Normalizer/FileEntityNormalizer.php | 10 ++++++++++ 5 files changed, 48 insertions(+) diff --git a/src/Normalizer/ContentEntityNormalizer.php b/src/Normalizer/ContentEntityNormalizer.php index 55ffa10..c1b4834 100644 --- a/src/Normalizer/ContentEntityNormalizer.php +++ b/src/Normalizer/ContentEntityNormalizer.php @@ -3,6 +3,7 @@ namespace Drupal\jsonld\Normalizer; use Drupal\Component\Utility\NestedArray; +use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\hal\LinkManager\LinkManagerInterface; @@ -304,4 +305,13 @@ protected function getTypedDataIds(array $types, array $context = []) { return $typed_data_ids; } + /** + * {@inheritdoc} + */ + public function getSupportedTypes(?string $format): array { + return [ + ContentEntityInterface::class => TRUE, + ]; + } + } diff --git a/src/Normalizer/EntityReferenceItemNormalizer.php b/src/Normalizer/EntityReferenceItemNormalizer.php index 2646a40..85c4256 100644 --- a/src/Normalizer/EntityReferenceItemNormalizer.php +++ b/src/Normalizer/EntityReferenceItemNormalizer.php @@ -3,6 +3,7 @@ namespace Drupal\jsonld\Normalizer; use Drupal\Core\Entity\FieldableEntityInterface; +use Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem; use Drupal\hal\LinkManager\LinkManagerInterface; use Drupal\jsonld\ContextGenerator\JsonldContextGeneratorInterface; use Drupal\serialization\EntityResolver\EntityResolverInterface; @@ -178,4 +179,13 @@ public function getUuid($data) { } } + /** + * {@inheritdoc} + */ + public function getSupportedTypes(?string $format): array { + return [ + EntityReferenceItem::class => TRUE, + ]; + } + } diff --git a/src/Normalizer/FieldItemNormalizer.php b/src/Normalizer/FieldItemNormalizer.php index 1922297..be0004d 100644 --- a/src/Normalizer/FieldItemNormalizer.php +++ b/src/Normalizer/FieldItemNormalizer.php @@ -210,4 +210,13 @@ protected function createTranslatedInstance(FieldItemInterface $item, $langcode) return $entity_translation->get($field_name)->appendItem(); } + /** + * {@inheritdoc} + */ + public function getSupportedTypes(?string $format): array { + return [ + FieldItemInterface::class => TRUE, + ]; + } + } diff --git a/src/Normalizer/FieldNormalizer.php b/src/Normalizer/FieldNormalizer.php index 96153c3..ad58d1e 100644 --- a/src/Normalizer/FieldNormalizer.php +++ b/src/Normalizer/FieldNormalizer.php @@ -110,4 +110,13 @@ protected function normalizeFieldItems(FieldItemListInterface $field, $format, a return $normalized_field_items; } + /** + * {@inheritdoc} + */ + public function getSupportedTypes(?string $format): array { + return [ + FieldItemListInterface::class => TRUE, + ]; + } + } diff --git a/src/Normalizer/FileEntityNormalizer.php b/src/Normalizer/FileEntityNormalizer.php index 9d7cc74..6ea53d2 100644 --- a/src/Normalizer/FileEntityNormalizer.php +++ b/src/Normalizer/FileEntityNormalizer.php @@ -5,6 +5,7 @@ use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\File\FileSystemInterface; +use Drupal\file\FileInterface; use Drupal\hal\LinkManager\LinkManagerInterface; use Drupal\jsonld\Utils\JsonldNormalizerUtilsInterface; use GuzzleHttp\ClientInterface; @@ -89,4 +90,13 @@ public function denormalize(mixed $data, string $class, ?string $format = NULL, return $this->entityManager->getStorage('file')->create($data); } + /** + * {@inheritdoc} + */ + public function getSupportedTypes(?string $format): array { + return [ + FileInterface::class => TRUE, + ]; + } + } From d665faa12082e99f9b98d447ada7d04a9dc23d57 Mon Sep 17 00:00:00 2001 From: Joe Corall Date: Wed, 30 Oct 2024 07:05:52 -0400 Subject: [PATCH 10/10] lint --- src/ContextGenerator/JsonldContextGenerator.php | 14 +++++++------- src/Controller/JsonldContextController.php | 6 +++--- src/Normalizer/ContentEntityNormalizer.php | 10 ++++++---- src/Normalizer/EntityReferenceItemNormalizer.php | 15 ++++++++------- src/Normalizer/FieldItemNormalizer.php | 6 +++--- src/Normalizer/FileEntityNormalizer.php | 14 ++++++++------ src/Utils/JsonldNormalizerUtils.php | 2 +- tests/src/Kernel/JsonldHookTest.php | 2 +- tests/src/Kernel/JsonldKernelTestBase.php | 4 ++-- tests/src/Kernel/JsonldTestEntityGenerator.php | 2 +- .../JsonldContentEntityNormalizerTest.php | 10 +++++----- 11 files changed, 45 insertions(+), 40 deletions(-) diff --git a/src/ContextGenerator/JsonldContextGenerator.php b/src/ContextGenerator/JsonldContextGenerator.php index b0ccc7e..a18a284 100644 --- a/src/ContextGenerator/JsonldContextGenerator.php +++ b/src/ContextGenerator/JsonldContextGenerator.php @@ -2,14 +2,14 @@ namespace Drupal\jsonld\ContextGenerator; -use Drupal\Core\Entity\EntityFieldManagerInterface; -use Drupal\Core\Entity\EntityTypeManagerInterface; -use Drupal\Core\Entity\EntityTypeBundleInfoInterface; use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\CacheBackendInterface; +use Drupal\Core\Entity\EntityFieldManagerInterface; +use Drupal\Core\Entity\EntityTypeBundleInfoInterface; +use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Field\FieldDefinitionInterface; -use Drupal\rdf\RdfMappingInterface; use Drupal\rdf\Entity\RdfMapping; +use Drupal\rdf\RdfMappingInterface; use Psr\Log\LoggerInterface; /** @@ -206,7 +206,7 @@ public function getFieldsRdf(RdfMappingInterface $rdfMapping, $field_name, Field // Now we start overriding from config entity defined mappings. // Assume all non defined mapping types as "property". - $reltype = isset($fieldRDFMapping['mapping_type']) ? $fieldRDFMapping['mapping_type'] : 'property'; + $reltype = $fieldRDFMapping['mapping_type'] ?? 'property'; if (isset($fieldRDFMapping['datatype']) && ($reltype == 'property')) { $termDefinition = ['@type' => $fieldRDFMapping['datatype']]; @@ -277,7 +277,7 @@ protected function writeCache(RdfMappingInterface $rdfMapping, $cid) { * And array with the entity type and the bundle id */ protected function entityBundleIdsSplitter($ids) { - list($entity_type_id, $bundle_id) = explode(".", $ids, 2); + [$entity_type_id, $bundle_id] = explode(".", $ids, 2); return ['entityTypeId' => $entity_type_id, 'bundleId' => $bundle_id]; } @@ -297,7 +297,7 @@ protected function entityBundleIdsSplitter($ids) { */ protected function parseCompactedIri($iri) { // As naive as it gets. - list($prefix, $rest) = array_pad(explode(":", $iri, 2), 2, ''); + [$prefix, $rest] = array_pad(explode(":", $iri, 2), 2, ''); if ((substr($rest, 0, 2) == "//") || ($prefix == $iri)) { // Means this was never a compacted IRI. return ['prefix' => NULL, 'term' => $iri]; diff --git a/src/Controller/JsonldContextController.php b/src/Controller/JsonldContextController.php index 8cd8b6e..6566712 100644 --- a/src/Controller/JsonldContextController.php +++ b/src/Controller/JsonldContextController.php @@ -2,15 +2,15 @@ namespace Drupal\jsonld\Controller; +use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\CacheableJsonResponse; +use Drupal\Core\Cache\CacheableMetadata; use Drupal\Core\Controller\ControllerBase; use Drupal\jsonld\ContextGenerator\JsonldContextGeneratorInterface; +use Drupal\rdf\Entity\RdfMapping; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Drupal\rdf\Entity\RdfMapping; -use Drupal\Core\Cache\Cache; -use Drupal\Core\Cache\CacheableMetadata; /** * Controller for retrieving jsonld contexts. diff --git a/src/Normalizer/ContentEntityNormalizer.php b/src/Normalizer/ContentEntityNormalizer.php index c1b4834..b57e5ee 100644 --- a/src/Normalizer/ContentEntityNormalizer.php +++ b/src/Normalizer/ContentEntityNormalizer.php @@ -64,10 +64,12 @@ class ContentEntityNormalizer extends NormalizerBase { * @param \Drupal\Jsonld\Utils\JsonldNormalizerUtilsInterface $normalizer_utils * The json-ld normalizer utilities. */ - public function __construct(LinkManagerInterface $link_manager, - EntityTypeManagerInterface $entity_manager, - ModuleHandlerInterface $module_handler, - JsonldNormalizerUtilsInterface $normalizer_utils) { + public function __construct( + LinkManagerInterface $link_manager, + EntityTypeManagerInterface $entity_manager, + ModuleHandlerInterface $module_handler, + JsonldNormalizerUtilsInterface $normalizer_utils, + ) { $this->linkManager = $link_manager; $this->entityManager = $entity_manager; diff --git a/src/Normalizer/EntityReferenceItemNormalizer.php b/src/Normalizer/EntityReferenceItemNormalizer.php index 85c4256..a88bfee 100644 --- a/src/Normalizer/EntityReferenceItemNormalizer.php +++ b/src/Normalizer/EntityReferenceItemNormalizer.php @@ -45,9 +45,11 @@ class EntityReferenceItemNormalizer extends FieldItemNormalizer implements UuidR * @param \Drupal\jsonld\ContextGenerator\JsonldContextGeneratorInterface $jsonld_context * The Json-Ld context service. */ - public function __construct(LinkManagerInterface $link_manager, - EntityResolverInterface $entity_Resolver, - JsonldContextGeneratorInterface $jsonld_context) { + public function __construct( + LinkManagerInterface $link_manager, + EntityResolverInterface $entity_Resolver, + JsonldContextGeneratorInterface $jsonld_context, + ) { parent::__construct($jsonld_context); $this->linkManager = $link_manager; $this->entityResolver = $entity_Resolver; @@ -69,7 +71,7 @@ public function normalize($field_item, $format = NULL, array $context = []): arr // If the parent entity passed in a langcode, unset it before normalizing // the target entity. Otherwise, untranslatable fields of the target entity // will include the langcode. - $langcode = isset($context['langcode']) ? $context['langcode'] : NULL; + $langcode = $context['langcode'] ?? NULL; unset($context['langcode']); // Limiting to uuid makes sure that we only get one child from base entity // if not we could end traversing forever since there is no way @@ -91,15 +93,14 @@ public function normalize($field_item, $format = NULL, array $context = []): arr $field_item->getParent() ->getName() ); - $field_keys = isset($field_mappings['properties']) ? - $field_mappings['properties'] : + $field_keys = $field_mappings['properties'] ?? [$field_item->getParent()->getName()]; // Value in this case is the target entity, so if a callback exists // it should work against that. if (!empty($field_mappings['datatype_callback'])) { $callback = $field_mappings['datatype_callback']['callable']; - $arguments = isset($field_mappings['datatype_callback']['arguments']) ? $field_mappings['datatype_callback']['arguments'] : NULL; + $arguments = $field_mappings['datatype_callback']['arguments'] ?? NULL; $transformed_value = call_user_func($callback, $target_entity, $arguments); // If the config says it is an @id, we'll save it as an @id. if (!empty($field_mappings['datatype']) && $field_mappings['datatype'] == '@id') { diff --git a/src/Normalizer/FieldItemNormalizer.php b/src/Normalizer/FieldItemNormalizer.php index be0004d..d5405e5 100644 --- a/src/Normalizer/FieldItemNormalizer.php +++ b/src/Normalizer/FieldItemNormalizer.php @@ -57,14 +57,14 @@ public function normalize($field_item, $format = NULL, array $context = []): arr } else { // Set the uri here, and then convert it to '@id' later on. - $values_clean['@value'] = isset($values['value']) ? $values['value'] : $values['uri']; + $values_clean['@value'] = $values['value'] ?? $values['uri']; if (isset($context['current_entity_rdf_mapping'])) { // So why i am passing the whole rdf mapping object and not // only the predicate? Well because i hope i will be able // to MAP to RDF also sub fields of a complex field someday // and somehow. $field_mappings = $context['current_entity_rdf_mapping']->getPreparedFieldMapping($field->getName()); - $field_keys = isset($field_mappings['properties']) ? $field_mappings['properties'] : [$field->getName()]; + $field_keys = $field_mappings['properties'] ?? [$field->getName()]; if (!empty($field_mappings['datatype'])) { $values_clean['@type'] = $field_mappings['datatype']; @@ -76,7 +76,7 @@ public function normalize($field_item, $format = NULL, array $context = []): arr // For now this is a dirty solution. if (!empty($field_mappings['datatype_callback'])) { $callback = $field_mappings['datatype_callback']['callable']; - $arguments = isset($field_mappings['datatype_callback']['arguments']) ? $field_mappings['datatype_callback']['arguments'] : NULL; + $arguments = $field_mappings['datatype_callback']['arguments'] ?? NULL; $values_clean['@value'] = call_user_func($callback, $values, $arguments); } $field_context = $this->jsonldContextgenerator->getFieldsRdf( diff --git a/src/Normalizer/FileEntityNormalizer.php b/src/Normalizer/FileEntityNormalizer.php index 6ea53d2..d5e006a 100644 --- a/src/Normalizer/FileEntityNormalizer.php +++ b/src/Normalizer/FileEntityNormalizer.php @@ -52,12 +52,14 @@ class FileEntityNormalizer extends ContentEntityNormalizer { * @param \Drupal\jsonld\Utils\JsonldNormalizerUtilsInterface $normalizer_utils * The json-ld normalizer utils. */ - public function __construct(EntityTypeManagerInterface $entity_manager, - ClientInterface $http_client, - LinkManagerInterface $link_manager, - ModuleHandlerInterface $module_handler, - FileSystemInterface $file_system, - JsonldNormalizerUtilsInterface $normalizer_utils) { + public function __construct( + EntityTypeManagerInterface $entity_manager, + ClientInterface $http_client, + LinkManagerInterface $link_manager, + ModuleHandlerInterface $module_handler, + FileSystemInterface $file_system, + JsonldNormalizerUtilsInterface $normalizer_utils, + ) { parent::__construct($link_manager, $entity_manager, $module_handler, $normalizer_utils); diff --git a/src/Utils/JsonldNormalizerUtils.php b/src/Utils/JsonldNormalizerUtils.php index 66b291f..24cb000 100644 --- a/src/Utils/JsonldNormalizerUtils.php +++ b/src/Utils/JsonldNormalizerUtils.php @@ -51,7 +51,7 @@ class JsonldNormalizerUtils implements JsonldNormalizerUtilsInterface { public function __construct( ConfigFactoryInterface $config_factory, LanguageManagerInterface $language_manager, - RouteProviderInterface $route_provider + RouteProviderInterface $route_provider, ) { $this->config = $config_factory->get(JsonLdSettingsForm::CONFIG_NAME); $this->languageManager = $language_manager; diff --git a/tests/src/Kernel/JsonldHookTest.php b/tests/src/Kernel/JsonldHookTest.php index ccfc17b..a837e42 100644 --- a/tests/src/Kernel/JsonldHookTest.php +++ b/tests/src/Kernel/JsonldHookTest.php @@ -37,7 +37,7 @@ public function setUp() : void { */ public function testAlterNormalizedJsonld() { - list($entity, $expected) = JsonldTestEntityGenerator::create()->generateNewEntity(); + [$entity, $expected] = JsonldTestEntityGenerator::create()->generateNewEntity(); $expected['@graph'][] = [ "@id" => "json_alter_normalize_hooks", "http://purl.org/dc/elements/1.1/title" => "The hook is tested.", diff --git a/tests/src/Kernel/JsonldKernelTestBase.php b/tests/src/Kernel/JsonldKernelTestBase.php index 0e4ec39..f0c28c9 100644 --- a/tests/src/Kernel/JsonldKernelTestBase.php +++ b/tests/src/Kernel/JsonldKernelTestBase.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\jsonld\Kernel; +use Drupal\KernelTests\KernelTestBase; use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldStorageConfig; use Drupal\jsonld\Encoder\JsonldEncoder; @@ -10,11 +11,10 @@ use Drupal\jsonld\Normalizer\FieldItemNormalizer; use Drupal\jsonld\Normalizer\FieldNormalizer; use Drupal\jsonld\Utils\JsonldNormalizerUtils; -use Drupal\KernelTests\KernelTestBase; +use Drupal\language\Entity\ConfigurableLanguage; use Drupal\serialization\EntityResolver\ChainEntityResolver; use Drupal\serialization\EntityResolver\TargetIdResolver; use Symfony\Component\Serializer\Serializer; -use Drupal\language\Entity\ConfigurableLanguage; /** * Base class for Json-LD Kernel tests. diff --git a/tests/src/Kernel/JsonldTestEntityGenerator.php b/tests/src/Kernel/JsonldTestEntityGenerator.php index 13fca31..a632936 100644 --- a/tests/src/Kernel/JsonldTestEntityGenerator.php +++ b/tests/src/Kernel/JsonldTestEntityGenerator.php @@ -2,8 +2,8 @@ namespace Drupal\Tests\jsonld\Kernel; -use Drupal\entity_test\Entity\EntityTest; use Drupal\Tests\RandomGeneratorTrait; +use Drupal\entity_test\Entity\EntityTest; use Drupal\user\Entity\User; /** diff --git a/tests/src/Kernel/Normalizer/JsonldContentEntityNormalizerTest.php b/tests/src/Kernel/Normalizer/JsonldContentEntityNormalizerTest.php index 1a9cce6..fff0176 100644 --- a/tests/src/Kernel/Normalizer/JsonldContentEntityNormalizerTest.php +++ b/tests/src/Kernel/Normalizer/JsonldContentEntityNormalizerTest.php @@ -33,7 +33,7 @@ protected function setUp() :void { */ public function testSimpleNormalizeJsonld() { - list($entity, $expected) = JsonldTestEntityGenerator::create()->generateNewEntity(); + [$entity, $expected] = JsonldTestEntityGenerator::create()->generateNewEntity(); $normalized = $this->serializer->normalize($entity, $this->format); $this->assertEquals($expected, $normalized, "Did not normalize correctly."); @@ -52,7 +52,7 @@ public function testSimpleNormalizeJsonld() { */ public function testLocalizedNormalizeJsonld() { - list($entity, $expected) = JsonldTestEntityGenerator::create()->generateNewEntity(); + [$entity, $expected] = JsonldTestEntityGenerator::create()->generateNewEntity(); $existing_entity_values = $entity->toArray(); $target_entity_tl_id = $existing_entity_values['field_test_entity_reference'][0]['target_id']; @@ -96,7 +96,7 @@ public function testLocalizedNormalizeJsonld() { */ public function testDeduplicateEntityReferenceMappings(): void { - list($entity, $expected) = JsonldTestEntityGenerator::create()->makeDuplicateReferenceMapping()->generateNewEntity(); + [$entity, $expected] = JsonldTestEntityGenerator::create()->makeDuplicateReferenceMapping()->generateNewEntity(); $normalized = $this->serializer->normalize($entity, $this->format); @@ -108,7 +108,7 @@ public function testDeduplicateEntityReferenceMappings(): void { */ public function testDeduplicateEntityReferenceIds(): void { - list($entity, $expected) = JsonldTestEntityGenerator::create()->makeDuplicateReference()->generateNewEntity(); + [$entity, $expected] = JsonldTestEntityGenerator::create()->makeDuplicateReference()->generateNewEntity(); $normalized = $this->serializer->normalize($entity, $this->format); @@ -122,7 +122,7 @@ public function testDeduplicateEntityReferenceIds(): void { * - sharing the same RDF mapping. */ public function testDuplicateEntityReferenceAndMappings(): void { - list($entity, $expected) = JsonldTestEntityGenerator::create()->makeDuplicateReference()->makeDuplicateReferenceMapping() + [$entity, $expected] = JsonldTestEntityGenerator::create()->makeDuplicateReference()->makeDuplicateReferenceMapping() ->generateNewEntity(); $normalized = $this->serializer->normalize($entity, $this->format);