function Choice::__construct
Parameters
array|null $choices An array of choices (required unless a callback is specified):
callable|string|null $callback Callback method to use instead of the choice option to get the choices:
bool|null $multiple Whether to expect the value to be an array of valid choices (defaults to false):
bool|null $strict This option defaults to true and should not be used:
int<0, max>|null $min Minimum of valid choices if multiple values are expected:
positive-int|null $max Maximum of valid choices if multiple values are expected:
string[]|null $groups:
bool|null $match Whether to validate the values are part of the choices or not (defaults to true):
Overrides Constraint::__construct
2 calls to Choice::__construct()
- AllowedValuesConstraint::__construct in core/
lib/ Drupal/ Core/ Validation/ Plugin/ Validation/ Constraint/ AllowedValuesConstraint.php - Initializes the constraint with options.
- AllowedValuesConstraint::__construct in core/
lib/ Drupal/ Core/ Validation/ Plugin/ Validation/ Constraint/ AllowedValuesConstraint.php - Initializes the constraint with options.
1 method overrides Choice::__construct()
- AllowedValuesConstraint::__construct in core/
lib/ Drupal/ Core/ Validation/ Plugin/ Validation/ Constraint/ AllowedValuesConstraint.php - Initializes the constraint with options.
File
-
vendor/
symfony/ validator/ Constraints/ Choice.php, line 62
Class
- Choice
- Validates that a value is one of a given set of valid choices.
Namespace
Symfony\Component\Validator\ConstraintsCode
public function __construct(string|array $options = [], ?array $choices = null, callable|string|null $callback = null, ?bool $multiple = null, ?bool $strict = null, ?int $min = null, ?int $max = null, ?string $message = null, ?string $multipleMessage = null, ?string $minMessage = null, ?string $maxMessage = null, ?array $groups = null, mixed $payload = null, ?bool $match = null) {
if (\is_array($options) && $options && array_is_list($options)) {
$choices ??= $options;
$options = [];
}
if (null !== $choices) {
$options['value'] = $choices;
}
parent::__construct($options, $groups, $payload);
$this->callback = $callback ?? $this->callback;
$this->multiple = $multiple ?? $this->multiple;
$this->strict = $strict ?? $this->strict;
$this->min = $min ?? $this->min;
$this->max = $max ?? $this->max;
$this->message = $message ?? $this->message;
$this->multipleMessage = $multipleMessage ?? $this->multipleMessage;
$this->minMessage = $minMessage ?? $this->minMessage;
$this->maxMessage = $maxMessage ?? $this->maxMessage;
$this->match = $match ?? $this->match;
}