You are here

function social_event_date_validate in Open Social 10.3.x

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_event/social_event.module \social_event_date_validate()
  2. 8.3 modules/social_features/social_event/social_event.module \social_event_date_validate()
  3. 8.4 modules/social_features/social_event/social_event.module \social_event_date_validate()
  4. 8.5 modules/social_features/social_event/social_event.module \social_event_date_validate()
  5. 8.6 modules/social_features/social_event/social_event.module \social_event_date_validate()
  6. 8.7 modules/social_features/social_event/social_event.module \social_event_date_validate()
  7. 8.8 modules/social_features/social_event/social_event.module \social_event_date_validate()
  8. 10.0.x modules/social_features/social_event/social_event.module \social_event_date_validate()
  9. 10.1.x modules/social_features/social_event/social_event.module \social_event_date_validate()
  10. 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 740
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);
    }
  }
}