You are here

protected function Upload::prepareEntities in Entity Browser 8.2

Same name and namespace in other branches
  1. 8 src/Plugin/EntityBrowser/Widget/Upload.php \Drupal\entity_browser\Plugin\EntityBrowser\Widget\Upload::prepareEntities()

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 WidgetBase::prepareEntities

2 calls to Upload::prepareEntities()
MediaImageUpload::prepareEntities in src/Plugin/EntityBrowser/Widget/MediaImageUpload.php
Prepares the entities without saving them.
Upload::submit in src/Plugin/EntityBrowser/Widget/Upload.php
Submits form.
1 method overrides Upload::prepareEntities()
MediaImageUpload::prepareEntities in src/Plugin/EntityBrowser/Widget/MediaImageUpload.php
Prepares the entities without saving them.

File

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

Class

Upload
Adds an upload field browser's widget.

Namespace

Drupal\entity_browser\Plugin\EntityBrowser\Widget

Code

protected function prepareEntities(array $form, FormStateInterface $form_state) {
  $files = [];
  foreach ($form_state
    ->getValue([
    'upload',
  ], []) as $fid) {
    $files[] = $this->entityTypeManager
      ->getStorage('file')
      ->load($fid);
  }
  return $files;
}