public function DurationWidget::formElementValidate in Duration Field 8.2
Same name and namespace in other branches
- 3.0.x src/Plugin/Field/FieldWidget/DurationWidget.php \Drupal\duration_field\Plugin\Field\FieldWidget\DurationWidget::formElementValidate()
Validation handler, sets the number of seconds for the submitted duration.
File
- src/
Plugin/ Field/ FieldWidget/ DurationWidget.php, line 112
Class
- DurationWidget
- Widget for inputting durations.
Namespace
Drupal\duration_field\Plugin\Field\FieldWidgetCode
public function formElementValidate(array &$element, FormStateInterface $form_state) {
// Get the submitted DateInterval.
$date_interval = $form_state
->getValue($element['duration']['#parents']);
// Get the number of seconds for the duration.
$seconds = $this->durationService
->getSecondsFromDateInterval($date_interval);
// Save the values to the form state.
$form_state
->setValueForElement($element['seconds'], $seconds);
}