function EntityRepository::getActiveMultiple

Same name in other branches
  1. 9 core/lib/Drupal/Core/Entity/EntityRepository.php \Drupal\Core\Entity\EntityRepository::getActiveMultiple()
  2. 8.9.x 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()
1 call to EntityRepository::getActiveMultiple()
EntityRepository::getActive in core/lib/Drupal/Core/Entity/EntityRepository.php

File

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

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 = [];
    }
    // @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.