class ChainedPlaceholderStrategy in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/lib/Drupal/Core/Render/Placeholder/ChainedPlaceholderStrategy.php \Drupal\Core\Render\Placeholder\ChainedPlaceholderStrategy
Renders placeholders using a chain of placeholder strategies.
Hierarchy
- class \Drupal\Core\Render\Placeholder\ChainedPlaceholderStrategy implements PlaceholderStrategyInterface
Expanded class hierarchy of ChainedPlaceholderStrategy
1 file declares its use of ChainedPlaceholderStrategy
- ChainedPlaceholderStrategyTest.php in core/
tests/ Drupal/ Tests/ Core/ Render/ Placeholder/ ChainedPlaceholderStrategyTest.php - Contains \Drupal\Tests\Core\Render\Placeholder\ChainedPlaceholderStrategyTest.
1 string reference to 'ChainedPlaceholderStrategy'
- core.services.yml in core/
core.services.yml - core/core.services.yml
1 service uses ChainedPlaceholderStrategy
File
- core/
lib/ Drupal/ Core/ Render/ Placeholder/ ChainedPlaceholderStrategy.php, line 13 - Contains \Drupal\Core\Render\Placeholder\ChainedPlaceholderStrategy.
Namespace
Drupal\Core\Render\PlaceholderView source
class ChainedPlaceholderStrategy implements PlaceholderStrategyInterface {
/**
* An ordered list of placeholder strategy services.
*
* Ordered according to service priority.
*
* @var \Drupal\Core\Render\Placeholder\PlaceholderStrategyInterface[]
*/
protected $placeholderStrategies = [];
/**
* Adds a placeholder strategy to use.
*
* @param \Drupal\Core\Render\Placeholder\PlaceholderStrategyInterface $strategy
* The strategy to add to the placeholder strategies.
*/
public function addPlaceholderStrategy(PlaceholderStrategyInterface $strategy) {
$this->placeholderStrategies[] = $strategy;
}
/**
* {@inheritdoc}
*/
public function processPlaceholders(array $placeholders) {
if (empty($placeholders)) {
return [];
}
// Assert that there is at least one strategy.
assert('!empty($this->placeholderStrategies)', 'At least one placeholder strategy must be present; by default the fallback strategy \\Drupal\\Core\\Render\\Placeholder\\SingleFlushStrategy is always present.');
$new_placeholders = [];
// Give each placeholder strategy a chance to replace all not-yet replaced
// 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);
assert('array_intersect_key($processed_placeholders, $placeholders) === $processed_placeholders', 'Processed placeholders must be a subset of all placeholders.');
$placeholders = array_diff_key($placeholders, $processed_placeholders);
$new_placeholders += $processed_placeholders;
if (empty($placeholders)) {
break;
}
}
return $new_placeholders;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ChainedPlaceholderStrategy:: |
protected | property | An ordered list of placeholder strategy services. | |
ChainedPlaceholderStrategy:: |
public | function | Adds a placeholder strategy to use. | |
ChainedPlaceholderStrategy:: |
public | function |
Processes placeholders to render them with different strategies. Overrides PlaceholderStrategyInterface:: |