function EntityRepository::getActiveMultiple

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Entity/EntityRepository.php \Drupal\Core\Entity\EntityRepository::getActiveMultiple()
  2. 10 core/lib/Drupal/Core/Entity/EntityRepository.php \Drupal\Core\Entity\EntityRepository::getActiveMultiple()
  3. 11.x core/lib/Drupal/Core/Entity/EntityRepository.php \Drupal\Core\Entity\EntityRepository::getActiveMultiple()

Retrieves the active entity variants matching the specified context.

Parameters

string $entity_type_id: The entity type identifier.

int[]|string[] $entity_ids: An array of entity identifiers.

\Drupal\Core\Plugin\Context\ContextInterface[] $contexts: (optional) An associative array of objects representing the contexts the entity will be edited in keyed by fully qualified context ID. Defaults to the currently available contexts.

Return value

\Drupal\Core\Entity\EntityInterface An array of entity object variants keyed by entity ID.

Overrides EntityRepositoryInterface::getActiveMultiple

1 call to EntityRepository::getActiveMultiple()
EntityRepository::getActive in core/lib/Drupal/Core/Entity/EntityRepository.php
Retrieves the active entity variant matching the specified context.

File

core/lib/Drupal/Core/Entity/EntityRepository.php, line 142

Class

EntityRepository
Provides several mechanisms for retrieving entities.

Namespace

Drupal\Core\Entity

Code

public function getActiveMultiple($entity_type_id, array $entity_ids, array $contexts = NULL) {
    $active = [];
    if (!isset($contexts)) {
        $contexts = $this->contextRepository
            ->getAvailableContexts();
    }
    // @todo Consider implementing a more performant version of this logic fully
    //   supporting multiple entities in https://www.drupal.org/node/3031082.
    $langcode = $this->languageManager
        ->isMultilingual() ? $this->getContentLanguageFromContexts($contexts) : $this->languageManager
        ->getDefaultLanguage()
        ->getId();
    $entities = $this->entityTypeManager
        ->getStorage($entity_type_id)
        ->loadMultiple($entity_ids);
    foreach ($entities as $id => $entity) {
        // Retrieve the fittest revision, if needed.
        if ($entity instanceof RevisionableInterface && $entity->getEntityType()
            ->isRevisionable()) {
            $entity = $this->getLatestTranslationAffectedRevision($entity, $langcode);
        }
        // Retrieve the fittest translation, if needed.
        if ($entity instanceof TranslatableInterface) {
            $entity = $this->getTranslationFromContext($entity, $langcode);
        }
        $active[$id] = $entity;
    }
    return $active;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.