RulesConditionBase.php in Rules 8.3
File
src/Core/RulesConditionBase.php
View source
<?php
namespace Drupal\rules\Core;
use Drupal\Component\Plugin\Exception\ContextException;
use Drupal\Core\Condition\ConditionPluginBase;
use Drupal\rules\Context\ContextProviderTrait;
abstract class RulesConditionBase extends ConditionPluginBase implements RulesConditionInterface {
use ContextProviderTrait;
use ExecutablePluginTrait;
use ConfigurationAccessControlTrait;
public function refineContextDefinitions(array $selected_data) {
}
public function assertMetadata(array $selected_data) {
return [];
}
public function getContextValue($name) {
try {
return parent::getContextValue($name);
} catch (ContextException $e) {
if (strpos($e
->getMessage(), 'context is required') === FALSE) {
throw $e;
}
}
}
public function negate($negate = TRUE) {
$this->configuration['negate'] = $negate;
return $this;
}
public function evaluate() {
$args = [];
foreach ($this
->getContextDefinitions() as $name => $definition) {
$args[$name] = $this
->getContextValue($name);
}
return call_user_func_array([
$this,
'doEvaluate',
], $args);
}
}