You are here

public function FileUpload::submit in Lightning Media 8

Same name and namespace in other branches
  1. 8.4 src/Plugin/EntityBrowser/Widget/FileUpload.php \Drupal\lightning_media\Plugin\EntityBrowser\Widget\FileUpload::submit()
  2. 8.2 src/Plugin/EntityBrowser/Widget/FileUpload.php \Drupal\lightning_media\Plugin\EntityBrowser\Widget\FileUpload::submit()
  3. 8.3 src/Plugin/EntityBrowser/Widget/FileUpload.php \Drupal\lightning_media\Plugin\EntityBrowser\Widget\FileUpload::submit()

Overrides EntityFormProxy::submit

File

src/Plugin/EntityBrowser/Widget/FileUpload.php, line 103

Class

FileUpload
An Entity Browser widget for creating media entities from uploaded files.

Namespace

Drupal\lightning_media\Plugin\EntityBrowser\Widget

Code

public function submit(array &$element, array &$form, FormStateInterface $form_state) {

  /** @var \Drupal\media\MediaInterface $entity */
  $entity = $element['entity']['#entity'];
  $file = MediaHelper::useFile($entity, MediaHelper::getSourceField($entity)->entity);
  $file
    ->setPermanent();
  $file
    ->save();
  $entity
    ->save();
  $selection = [
    $this->configuration['return_file'] ? $file : $entity,
  ];
  $this
    ->selectEntities($selection, $form_state);
}