You are here

public static function CalendarSystemsTimestampDatetimeNoDefaultWidget::valueCallback in Calendar Systems 8.3

Callback function to add default time to the input date if needed.

This will intercept the user input before form validation is processed.

File

src/Plugin/Field/FieldWidget/CalendarSystemsTimestampDatetimeNoDefaultWidget.php, line 38

Class

CalendarSystemsTimestampDatetimeNoDefaultWidget
Replaces core's widget with a localizable one.

Namespace

Drupal\calendar_systems\Plugin\Field\FieldWidget

Code

public static function valueCallback(&$element, $input, FormStateInterface $form_state) {
  if ($input !== FALSE) {
    $date_input = $element['#date_date_element'] != 'none' && !empty($input['date']) ? $input['date'] : '';
    $time_input = $element['#date_time_element'] != 'none' && !empty($input['time']) ? $input['time'] : '';

    // If there is an input date but no time and the date-only option is on
    // then set the input time to the default specified by scheduler options.
    $config = Drupal::config('scheduler.settings');
    if (!empty($date_input) && empty($time_input) && $config
      ->get('allow_date_only')) {
      $input['time'] = $config
        ->get('default_time');
    }
  }

  // Chain on to the standard valueCallback for Datetime as we do not want to
  // duplicate that core code here.
  return CalendarSystemsDateTime::valueCallback($element, $input, $form_state);
}