function TimestampDatetimeWidget::massageFormValues

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/Datetime/Plugin/Field/FieldWidget/TimestampDatetimeWidget.php \Drupal\Core\Datetime\Plugin\Field\FieldWidget\TimestampDatetimeWidget::massageFormValues()
  2. 10 core/lib/Drupal/Core/Datetime/Plugin/Field/FieldWidget/TimestampDatetimeWidget.php \Drupal\Core\Datetime\Plugin\Field\FieldWidget\TimestampDatetimeWidget::massageFormValues()
  3. 11.x core/lib/Drupal/Core/Datetime/Plugin/Field/FieldWidget/TimestampDatetimeWidget.php \Drupal\Core\Datetime\Plugin\Field\FieldWidget\TimestampDatetimeWidget::massageFormValues()

Overrides WidgetBase::massageFormValues

File

core/lib/Drupal/Core/Datetime/Plugin/Field/FieldWidget/TimestampDatetimeWidget.php, line 50

Class

TimestampDatetimeWidget
Plugin implementation of the 'datetime timestamp' widget.

Namespace

Drupal\Core\Datetime\Plugin\Field\FieldWidget

Code

public function massageFormValues(array $values, array $form, FormStateInterface $form_state) {
    foreach ($values as &$item) {
        // @todo The structure is different whether access is denied or not, to
        //   be fixed in https://www.drupal.org/node/2326533.
        if (isset($item['value']) && $item['value'] instanceof DrupalDateTime) {
            $date = $item['value'];
        }
        elseif (isset($item['value']['object']) && $item['value']['object'] instanceof DrupalDateTime) {
            $date = $item['value']['object'];
        }
        else {
            $date = new DrupalDateTime();
        }
        $item['value'] = $date->getTimestamp();
    }
    return $values;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.