function DataListContains::doEvaluate

Evaluate whether the list has the item.

Parameters

array|\Drupal\Core\TypedData\ListInterface $list: List to be searched.

mixed $item: Item to be found in list.

File

src/Plugin/Condition/DataListContains.php, line 42

Class

DataListContains
Provides a 'List contains' condition.

Namespace

Drupal\rules\Plugin\Condition

Code

protected function doEvaluate($list, $item) {
    if ($item instanceof EntityInterface && ($id = $item->id())) {
        // Check for equal items using the identifier if there is one.
        foreach ($list as $list_item) {
            if ($list_item->id() == $id) {
                return TRUE;
            }
        }
        return FALSE;
    }
    return in_array($item, $list);
}