protected function MediaImageUpload::prepareEntities in Entity Browser 8.2
Prepares the entities without saving them.
We need this method when we want to validate or perform other operations before submit.
Parameters
array $form: Complete form.
\Drupal\Core\Form\FormStateInterface $form_state: The form state object.
Return value
\Drupal\Core\Entity\EntityInterface[] Array of entities.
Overrides Upload::prepareEntities
1 call to MediaImageUpload::prepareEntities()
- MediaImageUpload::submit in src/
Plugin/ EntityBrowser/ Widget/ MediaImageUpload.php - Submits form.
File
- src/
Plugin/ EntityBrowser/ Widget/ MediaImageUpload.php, line 54
Class
- MediaImageUpload
- Uses upload to create media images.
Namespace
Drupal\entity_browser\Plugin\EntityBrowser\WidgetCode
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 $image */
$image = $this->entityTypeManager
->getStorage('media')
->create([
'bundle' => $media_type
->id(),
$media_type
->getSource()
->getConfiguration()['source_field'] => $file,
]);
$images[] = $image;
}
return $images;
}