You are here

public static function DatexTimestampDatetimeNoDefaultWidget::valueCallback in Datex 8

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/DatexTimestampDatetimeNoDefaultWidget.php, line 53

Class

DatexTimestampDatetimeNoDefaultWidget
Replaces core's widget with a localizable one.

Namespace

Drupal\datex\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 DatexDateTime::valueCallback($element, $input, $form_state);
}