public function DataIsEmpty::evaluate in Rules 8.3
Evaluates the condition and returns TRUE or FALSE accordingly.
Return value
bool TRUE if the condition has been met, FALSE otherwise.
Overrides RulesConditionBase::evaluate
File
- src/
Plugin/ Condition/ DataIsEmpty.php, line 35
Class
- DataIsEmpty
- Provides a 'Data value is empty' condition.
Namespace
Drupal\rules\Plugin\ConditionCode
public function evaluate() {
$data = $this
->getContext('data')
->getContextData();
if ($data instanceof ComplexDataInterface || $data instanceof ListInterface) {
return $data
->isEmpty();
}
$value = $data
->getValue();
// For some primitives we can rely on PHP's type casting to boolean.
if ($data instanceof StringInterface || $data instanceof IntegerInterface || $data instanceof BooleanInterface) {
return !isset($value) || !$value;
}
return !isset($value);
}