@@ -63,6 +63,22 @@ class SmartDateFieldItemList extends DateTimeFieldItemList {
'#required'=>TRUE,
];
$element['min']=[
'#type'=>'textfield',
'#title'=>t('Minimum Date'),
// @todo Add link to token browser.
'#description'=>t('Minimum date that will be accepted. Leave blank to accept any value. Provide a date value formatted like YYYY-MM-DD or a valid token that will return a date value.'),
'#default_value'=>$default_value['min']??'',
];
$element['max']=[
'#type'=>'textfield',
'#title'=>t('Maximum Date'),
// @todo Add link to token browser.
'#description'=>t('Maximum date that will be accepted. Leave blank to accept any value. Provide a date value formatted like YYYY-MM-DD or a valid token that will return a date value.'),
@@ -107,10 +123,77 @@ class SmartDateFieldItemList extends DateTimeFieldItemList {
$form_state->setErrorByName('default_value_input][default_duration',$this->t('Please specify a default duration that is one of the provided options.'));
}
}
// Validate that if min and max are both set max >= min.
$limits_to_check=['min','max'];
$limits=[];
foreach($limits_to_checkas$check){
$user_val=$form_state->getValue([
'default_value_input',
$check,
])??'';
if(empty($user_val)){
continue;
}
$user_val=$this->validateLimit($user_val);
if($user_val!==FALSE){
$limits[$check]=$user_val;
}
else{
$form_state->setErrorByName('default_value_input]['.$check,$this->t('Invalid limit value provided. Please use either a date string in the format or YYYY-MM-DD or token.'));
}
}
if(count($limits)==2){
if($limits['min']>$limits['max']){
$form_state->setErrorByName('default_value_input][min',$this->t('The maximum date limit cannot be before the minimum.'));
}
}
// Use the parent class method to validate relative dates.