function DataIsEmpty::evaluate

Overrides RulesConditionBase::evaluate

File

src/Plugin/Condition/DataIsEmpty.php, line 35

Class

DataIsEmpty
Provides a 'Data value is empty' condition.

Namespace

Drupal\rules\Plugin\Condition

Code

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);
}