Skip to content
Snippets Groups Projects
Commit e66f0fc3 authored by catch's avatar catch
Browse files

Issue #3497935 by prudloff, smustgrave: Renderer::getCurrentRenderContext()...

Issue #3497935 by prudloff, smustgrave: Renderer::getCurrentRenderContext() triggers a TypeError when there is no current request

(cherry picked from commit e7bb6157)
parent 892267a1
No related branches found
No related tags found
No related merge requests found
Pipeline #447271 passed
......@@ -652,6 +652,11 @@ public function executeInRenderContext(RenderContext $context, callable $callabl
*/
protected function getCurrentRenderContext() {
$request = $this->requestStack->getCurrentRequest();
if (is_null($request)) {
return NULL;
}
return static::$contextCollection[$request] ?? NULL;
}
......
......@@ -4,6 +4,7 @@
namespace Drupal\Tests\Core\Render;
use Drupal\Core\Render\RenderContext;
use Drupal\Component\Render\MarkupInterface;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Access\AccessResultInterface;
......@@ -1063,6 +1064,23 @@ public static function providerTestAddCacheableDependency() {
];
}
/**
* @covers ::hasRenderContext
*/
public function testHasRenderContext(): void {
// Tests with no render context.
$this->assertFalse($this->renderer->hasRenderContext());
// Tests in a render context.
$this->renderer->executeInRenderContext(new RenderContext(), function () {
$this->assertTrue($this->renderer->hasRenderContext());
});
// Test that the method works with no current request.
$this->requestStack->pop();
$this->assertFalse($this->renderer->hasRenderContext());
}
}
class TestAccessClass implements TrustedCallbackInterface {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment