You are here

public function EntityFieldNullCompareType::evaluate in Entity Field Condition 2.0.x

Evaluate the entity field value.

Parameters

\Drupal\Core\Entity\ContentEntityInterface $entity: The entity instance.

string $field_name: The entity field name.

Return value

bool Return TRUE if the field value compare is valid, otherwise FALSE.

Overrides EntityFieldCompareTypeInterface::evaluate

File

src/Plugin/EntityFieldCondition/CompareType/EntityFieldNullCompareType.php, line 23

Class

EntityFieldNullCompareType
Define the entity field NULL compare type plugin.

Namespace

Drupal\entity_field_condition\Plugin\EntityFieldCondition\CompareType

Code

public function evaluate(ContentEntityInterface $entity, string $field_name) : bool {
  if (!$entity
    ->hasField($field_name)) {
    return FALSE;
  }
  return $entity
    ->get($field_name)->value === NULL;
}