You are here

public function InlineEntityFormMediaWidget::submit in DropzoneJS 8.2

Same name and namespace in other branches
  1. 8 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 203

Class

InlineEntityFormMediaWidget
Provides an Entity Browser widget that uploads and edit new files.

Namespace

Drupal\dropzonejs_eb_widget\Plugin\EntityBrowser\Widget

Code

public function submit(array &$element, array &$form, FormStateInterface $form_state) {
  $media_entities = $this
    ->prepareEntitiesFromForm($form, $form_state);
  foreach ($media_entities as $id => $media_entity) {
    $source_field = $media_entity
      ->getSource()
      ->getConfiguration()['source_field'];
    $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);
  }
}