diff --git a/core/core.services.yml b/core/core.services.yml index dc79944..0b5a286 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -1507,20 +1507,20 @@ services: arguments: ['@controller_resolver', '@renderer'] tags: - { name: event_subscriber } - # Render strategies for rendering placeholders. - render_strategy_html.subscriber: - class: Drupal\Core\EventSubscriber\HtmlRenderStrategySubscriber + # Placeholder strategies for rendering placeholders. + html_response.placeholder_strategy_subscriber: + class: Drupal\Core\EventSubscriber\HtmlResponsePlaceholderStrategySubscriber tags: - { name: event_subscriber } - arguments: ['@render_strategy_manager'] - render_strategy_manager: - class: Drupal\Core\Render\Strategy\RenderStrategyManager + arguments: ['@placeholder_strategy_manager'] + placeholder_strategy_manager: + class: Drupal\Core\Render\Placeholder\PlaceholderStrategyManager tags: - - { name: service_collector, tag: render_strategy, call: addRenderStrategy } - render_strategy.single_flush: - class: Drupal\Core\Render\Strategy\SingleFlushRenderStrategy + - { name: service_collector, tag: placeholder_strategy, call: addPlaceholderStrategy } + placeholder_strategy.single_flush: + class: Drupal\Core\Render\Placeholder\SingleFlushStrategy tags: - - { name: render_strategy, priority: -1000 } + - { name: placeholder_strategy, priority: -1000 } email.validator: class: Egulias\EmailValidator\EmailValidator diff --git a/core/lib/Drupal/Core/EventSubscriber/HtmlResponsePlaceholderStrategySubscriber.php b/core/lib/Drupal/Core/EventSubscriber/HtmlResponsePlaceholderStrategySubscriber.php index c93e0b0..9953f83 100644 --- a/core/lib/Drupal/Core/EventSubscriber/HtmlResponsePlaceholderStrategySubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/HtmlResponsePlaceholderStrategySubscriber.php @@ -2,37 +2,37 @@ /** * @file - * Contains \Drupal\Core\EventSubscriber\HtmlRenderStrategySubscriber. + * Contains \Drupal\Core\EventSubscriber\HtmlResponsePlaceholderStrategySubscriber. */ namespace Drupal\Core\EventSubscriber; use Drupal\Core\Render\HtmlResponse; -use Drupal\Core\Render\Strategy\RenderStrategyInterface; +use Drupal\Core\Render\Placeholder\PlaceholderStrategyInterface; use Symfony\Component\HttpKernel\Event\FilterResponseEvent; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** - * HTML Response subscriber to handle placeholder render strategies. + * HTML Response subscriber to handle placeholder strategies. */ -class HtmlRenderStrategySubscriber implements EventSubscriberInterface { +class HtmlResponsePlaceholderStrategySubscriber implements EventSubscriberInterface { /** - * The render strategy manager service. + * The placeholder strategy manager service. * - * @var \Drupal\Core\Render\Strategy\RenderStrategyInterface + * @var \Drupal\Core\Render\Placeholder\PlaceholderStrategyInterface */ - protected $renderStrategyManager; + protected $placeholderStrategyManager; /** - * Constructs a HtmlRenderStrategySubscriber object. + * Constructs a HtmlResponsePlaceholderStrategySubscriber object. * - * @param \Drupal\Core\Render\Strategy\RenderStrategyInterface $render_strategy_manager - * The render strategy manager service. + * @param \Drupal\Core\Render\Placeholder\PlaceholderStrategyInterface $placeholder_strategy_manager + * The placeholder strategy manager service. */ - public function __construct(RenderStrategyInterface $render_strategy_manager) { - $this->renderStrategyManager = $render_strategy_manager; + public function __construct(PlaceholderStrategyInterface $placeholder_strategy_manager) { + $this->placeholderStrategyManager = $placeholder_strategy_manager; } /** @@ -56,7 +56,7 @@ public function onRespond(FilterResponseEvent $event) { return; } - $attachments['placeholders'] = $this->renderStrategyManager->processPlaceholders($attachments['placeholders']); + $attachments['placeholders'] = $this->placeholderStrategyManager->processPlaceholders($attachments['placeholders']); $response->setAttachments($attachments); $event->setResponse($response); diff --git a/core/lib/Drupal/Core/Render/Placeholder/PlaceholderStrategyInterface.php b/core/lib/Drupal/Core/Render/Placeholder/PlaceholderStrategyInterface.php index e6abbd5..8f10822 100644 --- a/core/lib/Drupal/Core/Render/Placeholder/PlaceholderStrategyInterface.php +++ b/core/lib/Drupal/Core/Render/Placeholder/PlaceholderStrategyInterface.php @@ -2,15 +2,15 @@ /** * @file - * Contains \Drupal\Core\Render\Strategy\RenderStrategyInterface. + * Contains \Drupal\Core\Render\Placeholder\PlaceholderStrategyInterface. */ -namespace Drupal\Core\Render\Strategy; +namespace Drupal\Core\Render\Placeholder; /** - * Provides an interface for defining a render strategy service. + * Provides an interface for defining a placeholder strategy service. */ -interface RenderStrategyInterface { +interface PlaceholderStrategyInterface { /** * Processes placeholders to render them with different strategies. diff --git a/core/lib/Drupal/Core/Render/Placeholder/PlaceholderStrategyManager.php b/core/lib/Drupal/Core/Render/Placeholder/PlaceholderStrategyManager.php index 9f188e0..ed34e60 100644 --- a/core/lib/Drupal/Core/Render/Placeholder/PlaceholderStrategyManager.php +++ b/core/lib/Drupal/Core/Render/Placeholder/PlaceholderStrategyManager.php @@ -2,33 +2,33 @@ /** * @file - * Contains \Drupal\Core\Render\Strategy\RenderStrategyManager. + * Contains \Drupal\Core\Render\Placeholder\PlaceholderStrategyManager. */ -namespace Drupal\Core\Render\Strategy; +namespace Drupal\Core\Render\Placeholder; use Drupal\Core\Render\RendererInterface; /** * Provides a class which allows to render placeholders. */ -class RenderStrategyManager implements RenderStrategyInterface { +class PlaceholderStrategyManager implements PlaceholderStrategyInterface { /** - * The RenderStrategy services. + * The placeholder strategy services. * - * @var Drupal\Core\Render\Strategy\RenderStrategyInterface[] + * @var Drupal\Core\Render\Placeholder\PlaceholderStrategyInterface[] */ - protected $renderStrategies; + protected $placeholderStrategies; /** * Adds a render strategy to process. * - * @param RenderStrategyInterface $strategy + * @param PlaceholderStrategyInterface $strategy * The strategy to add to the render strategies. */ - public function addRenderStrategy(RenderStrategyInterface $strategy) { - $this->renderStrategies[] = $strategy; + public function addPlaceholderStrategy(PlaceholderStrategyInterface $strategy) { + $this->placeholderStrategies[] = $strategy; } /** @@ -43,7 +43,7 @@ public function processPlaceholders(array $placeholders) { // Give each render strategy a chance to replace all not-yet replaced // placeholders. - foreach ($this->renderStrategies as $strategy) { + foreach ($this->placeholderStrategies as $strategy) { $processed_placeholders = $strategy->processPlaceholders($placeholders); $placeholders = array_diff_key($placeholders, $processed_placeholders); $new_placeholders += $processed_placeholders; diff --git a/core/lib/Drupal/Core/Render/Placeholder/SingleFlushStrategy.php b/core/lib/Drupal/Core/Render/Placeholder/SingleFlushStrategy.php index 7bed91e..2c47c8d 100644 --- a/core/lib/Drupal/Core/Render/Placeholder/SingleFlushStrategy.php +++ b/core/lib/Drupal/Core/Render/Placeholder/SingleFlushStrategy.php @@ -2,17 +2,17 @@ /** * @file - * Contains \Drupal\Core\Render\Strategy\SingleFlushRenderStrategy + * Contains \Drupal\Core\Render\Placeholder\SingleFlushStrategy */ -namespace Drupal\Core\Render\Strategy; +namespace Drupal\Core\Render\Placeholder; /** - * Defines the 'single_flush' render strategy. + * Defines the 'single_flush' placeholder strategy. * * This is the last strategy that always replaces all remaining placeholders. */ -class SingleFlushRenderStrategy implements RenderStrategyInterface { +class SingleFlushStrategy implements PlaceholderStrategyInterface { /** * {@inheritdoc} diff --git a/core/tests/Drupal/Tests/Core/Render/Placeholder/PlaceholderStrategyManagerTest.php b/core/tests/Drupal/Tests/Core/Render/Placeholder/PlaceholderStrategyManagerTest.php index 329159b..a4a5be1 100644 --- a/core/tests/Drupal/Tests/Core/Render/Placeholder/PlaceholderStrategyManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Render/Placeholder/PlaceholderStrategyManagerTest.php @@ -2,31 +2,31 @@ /** * @file - * Contains \Drupal\Tests\Core\Render\Strategy\RenderStrategyManagerTest. + * Contains \Drupal\Tests\Core\Render\Placeholder\PlaceholderStrategyManagerTest. */ -namespace Drupal\Tests\Core\Render\Strategy; +namespace Drupal\Tests\Core\Render\Placeholder; -use Drupal\Core\Render\Strategy\RenderStrategyManager; +use Drupal\Core\Render\Placeholder\PlaceholderStrategyManager; use Drupal\Tests\UnitTestCase; /** - * @coversDefaultClass \Drupal\Core\Render\Strategy\RenderStrategyManager + * @coversDefaultClass \Drupal\Core\Render\Placeholder\PlaceholderStrategyManager * @group Render */ -class RenderStrategyManagerTest extends UnitTestCase { +class PlaceholderStrategyManagerTest extends UnitTestCase { /** - * @covers ::addRenderStrategy + * @covers ::addPlaceholderStrategy * @covers ::processPlaceholders * * @dataProvider providerProcessPlaceholders */ public function testProcessPlaceholdersSingleFlush($strategies, $placeholders, $result) { - $render_strategy_manager = new RenderStrategyManager(); + $render_strategy_manager = new PlaceholderStrategyManager(); foreach ($strategies as $strategy) { - $render_strategy_manager->addRenderStrategy($strategy); + $render_strategy_manager->addPlaceholderStrategy($strategy); } $this->assertEquals($result, $render_strategy_manager->processPlaceholders($placeholders)); @@ -48,7 +48,7 @@ public function providerProcessPlaceholders() { 'remove-me' => ['#markup' => 'I-am-a-llama-that-will-be-removed-sad-face.'], ]; - $prophecy = $this->prophesize('\Drupal\Core\Render\Strategy\RenderStrategyInterface'); + $prophecy = $this->prophesize('\Drupal\Core\Render\Placeholder\PlaceholderStrategyInterface'); $prophecy->processPlaceholders($placeholders)->willReturn([]); $dev_null_strategy = $prophecy->reveal(); @@ -59,7 +59,7 @@ public function providerProcessPlaceholders() { '67890' => ['#markup' => 'special-placeholder'], ]; - $prophecy = $this->prophesize('\Drupal\Core\Render\Strategy\RenderStrategyInterface'); + $prophecy = $this->prophesize('\Drupal\Core\Render\Placeholder\PlaceholderStrategyInterface'); $prophecy->processPlaceholders($placeholders)->willReturn($placeholders); $single_flush_strategy = $prophecy->reveal(); @@ -73,18 +73,18 @@ public function providerProcessPlaceholders() { '12345' => ['#markup' => ''], ]; - $prophecy = $this->prophesize('\Drupal\Core\Render\Strategy\RenderStrategyInterface'); + $prophecy = $this->prophesize('\Drupal\Core\Render\Placeholder\PlaceholderStrategyInterface'); $prophecy->processPlaceholders($placeholders)->willReturn($result); $esi_strategy = $prophecy->reveal(); $data[] = [[$esi_strategy], $placeholders, $result]; // ESI + SingleFlush strategy (ESI replaces all). - $prophecy = $this->prophesize('\Drupal\Core\Render\Strategy\RenderStrategyInterface'); + $prophecy = $this->prophesize('\Drupal\Core\Render\Placeholder\PlaceholderStrategyInterface'); $prophecy->processPlaceholders($placeholders)->willReturn($result); $esi_strategy = $prophecy->reveal(); - $prophecy = $this->prophesize('\Drupal\Core\Render\Strategy\RenderStrategyInterface'); + $prophecy = $this->prophesize('\Drupal\Core\Render\Placeholder\PlaceholderStrategyInterface'); $single_flush_strategy = $prophecy->reveal(); $data[] = [[$esi_strategy, $single_flush_strategy], $placeholders, $result]; @@ -107,11 +107,11 @@ public function providerProcessPlaceholders() { $result = $esi_result + $normal_result; - $prophecy = $this->prophesize('\Drupal\Core\Render\Strategy\RenderStrategyInterface'); + $prophecy = $this->prophesize('\Drupal\Core\Render\Placeholder\PlaceholderStrategyInterface'); $prophecy->processPlaceholders($placeholders)->willReturn($esi_result); $esi_strategy = $prophecy->reveal(); - $prophecy = $this->prophesize('\Drupal\Core\Render\Strategy\RenderStrategyInterface'); + $prophecy = $this->prophesize('\Drupal\Core\Render\Placeholder\PlaceholderStrategyInterface'); $prophecy->processPlaceholders($normal_result)->willReturn($normal_result); $single_flush_strategy = $prophecy->reveal();