class DataListCountIs
Provides a 'List count comparison' condition.
@todo Add access callback information from Drupal 7?
Plugin annotation
@Condition(
id = "rules_list_count_is",
label = @Translation("List count comparison"),
category = @Translation("Data"),
context_definitions = {
"list" = @ContextDefinition("list",
label = @Translation("List"),
description = @Translation("A multi-valued data element to have its count compared, specified by using a data selector, eg 'node.uid.entity.roles'."),
assignment_restriction = "selector"
),
"operator" = @ContextDefinition("string",
label = @Translation("Operator"),
description = @Translation("The comparison operator."),
options_provider = "\Drupal\rules\TypedData\Options\ComparisonOperatorNumericOptions",
assignment_restriction = "input",
default_value = "==",
required = FALSE
),
"value" = @ContextDefinition("integer",
label = @Translation("Count"),
description = @Translation("The count to compare the data count with.")
),
}
)
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\DataListCountIs 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 DataListCountIs
File
-
src/
Plugin/ Condition/ DataListCountIs.php, line 37
Namespace
Drupal\rules\Plugin\ConditionView source
class DataListCountIs extends RulesConditionBase {
/**
* Compare the value to the count of the list.
*
* @param array $list
* The list to compare the value to.
* @param string $operator
* The type of comparison to do, may be one of '==', '<', or '>'.
* @param int $value
* The value of that the count is to compare to.
*
* @return bool
* TRUE if the comparison returns true.
*/
protected function doEvaluate(array $list, $operator, $value) {
switch ($operator) {
case '==':
return count($list) == $value;
case '<':
return count($list) < $value;
case '<=':
return count($list) <= $value;
case '>':
return count($list) > $value;
case '>=':
return count($list) >= $value;
}
}
}