You are here

public function InlineEntityFormMediaWidget::submitEdit in DropzoneJS 8

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

Class

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

Namespace

Drupal\dropzonejs_eb_widget\Plugin\EntityBrowser\Widget

Code

public function submitEdit(array $form, FormStateInterface $form_state) {
  $form_state
    ->setRebuild(TRUE);

  // Files have to saved before they can be viewed in the IEF form.
  $media_entities = $this
    ->prepareEntities($form, $form_state);
  $source_field = $this
    ->getBundle()
    ->getTypeConfiguration()['source_field'];
  foreach ($media_entities as $media_entity) {

    /** @var \Drupal\file\Entity\File $file */
    $file = $media_entity->{$source_field}->entity;
    $file
      ->save();
    $media_entity->{$source_field}->target_id = $file
      ->id();
  }
  $form_state
    ->set('uploaded_entities', $media_entities);
}