public function MenuPositionRule::isActive in Menu Position 8
Evaluates all conditions attached to this rule and determines if this rule is "active" or not.
Return value
bool Whether or not this rule is active.
File
- src/
Entity/ MenuPositionRule.php, line 266
Class
- MenuPositionRule
- Defines the MenuPositionRule entity.
Namespace
Drupal\menu_position\EntityCode
public function isActive() {
// Must be enabled.
if (!$this
->getEnabled()) {
return FALSE;
}
// Rules are good unless told otherwise by the conditions.
foreach ($this
->getConditions() as $condition) {
// Need to get context for this condition.
if ($condition instanceof ContextAwarePluginInterface) {
// Get runtime contexts and set them for this condition.
$runtime_contexts = $this
->contextRepository()
->getRuntimeContexts($condition
->getContextMapping());
$condition_contexts = $condition
->getContextDefinitions();
foreach ($condition
->getContextMapping() as $name => $context) {
// Attach appropriate context.
if (isset($runtime_contexts[$context]) && $runtime_contexts[$context]
->hasContextValue()) {
$condition
->setContext($name, $runtime_contexts[$context]);
}
elseif ($condition_contexts[$name]
->isRequired()) {
return FALSE;
}
}
}
// If this condition evaluates to false, rule is inactive.
if (!$condition
->execute()) {
return FALSE;
}
}
// No objections, rule is active.
return TRUE;
}