public function EntityExtraField::hasConditionsBeenMet in Entity Extra Field 8
Same name and namespace in other branches
- 2.0.x src/Entity/EntityExtraField.php \Drupal\entity_extra_field\Entity\EntityExtraField::hasConditionsBeenMet()
Has extra field conditions been met.
Parameters
array $contexts: An array of context values.
bool $all_must_pass: Determine if all conditions must pass.
Return value
bool Return TRUE if the extra field conditions have been met; otherwise FALSE.
Throws
\Drupal\Component\Plugin\Exception\PluginException
Overrides EntityExtraFieldInterface::hasConditionsBeenMet
File
- src/
Entity/ EntityExtraField.php, line 303
Class
- EntityExtraField
- Define entity extra field.
Namespace
Drupal\entity_extra_field\EntityCode
public function hasConditionsBeenMet(array $contexts, $all_must_pass = FALSE) {
$conditions = $this
->getActiveFieldTypeConditions();
if (empty($conditions)) {
return TRUE;
}
$verdicts = [];
foreach ($this
->getActiveFieldTypeConditions() as $plugin_id => $configuration) {
/** @var \Drupal\Core\Condition\ConditionPluginBase $condition */
$condition = $this
->conditionPluginManager()
->createInstance($plugin_id, $configuration);
if ($context_definitions = $condition
->getContextDefinitions()) {
$condition_contexts = array_intersect_key($contexts, $context_definitions);
foreach ($condition_contexts as $name => $context) {
$condition
->setContextValue($name, $context);
}
}
$verdict = $condition
->evaluate();
if ($verdict && !$all_must_pass) {
return TRUE;
}
$verdicts[] = $verdict;
}
$verdicts = array_unique($verdicts);
return count($verdicts) === 1 && current($verdicts) === TRUE;
}