You are here

protected function Upload::prepareEntities in Media entity video 8

Same name and namespace in other branches
  1. 8.3 src/Plugin/EntityBrowser/Widget/Upload.php \Drupal\media_entity_video\Plugin\EntityBrowser\Widget\Upload::prepareEntities()
  2. 8.2 src/Plugin/EntityBrowser/Widget/Upload.php \Drupal\media_entity_video\Plugin\EntityBrowser\Widget\Upload::prepareEntities()
1 call to Upload::prepareEntities()
Upload::submit in src/Plugin/EntityBrowser/Widget/Upload.php

File

src/Plugin/EntityBrowser/Widget/Upload.php, line 53

Class

Upload
Uses upload to create media entity videos.

Namespace

Drupal\media_entity_video\Plugin\EntityBrowser\Widget

Code

protected function prepareEntities(array $form, FormStateInterface $form_state) {
  $files = parent::prepareEntities($form, $form_state);

  /** @var \Drupal\media_entity\MediaBundleInterface $bundle */
  $bundle = $this->entityTypeManager
    ->getStorage('media_bundle')
    ->load($this->configuration['media bundle']);
  $videos = [];
  foreach ($files as $file) {

    /** @var \Drupal\media_entity\MediaInterface $video */
    $video = $this->entityTypeManager
      ->getStorage('media')
      ->create([
      'bundle' => $bundle
        ->id(),
      $bundle
        ->getTypeConfiguration()['source_field'] => $file,
    ]);
    $videos[] = $video;
  }
  return $videos;
}