diff --git a/core/lib/Drupal/Core/Render/Placeholder/PlaceholderStrategyManager.php b/core/lib/Drupal/Core/Render/Placeholder/PlaceholderStrategyManager.php index ed34e60..bcb1a00 100644 --- a/core/lib/Drupal/Core/Render/Placeholder/PlaceholderStrategyManager.php +++ b/core/lib/Drupal/Core/Render/Placeholder/PlaceholderStrategyManager.php @@ -39,10 +39,16 @@ public function processPlaceholders(array $placeholders) { return []; } + // In case there are no placeholder strategies, return all placeholders. + if (empty($this->placeholderStrategies)) { + return $placeholders; + } + $new_placeholders = []; // Give each render strategy a chance to replace all not-yet replaced - // placeholders. + // placeholders. The order of placeholder strategies is well defined + // and this uses a variation of the "chain of responsibility" design pattern. foreach ($this->placeholderStrategies as $strategy) { $processed_placeholders = $strategy->processPlaceholders($placeholders); $placeholders = array_diff_key($placeholders, $processed_placeholders); diff --git a/core/lib/Drupal/Core/Render/Placeholder/SingleFlushStrategy.php b/core/lib/Drupal/Core/Render/Placeholder/SingleFlushStrategy.php index 2c47c8d..61fea0f 100644 --- a/core/lib/Drupal/Core/Render/Placeholder/SingleFlushStrategy.php +++ b/core/lib/Drupal/Core/Render/Placeholder/SingleFlushStrategy.php @@ -10,7 +10,8 @@ /** * Defines the 'single_flush' placeholder strategy. * - * This is the last strategy that always replaces all remaining placeholders. + * This is designed to be the fallback strategy, so should have the lowest + * priority. */ class SingleFlushStrategy implements PlaceholderStrategyInterface { diff --git a/core/tests/Drupal/Tests/Core/Render/Placeholder/PlaceholderStrategyManagerTest.php b/core/tests/Drupal/Tests/Core/Render/Placeholder/PlaceholderStrategyManagerTest.php index a4a5be1..4018a0b 100644 --- a/core/tests/Drupal/Tests/Core/Render/Placeholder/PlaceholderStrategyManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Render/Placeholder/PlaceholderStrategyManagerTest.php @@ -43,6 +43,12 @@ public function providerProcessPlaceholders() { // Empty placeholders. $data[] = [[], [], []]; + // Placeholders but no strategies defined. + $placeholders = [ + 'ignore-me' => ['#markup' => 'I-am-a-llama-that-will-be-ignored-by-the-placeholder-strategy-manager.'], + ]; + $data[] = [[], $placeholders, $placeholders]; + // Placeholder removing strategy. $placeholders = [ 'remove-me' => ['#markup' => 'I-am-a-llama-that-will-be-removed-sad-face.'],