You are here

protected function Upload::prepareEntities in Entity Browser 8

Same name and namespace in other branches
  1. 8.2 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

1 call to Upload::prepareEntities()
Upload::submit in src/Plugin/EntityBrowser/Widget/Upload.php
Submits form.

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;
}