Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Wim Leers created an issue. See original summary.

Wim Leers’s picture

Status: Active » Needs review
FileSize
1.64 KB

This:

  1. marks JsonApiSpec @internal
  2. adds two official query parameters that we missed in #2829328: Clean up Drupal\jsonapi\Access\CustomParameterNames and make it follow the spec more closely: fields and include.
  3. removes RequestCacheabilityDependency::getQueryParamCacheContextList(), because that can now be read from JsonApiSpec::getReservedQueryParameters()
Wim Leers’s picture

FileSize
3.27 KB
1.65 KB

Note that #2 passes tests, so RequestCacheabilityDependencyTest passes. But that test really is pretty pointless. So, removing it.

Wim Leers’s picture

Title: Update \Drupal\jsonapi\RequestCacheabilityDependency to use \Drupal\jsonapi\JsonApiSpec::getReservedQueryParameters() » Remove \Drupal\jsonapi\RequestCacheabilityDependency, use \Drupal\jsonapi\JsonApiSpec::getReservedQueryParameters() instead
FileSize
2.21 KB
4.81 KB

In fact, we can remove RequestCacheabilityDependency altogether. It was only being used in one place: \Drupal\jsonapi\Normalizer\Value\JsonApiDocumentTopLevelNormalizerValue::__construct().

I'm not convinced that's entirely the correct place, but that's a problem for later. What matters most right now, is that we have less duplication, and also one less class that is rather strange-looking.

Status: Needs review » Needs work

The last submitted patch, 4: 2846659-4.patch, failed testing.

Wim Leers’s picture

dawehner’s picture

+++ b/src/Normalizer/Value/JsonApiDocumentTopLevelNormalizerValue.php
@@ -74,7 +74,10 @@ class JsonApiDocumentTopLevelNormalizerValue implements ValueExtractorInterface,
+    $reserved_jsonapi_query_parameters = JsonApiSpec::getReservedQueryParameters();
+    foreach ($reserved_jsonapi_query_parameters as $query_parameter_name) {
+      $this->addCacheContexts([sprintf('url.query_args:%s', $query_parameter_name)]);
+    }
 

+++ /dev/null
@@ -1,34 +0,0 @@
-    return array_map(function ($param_name) {
-      return sprintf('url.query_args:%s', $param_name);
-    }, $this::getQueryParamCacheContextList());

An array_map got replaced by a foreach :(

Wim Leers’s picture

Status: Needs work » Needs review
FileSize
1.41 KB
6.17 KB

#4 causes \Drupal\Core\Cache\RefinableCacheableDependencyTrait::addCacheContexts() to be called, which calls Cache::mergeContexts(), which uses the cache contexts manager. That's what's causing this to fail.

Wim Leers’s picture

+++ b/src/Normalizer/Value/JsonApiDocumentTopLevelNormalizerValue.php
@@ -74,7 +74,10 @@ class JsonApiDocumentTopLevelNormalizerValue implements ValueExtractorInterface,
+    $reserved_jsonapi_query_parameters = JsonApiSpec::getReservedQueryParameters();
+    foreach ($reserved_jsonapi_query_parameters as $query_parameter_name) {
+      $this->addCacheContexts([sprintf('url.query_args:%s', $query_parameter_name)]);
+    }

#7: let's convert this to an array_map() then :)

Wim Leers’s picture

FileSize
6.1 KB
1.11 KB

Done.

dawehner’s picture

Let's go back to using no side effects inside the array_map.

Wim Leers’s picture

LOL of course. Thanks.

Wim--

  • e0ipso committed d6b38c7 on 8.x-1.x authored by dawehner
    fix(Maintainability) Remove \Drupal\jsonapi\...
e0ipso’s picture

Status: Needs review » Fixed

This was merged.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.