protected function Upload::prepareEntities in Media entity image 8
1 call to Upload::prepareEntities()
- Upload::submit in src/
Plugin/ EntityBrowser/ Widget/ Upload.php
File
- src/
Plugin/ EntityBrowser/ Widget/ Upload.php, line 54
Class
- Upload
- Uses upload to create media entity images.
Namespace
Drupal\media_entity_image\Plugin\EntityBrowser\WidgetCode
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']);
$images = [];
foreach ($files as $file) {
/** @var \Drupal\media_entity\MediaInterface $image */
$image = $this->entityTypeManager
->getStorage('media')
->create([
'bundle' => $bundle
->id(),
$bundle
->getTypeConfiguration()['source_field'] => $file,
]);
$images[] = $image;
}
return $images;
}