function EntityRepository::getCanonicalMultiple
Retrieves the canonical 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::getCanonicalMultiple
1 call to EntityRepository::getCanonicalMultiple()
- EntityRepository::getCanonical in core/lib/ Drupal/ Core/ Entity/ EntityRepository.php 
- Retrieves the canonical entity variant matching the specified context.
File
- 
              core/lib/ Drupal/ Core/ Entity/ EntityRepository.php, line 181 
Class
- EntityRepository
- Provides several mechanisms for retrieving entities.
Namespace
Drupal\Core\EntityCode
public function getCanonicalMultiple($entity_type_id, array $entity_ids, ?array $contexts = NULL) {
  $entities = $this->entityTypeManager
    ->getStorage($entity_type_id)
    ->loadMultiple($entity_ids);
  if (!$entities || !$this->languageManager
    ->isMultilingual()) {
    return $entities;
  }
  if (!isset($contexts)) {
    $contexts = [];
  }
  $key = '@entity.repository:legacy_context_operation';
  if (isset($contexts[$key])) {
    @trigger_error('Providing an \\Drupal\\Core\\Entity\\EntityRepositoryInterface::CONTEXT_ID_LEGACY_CONTEXT_OPERATION context to EntityRepository::getCanonicalMultiple() is deprecated in drupal:10.3.0 and is removed from drupal:12.0.0. There is no replacement. See https://www.drupal.org/node/3437685', E_USER_DEPRECATED);
    $contexts['operation'] = $contexts[$key]->getContextValue();
  }
  $canonical = [];
  $langcode = $this->getContentLanguageFromContexts($contexts);
  foreach ($entities as $id => $entity) {
    $canonical[$id] = $this->getTranslationFromContext($entity, $langcode, $contexts);
  }
  return $canonical;
}Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.
