public function InlineEntityFormMediaWidget::submitEdit in DropzoneJS 8.2
Same name and namespace in other branches
- 8 modules/eb_widget/src/Plugin/EntityBrowser/Widget/InlineEntityFormMediaWidget.php \Drupal\dropzonejs_eb_widget\Plugin\EntityBrowser\Widget\InlineEntityFormMediaWidget::submitEdit()
Submit callback for the edit button.
Parameters
array $form: Form array.
\Drupal\Core\Form\FormStateInterface $form_state: Form object.
File
- modules/
eb_widget/ src/ Plugin/ EntityBrowser/ Widget/ InlineEntityFormMediaWidget.php, line 133
Class
- InlineEntityFormMediaWidget
- Provides an Entity Browser widget that uploads and edit new files.
Namespace
Drupal\dropzonejs_eb_widget\Plugin\EntityBrowser\WidgetCode
public function submitEdit(array $form, FormStateInterface $form_state) {
$form_state
->setRebuild(TRUE);
$media_entities = $this
->prepareEntities($form, $form_state);
foreach ($media_entities as $id => $media_entity) {
/** @var \Drupal\file\Entity\File $file */
// Files have to saved before they can be viewed in the IEF form.
$source_field = $this
->getType()
->getSource()
->getSourceFieldDefinition($this
->getType())
->getName();
$file = $media_entity->{$source_field}->entity;
$file
->save();
$media_entity->{$source_field}->target_id = $file
->id();
if (method_exists($media_entity, 'prepareSave')) {
$media_entity
->prepareSave();
}
/** @var \Drupal\dropzonejs\Events\DropzoneMediaEntityCreateEvent $event */
$event = $this->eventDispatcher
->dispatch(Events::MEDIA_ENTITY_PRECREATE, new DropzoneMediaEntityCreateEvent($media_entity, $file, $form, $form_state, $form));
$media_entities[$id] = $event
->getMediaEntity();
}
$form_state
->set('uploaded_entities', $media_entities);
}