function social_event_date_validate in Open Social 8.9
Same name and namespace in other branches
- 8.3 modules/social_features/social_event/social_event.module \social_event_date_validate()
- 8.4 modules/social_features/social_event/social_event.module \social_event_date_validate()
- 8.5 modules/social_features/social_event/social_event.module \social_event_date_validate()
- 8.6 modules/social_features/social_event/social_event.module \social_event_date_validate()
- 8.7 modules/social_features/social_event/social_event.module \social_event_date_validate()
- 8.8 modules/social_features/social_event/social_event.module \social_event_date_validate()
- 10.3.x modules/social_features/social_event/social_event.module \social_event_date_validate()
- 10.0.x modules/social_features/social_event/social_event.module \social_event_date_validate()
- 10.1.x modules/social_features/social_event/social_event.module \social_event_date_validate()
- 10.2.x modules/social_features/social_event/social_event.module \social_event_date_validate()
Set default time to the date field if time was not set.
1 string reference to 'social_event_date_validate'
- social_event_date_after_build in modules/
social_features/ social_event/ social_event.module - Add custom validation to event date fields.
File
- modules/
social_features/ social_event/ social_event.module, line 741 - The Social event module.
Code
function social_event_date_validate(&$element, FormStateInterface $form_state, &$complete_form) {
$input = NestedArray::getValue($form_state
->getValues(), $element['#parents']);
$form_input = $form_state
->getUserInput();
// Skip default validation for required time when date is required.
if (!empty($input['date']) && (empty($input['time']) || !empty($form_input['event_all_day']))) {
$input['time'] = '00:01:00';
$storage_format = DrupalDateTime::FORMAT;
$datetime = trim($input['date'] . ' ' . $input['time']);
$storage_timezone = new DateTimeZone(DateTimeItemInterface::STORAGE_TIMEZONE);
$input['object'] = DrupalDateTime::createFromFormat($storage_format, $datetime, $storage_timezone);
if ($input['object'] instanceof DrupalDateTime) {
$form_state
->setValueForElement($element, $input);
}
}
}