--- src/Plugin/Field/FieldWidget/TimestampDatetimeNoDefaultWidget.5 2016-02-01 08:46:53.000000000 +0000 +++ src/Plugin/Field/FieldWidget/TimestampDatetimeNoDefaultWidget.php 2016-02-01 08:53:21.000000000 +0000 @@ -18,8 +18,8 @@ * * @FieldWidget( * id = "datetime_timestamp_no_default", - * label = @Translation("Datetime Timestamp no default"), - * description = @Translation("An optional datetime field. Does not provide a default time if left blank."), + * label = @Translation("Datetime Timestamp with no default"), + * description = @Translation("An optional datetime field. Does not provide a default time if left blank. Defined by Scheduler module."), * field_types = { * "timestamp", * } @@ -32,11 +32,13 @@ */ public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) { $element = parent::formElement($items, $delta, $element, $form, $form_state); - // @todo Do not these lines. The #description is entirely replaced by custom - // text in scheduler_form_node_form_alter() + // Remove 'Leave blank to use the time of form submission' which is in the + // #description inherited from TimestampDatetimeWidget. The text here is not + // used because it is entirely replaced in scheduler_form_node_form_alter() + // However the widget is generic and may be used elsewhere in future. $date_format = DateFormat::load('html_date')->getPattern(); $time_format = DateFormat::load('html_time')->getPattern(); - $element['value']['#description'] = $this->t('Format: %format. Leave blank to disable.', array('%format' => Datetime::formatExample($date_format . ' ' . $time_format))); + $element['value']['#description'] = $this->t('Format: %format. Leave blank for no date.', array('%format' => Datetime::formatExample($date_format . ' ' . $time_format))); // Set the callback function to allow interception of the submitted user // input and add the default time if needed. It is too late to try this in @@ -50,10 +52,10 @@ * * This will intercept the user input before form validation is processed. */ - public function valueCallback(&$element, $input, FormStateInterface $form_state) { + 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'] : ''; + $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');