You are here

public static function EntityBrowserFormTrait::loadEntityBrowserEntitiesByIds in Helper 8

Loads entities based on an ID in the format entity_type:entity_id.

Parameters

array|string $ids: An array of IDs.

Return value

\Drupal\Core\Entity\EntityInterface[] An array of loaded entities, keyed by an ID.

3 calls to EntityBrowserFormTrait::loadEntityBrowserEntitiesByIds()
EntityBrowserFormTrait::loadEntityBrowserEntity in src/EntityBrowserFormTrait.php
Loads entity based on an ID in the format entity_type:entity_id.
EntityBrowserFormTrait::processEntityBrowser in src/EntityBrowserFormTrait.php
Render API callback: Processes the entity browser element.
EntityBrowserFormTrait::processEntityBrowserSelected in src/EntityBrowserFormTrait.php
Render API callback: Processes the table element.

File

src/EntityBrowserFormTrait.php, line 95

Class

EntityBrowserFormTrait
Provides helpers for adding an entity browser element to a form.

Namespace

Drupal\helper

Code

public static function loadEntityBrowserEntitiesByIds($ids) {
  if (!is_array($ids)) {
    $ids = explode(' ', $ids);
  }
  $ids = array_filter($ids);
  $storage = [];
  $entities = [];
  foreach ($ids as $id) {
    list($entity_type_id, $entity_id) = explode(':', $id);
    if (!isset($storage[$entity_type_id])) {
      $storage[$entity_type_id] = \Drupal::entityTypeManager()
        ->getStorage($entity_type_id);
    }
    $entities[$entity_type_id . ':' . $entity_id] = $storage[$entity_type_id]
      ->load($entity_id);
  }
  return $entities;
}