You are here

public static function ContentEntitySource::loadMultiple in Translation Management Tool 8

Loads a list of entities for the given entity type ID.

By providing the language code, the latest revisions affecting the specified translation (language code) will be returned.

Parameters

string $entity_type_id: The entity type ID.

array $entity_ids: A list of entity IDs to load.

string|null $langcode: (optional) The language code. Defaults to source entity language.

Return value

\Drupal\Core\Entity\EntityInterface[] Returns a list of entities.

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

2 calls to ContentEntitySource::loadMultiple()
ContentEntitySource::load in sources/content/src/Plugin/tmgmt/Source/ContentEntitySource.php
Loads a single entity for the given entity type ID.
ContentEntitySourcePluginUi::overviewSubmitToContinuousJobs in sources/content/src/ContentEntitySourcePluginUi.php
Adds selected sources to continuous jobs.

File

sources/content/src/Plugin/tmgmt/Source/ContentEntitySource.php, line 72

Class

ContentEntitySource
Content entity source plugin controller.

Namespace

Drupal\tmgmt_content\Plugin\tmgmt\Source

Code

public static function loadMultiple($entity_type_id, array $entity_ids, $langcode = NULL) {

  /** @var \Drupal\Core\Entity\EntityStorageInterface $storage */
  $storage = \Drupal::entityTypeManager()
    ->getStorage($entity_type_id);
  $entities = $storage
    ->loadMultiple($entity_ids);

  // Load the latest revision if the entity type is revisionable.
  if ($storage
    ->getEntityType()
    ->isRevisionable() && $storage instanceof TranslatableRevisionableStorageInterface) {
    foreach ($entities as $entity_id => $entity) {

      // Use the specified langcode or fallback to the default language.
      $translation_langcode = $langcode ?: $entity
        ->language()
        ->getId();
      $revision_id = $storage
        ->getLatestTranslationAffectedRevisionId($entity
        ->id(), $translation_langcode);

      // Get the pending revisions. If the returned revision ID is the same as
      // the default one, there is no need for further checks.
      if ($revision_id && $entity
        ->getRevisionId() != $revision_id) {
        $revision = $storage
          ->loadRevision($revision_id);

        // If the affected revision was the default one at some point, then it
        // is an old revision that should be part of the already loaded
        // default so we do not need to replace it here.
        if (!$revision
          ->wasDefaultRevision()) {
          $entities[$entity_id] = $revision;
        }
      }
    }
  }
  return $entities;
}