public function InlineEntityFormMediaWidget::submit in DropzoneJS 8
Same name and namespace in other branches
- 8.2 modules/eb_widget/src/Plugin/EntityBrowser/Widget/InlineEntityFormMediaWidget.php \Drupal\dropzonejs_eb_widget\Plugin\EntityBrowser\Widget\InlineEntityFormMediaWidget::submit()
Overrides MediaEntityDropzoneJsEbWidget::submit
File
- modules/
eb_widget/ src/ Plugin/ EntityBrowser/ Widget/ InlineEntityFormMediaWidget.php, line 232
Class
- InlineEntityFormMediaWidget
- Provides an Entity Browser widget that uploads and edit new files.
Namespace
Drupal\dropzonejs_eb_widget\Plugin\EntityBrowser\WidgetCode
public function submit(array &$element, array &$form, FormStateInterface $form_state) {
$media_entities = $this
->prepareEntitiesFromForm($form, $form_state);
$source_field = $this
->getBundle()
->getTypeConfiguration()['source_field'];
foreach ($media_entities as $id => $media_entity) {
$file = $media_entity->{$source_field}->entity;
/** @var \Drupal\dropzonejs\Events\DropzoneMediaEntityCreateEvent $event */
$event = $this->eventDispatcher
->dispatch(Events::MEDIA_ENTITY_CREATE, new DropzoneMediaEntityCreateEvent($media_entity, $file, $form, $form_state, $element));
$media_entity = $event
->getMediaEntity();
$media_entity
->save();
$media_entities[$id] = $media_entity;
}
if (!empty(array_filter($media_entities))) {
$this
->selectEntities($media_entities, $form_state);
$this
->clearFormValues($element, $form_state);
}
}