class DataListContains
Provides a 'List contains' condition.
@todo Add access callback information from Drupal 7? @todo Add group information from Drupal 7? @todo Add info alter
Plugin annotation
@Condition(
id = "rules_list_contains",
label = @Translation("List contains item"),
category = @Translation("Data"),
context_definitions = {
"list" = @ContextDefinition("list",
label = @Translation("List"),
description = @Translation("The list to be checked."),
assignment_restriction = "selector"
),
"item" = @ContextDefinition("any",
label = @Translation("Item"),
description = @Translation("The item to check for.")
),
}
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements \Drupal\Component\Plugin\PluginInspectionInterface, \Drupal\Component\Plugin\DerivativeInspectionInterface
- class \Drupal\Core\Plugin\PluginBase extends \Drupal\Component\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait
- class \Drupal\Core\Executable\ExecutablePluginBase extends \Drupal\Core\Plugin\PluginBase implements \Drupal\Core\Executable\ExecutableInterface, \Drupal\Core\Cache\CacheableDependencyInterface, \Drupal\Core\Plugin\ContextAwarePluginInterface uses \Drupal\Core\Plugin\ContextAwarePluginTrait
- class \Drupal\Core\Condition\ConditionPluginBase extends \Drupal\Core\Executable\ExecutablePluginBase implements \Drupal\Core\Condition\ConditionInterface uses \Drupal\Core\Plugin\ContextAwarePluginAssignmentTrait
- class \Drupal\rules\Core\RulesConditionBase extends \Drupal\Core\Condition\ConditionPluginBase implements \Drupal\rules\Core\RulesConditionInterface uses \Drupal\rules\Context\ContextProviderTrait, \Drupal\rules\Core\ExecutablePluginTrait, \Drupal\rules\Core\ConfigurationAccessControlTrait
- class \Drupal\rules\Plugin\Condition\DataListContains extends \Drupal\rules\Core\RulesConditionBase
- class \Drupal\rules\Core\RulesConditionBase extends \Drupal\Core\Condition\ConditionPluginBase implements \Drupal\rules\Core\RulesConditionInterface uses \Drupal\rules\Context\ContextProviderTrait, \Drupal\rules\Core\ExecutablePluginTrait, \Drupal\rules\Core\ConfigurationAccessControlTrait
- class \Drupal\Core\Condition\ConditionPluginBase extends \Drupal\Core\Executable\ExecutablePluginBase implements \Drupal\Core\Condition\ConditionInterface uses \Drupal\Core\Plugin\ContextAwarePluginAssignmentTrait
- class \Drupal\Core\Executable\ExecutablePluginBase extends \Drupal\Core\Plugin\PluginBase implements \Drupal\Core\Executable\ExecutableInterface, \Drupal\Core\Cache\CacheableDependencyInterface, \Drupal\Core\Plugin\ContextAwarePluginInterface uses \Drupal\Core\Plugin\ContextAwarePluginTrait
- class \Drupal\Core\Plugin\PluginBase extends \Drupal\Component\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait
Expanded class hierarchy of DataListContains
File
-
src/
Plugin/ Condition/ DataListContains.php, line 32
Namespace
Drupal\rules\Plugin\ConditionView source
class DataListContains extends RulesConditionBase {
/**
* Evaluate whether the list has the item.
*
* @param array|\Drupal\Core\TypedData\ListInterface $list
* List to be searched.
* @param mixed $item
* Item to be found in list.
*/
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);
}
}