public function ContextManager::getActiveReactions in Context 8
Same name and namespace in other branches
- 8.4 src/ContextManager.php \Drupal\context\ContextManager::getActiveReactions()
- 8.0 src/ContextManager.php \Drupal\context\ContextManager::getActiveReactions()
Get all active reactions or reactions of a certain type.
Parameters
string $reactionType: Either the reaction class name or the id of the reaction type to get.
Return value
File
- src/
ContextManager.php, line 217
Class
- ContextManager
- This is the manager service for the context module and should not be confused with the built in contexts in Drupal.
Namespace
Drupal\contextCode
public function getActiveReactions($reactionType = NULL) {
$reactions = [];
foreach ($this
->getActiveContexts() as $context) {
// If no reaction type has been specified then add all reactions and
// continue to the next context.
if (is_null($reactionType)) {
foreach ($context
->getReactions() as $reaction) {
// Only return block reaction if there is a block applied to the current theme.
if ($reaction instanceof Blocks) {
$blocks = $reaction
->getBlocks();
$current_theme = $this
->getCurrentTheme();
foreach ($blocks as $block) {
if ($block
->getConfiguration()['theme'] == $current_theme) {
$reactions[] = $reaction;
break;
}
}
}
else {
$reactions[] = $reaction;
}
}
continue;
}
$contextReactions = $context
->getReactions();
// Filter the reactions based on the reaction type.
foreach ($contextReactions as $reaction) {
if (class_exists($reactionType) && $reaction instanceof $reactionType) {
$reactions[] = $reaction;
continue;
}
if ($reaction
->getPluginId() === $reactionType) {
$reactions[] = $reaction;
continue;
}
}
}
return $reactions;
}