Comments

Wim Leers created an issue. See original summary.

wim leers’s picture

Status: Active » Needs review
StatusFileSize
new1.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

StatusFileSize
new3.27 KB
new1.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
StatusFileSize
new2.21 KB
new4.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
StatusFileSize
new1.41 KB
new6.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

StatusFileSize
new6.1 KB
new1.11 KB

Done.

dawehner’s picture

StatusFileSize
new5.73 KB
new1.01 KB

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.