function ContentEntity::yieldEntities

Same name in other branches
  1. 8.9.x core/modules/migrate_drupal/src/Plugin/migrate/source/ContentEntity.php \Drupal\migrate_drupal\Plugin\migrate\source\ContentEntity::yieldEntities()
  2. 10 core/modules/migrate_drupal/src/Plugin/migrate/source/ContentEntity.php \Drupal\migrate_drupal\Plugin\migrate\source\ContentEntity::yieldEntities()
  3. 11.x core/modules/migrate_drupal/src/Plugin/migrate/source/ContentEntity.php \Drupal\migrate_drupal\Plugin\migrate\source\ContentEntity::yieldEntities()

Loads and yields entities, one at a time.

Parameters

array $ids: The entity IDs.

Return value

\Generator An iterable of the loaded entities.

1 call to ContentEntity::yieldEntities()
ContentEntity::initializeIterator in core/modules/migrate_drupal/src/Plugin/migrate/source/ContentEntity.php
Initializes the iterator with the source data.

File

core/modules/migrate_drupal/src/Plugin/migrate/source/ContentEntity.php, line 181

Class

ContentEntity
Source plugin to get content entities from the current version of Drupal.

Namespace

Drupal\migrate_drupal\Plugin\migrate\source

Code

protected function yieldEntities(array $ids) {
    $storage = $this->entityTypeManager
        ->getStorage($this->entityType
        ->id());
    foreach ($ids as $id) {
        
        /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
        $entity = $storage->load($id);
        (yield $this->toArray($entity));
        if ($this->configuration['include_translations']) {
            foreach ($entity->getTranslationLanguages(FALSE) as $language) {
                (yield $this->toArray($entity->getTranslation($language->getId())));
            }
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.