Commit bd85dfcc authored by marcoscano's avatar marcoscano Committed by Primsi

Issue #2956659 by marcoscano, Berdir: InlineEntityFormMediaWidget disregards...

Issue #2956659 by marcoscano, Berdir: InlineEntityFormMediaWidget disregards modifications after dispatching MEDIA_ENTITY_CREATE event
parent ef24d756
......@@ -233,12 +233,13 @@ class InlineEntityFormMediaWidget extends MediaEntityDropzoneJsEbWidget {
$media_entities = $this->prepareEntitiesFromForm($form, $form_state);
$source_field = $this->getType()->getSource()->getSourceFieldDefinition($this->getType())->getName();
foreach ($media_entities as $media_entity) {
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))) {
......
......@@ -181,7 +181,7 @@ class MediaEntityDropzoneJsEbWidget extends DropzoneJsEbWidget {
/** @var \Drupal\media\MediaInterface[] $media_entities */
$media_entities = $this->prepareEntities($form, $form_state);
foreach ($media_entities as &$media_entity) {
foreach ($media_entities as $id => $media_entity) {
$source_field = $this->getType()->getSource()->getConfiguration()['source_field'];
$file = $media_entity->$source_field->entity;
/** @var \Drupal\dropzonejs\Events\DropzoneMediaEntityCreateEvent $event */
......@@ -193,6 +193,7 @@ class MediaEntityDropzoneJsEbWidget extends DropzoneJsEbWidget {
// in Media entity, but this workaround should work for now.
$media_entity->$source_field->entity->save();
$media_entity->save();
$media_entities[$id] = $media_entity;
}
$this->selectEntities($media_entities, $form_state);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment