function EntityRepository::getActiveMultiple

Same name in other branches
  1. 8.9.x 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()

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 136

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.