You are here

protected function MediaFileUpload::prepareEntities in Panopoly 8.2

1 call to MediaFileUpload::prepareEntities()
MediaFileUpload::submit in modules/panopoly/panopoly_media/src/Plugin/EntityBrowser/Widget/MediaFileUpload.php

File

modules/panopoly/panopoly_media/src/Plugin/EntityBrowser/Widget/MediaFileUpload.php, line 54

Class

MediaFileUpload
Uses upload to create media images.

Namespace

Drupal\panopoly_media\Plugin\EntityBrowser\Widget

Code

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

  /** @var \Drupal\media\MediaTypeInterface $media_type */
  $media_type = $this->entityTypeManager
    ->getStorage('media_type')
    ->load($this->configuration['media_type']);
  $images = [];
  foreach ($files as $file) {

    /** @var \Drupal\media\MediaInterface $file */
    $file = $this->entityTypeManager
      ->getStorage('media')
      ->create([
      'bundle' => $media_type
        ->id(),
      $media_type
        ->getSource()
        ->getConfiguration()['source_field'] => $file,
    ]);
    $images[] = $file;
  }
  return $images;
}