You are here

protected function BlockStorage::doLoadMultiple in Multiversion 8.2

Same name and namespace in other branches
  1. 8 src/Entity/Storage/Sql/BlockStorage.php \Drupal\multiversion\Entity\Storage\Sql\BlockStorage::doLoadMultiple()

Performs storage-specific loading of entities.

Override this method to add custom functionality directly after loading. This is always called, while self::postLoad() is only called when there are actual results.

Parameters

array|null $ids: (optional) An array of entity IDs, or NULL to load all entities.

Return value

\Drupal\Core\Entity\EntityInterface[] Associative array of entities, keyed on the entity ID.

Overrides ConfigEntityStorage::doLoadMultiple

File

src/Entity/Storage/Sql/BlockStorage.php, line 16

Class

BlockStorage
A base entity storage class.

Namespace

Drupal\multiversion\Entity\Storage\Sql

Code

protected function doLoadMultiple(array $ids = NULL) {
  $entities = parent::doLoadMultiple($ids);
  $entity_type_manager = \Drupal::entityTypeManager();

  /** @var \Drupal\block\Entity\Block $entity */
  foreach ($entities as $id => $entity) {
    $plugin_id = $entity
      ->getPluginId();
    if (strpos($plugin_id, ':') === FALSE) {
      continue;
    }
    list($provider, $uuid) = explode(':', $plugin_id);
    if ($provider && $provider === 'block_content' && $uuid) {
      $storage = $entity_type_manager
        ->getStorage('block_content');
      $active_workspace = \Drupal::service('workspaces.manager')
        ->getActiveWorkspace();
      $loaded_entity = $storage
        ->loadByProperties([
        'uuid' => $uuid,
        'workspace' => $active_workspace
          ->id(),
      ]);
      $loaded_entity = reset($loaded_entity);
      if ($loaded_entity instanceof ContentEntityInterface) {
        $entities[$id]
          ->addCacheableDependency($loaded_entity);
        $entities[$id]
          ->addCacheableDependency($active_workspace);
      }
      else {
        unset($entities[$id]);
      }
    }
  }
  return $entities;
}