public function CalendarEventEmbeddedWidget::submitForm in Opigno calendar event 8
Same name in this branch
- 8 src/CalendarEventEmbeddedWidget.php \Drupal\opigno_calendar_event\CalendarEventEmbeddedWidget::submitForm()
- 8 src/Form/CalendarEventEmbeddedWidget.php \Drupal\opigno_calendar_event\Form\CalendarEventEmbeddedWidget::submitForm()
Same name and namespace in other branches
- 3.x src/CalendarEventEmbeddedWidget.php \Drupal\opigno_calendar_event\CalendarEventEmbeddedWidget::submitForm()
Submit handler.
Parameters
array $form: The form array.
\Drupal\Core\Form\FormStateInterface $form_state: The form state.
File
- src/
CalendarEventEmbeddedWidget.php, line 233
Class
- CalendarEventEmbeddedWidget
- Provides a widget to attach a calendar event to an entity.
Namespace
Drupal\opigno_calendar_eventCode
public function submitForm(array $form, FormStateInterface $form_state) {
$widget_state = $this
->getWidgetState($form, $form_state);
foreach (array_keys($widget_state['items']) as $delta) {
$item_form_object = $this
->getItemFormObject($form, $form_state, $delta);
$item_form_state = $this
->getItemFormState($form, $form_state, $delta);
/** @var \Drupal\opigno_calendar_event\CalendarEventInterface $calendar_event */
$calendar_event = $item_form_object
->buildEntity($form[static::ELEMENT_NAME][$delta], $item_form_state);
try {
if ($this
->isCalendarEventPopulated($calendar_event)) {
$calendar_event
->save();
}
elseif (!$calendar_event
->isNew()) {
$calendar_event
->delete();
}
} catch (EntityStorageException $e) {
$this
->logException($e);
}
}
}