Skip to content
Snippets Groups Projects
Commit c2e113ef authored by Gabe Sullice's avatar Gabe Sullice Committed by Simon Morvan
Browse files

Issue #3083723 by gabesullice: Try to respect misbehaving module cacheability

parent 7fad4925
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,7 @@
namespace Drupal\jsonapi_earlyrendering_workaround\EventSubscriber;
use Drupal\Core\Cache\CacheableResponseInterface;
use Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber as OriginalEarlyRenderingControllerWrapperSubscriber;
use Drupal\Core\Render\RenderContext;
......@@ -18,9 +19,14 @@ class EarlyRenderingControllerWrapperSubscriber extends OriginalEarlyRenderingCo
protected function wrapControllerExecutionInRenderContext($controller, array $arguments) {
if(get_class($controller[0]) === "Drupal\jsonapi\Controller\EntityResource"){
return $this->renderer->executeInRenderContext(new RenderContext(), function () use ($controller, $arguments) {
$context = new RenderContext();
$response = $this->renderer->executeInRenderContext($context, function () use ($controller, $arguments) {
return call_user_func_array($controller, $arguments);
});
if (!$context->isEmpty() && $response instanceof CacheableResponseInterface) {
$response->addCacheableDependency($context->pop());
}
return $response;
}
return $this->originalService->wrapControllerExecutionInRenderContext($controller, $arguments);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment