Skip to content

Commit

Permalink
add patch for jsonapi_extras
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfinnarn committed Feb 16, 2024
1 parent 6a73d9c commit 894364e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,9 @@
"3226473 - Opt-in system delete.": "https://www.drupal.org/files/issues/2023-03-28/3226473-opt-in-system-delete-2.patch",
"3061620 - Cancel closes all forms": "https://www.drupal.org/files/issues/2022-07-21/inline_entity_form-close-only-forms-where-close-clicked-3061620-13.patch"
},
"drupal/jsonapi_extras": {
"3025283 - Default field enhancer for each field type": "patches/field-type-enhancer-3025283-3.patch"
},
"drupal/jsonapi_menu_items": {
"3276561 - Add support for the Menu Item Extras module": "https://www.drupal.org/files/issues/2022-08-01/3276561-05-menu_item_extras_support.patch"
},
Expand Down
36 changes: 36 additions & 0 deletions patches/field-type-enhancer-3025283-3.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
diff --git a/src/Normalizer/FieldItemNormalizer.php b/src/Normalizer/FieldItemNormalizer.php
index 8882870..9f8abc8 100644
--- a/src/Normalizer/FieldItemNormalizer.php
+++ b/src/Normalizer/FieldItemNormalizer.php
@@ -51,12 +51,30 @@ class FieldItemNormalizer extends JsonApiNormalizerDecoratorBase {
public function normalize($object, $format = NULL, array $context = []) {
// First get the regular output.
$normalized_output = parent::normalize($object, $format, $context);
+
// Then detect if there is any enhancer to be applied here.
/** @var \Drupal\jsonapi_extras\ResourceType\ConfigurableResourceType $resource_type */
$resource_type = $context['resource_object']->getResourceType();
$enhancer = $resource_type->getFieldEnhancer($object->getParent()->getName());
+
if (!$enhancer) {
- return $normalized_output;
+ // Look for default field type enhancer.
+ $config = \Drupal::config('jsonapi_extras.jsonapi_field_type_config');
+ $field_type = $object->getFieldDefinition()->getType();
+ $field_type_config = $config->get('mapping.resourceFieldTypes')[$field_type];
+
+ if (!empty($field_type_config['enhancer']['id'])) {
+ // Get the enhancer instance.
+ /** @var \Drupal\jsonapi_extras\Plugin\ResourceFieldEnhancerInterface $enhancer */
+ $enhancer = $this->enhancerManager->createInstance(
+ $field_type_config['enhancer']['id'],
+ (array) $field_type_config['enhancer']['settings']
+ );
+ }
+
+ if (!$enhancer) {
+ return $normalized_output;
+ }
}
$cacheability = CacheableMetadata::createFromObject($normalized_output)
->addCacheTags(['config:jsonapi_resource_config_list']);

0 comments on commit 894364e

Please sign in to comment.