public function PriceItem::getConstraints in Commerce Core 8.2
Gets a list of validation constraints.
Return value
array Array of constraints, each being an instance of \Symfony\Component\Validator\Constraint.
Overrides TypedData::getConstraints
File
- modules/
price/ src/ Plugin/ Field/ FieldType/ PriceItem.php, line 126
Class
- PriceItem
- Plugin implementation of the 'commerce_price' field type.
Namespace
Drupal\commerce_price\Plugin\Field\FieldTypeCode
public function getConstraints() {
$constraint_manager = $this
->getTypedDataManager()
->getValidationConstraintManager();
$constraints = parent::getConstraints();
$constraints[] = $constraint_manager
->create('ComplexData', [
'number' => [
'Regex' => [
'pattern' => '/^[+-]?((\\d+(\\.\\d*)?)|(\\.\\d+))$/i',
],
],
]);
$available_currencies = array_filter($this
->getSetting('available_currencies'));
$constraints[] = $constraint_manager
->create('Currency', [
'availableCurrencies' => $available_currencies,
]);
return $constraints;
}