function 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.
array|null $contexts: (optional) An associative array of arbitrary data that can be useful to determine the proper fallback sequence. See \Drupal\Core\Language\LanguageManagerInterface::getFallbackCandidates(). Using context ids from the plugin context system is deprecated.
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 137 
Class
- EntityRepository
- Provides several mechanisms for retrieving entities.
Namespace
Drupal\Core\EntityCode
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.
