public function OptionalEndDateDateRangeItem::getConstraints in Optional End Date 8
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
- src/
Plugin/ Field/ FieldType/ OptionalEndDateDateRangeItem.php, line 62
Class
- OptionalEndDateDateRangeItem
- Custom DateRangeItem for optional end_value.
Namespace
Drupal\optional_end_date\Plugin\Field\FieldTypeCode
public function getConstraints() {
$constraint_manager = \Drupal::typedDataManager()
->getValidationConstraintManager();
$constraints = parent::getConstraints();
if (empty($this
->getSetting('optional_end_date'))) {
$label = $this
->getFieldDefinition()
->getLabel();
$constraints[] = $constraint_manager
->create('ComplexData', [
'end_value' => [
'NotNull' => [
'message' => $this
->t('The @title end date is required', [
'@title' => $label,
]),
],
],
]);
}
return $constraints;
}