You are here

protected function ContentGenerationTrait::populate in Workbench Moderation to Content Moderation 8.2

1 call to ContentGenerationTrait::populate()
MigrationTestTrait::createRevisions in tests/src/Kernel/MigrationTestTrait.php
Creates a set of revisions of a single entity.

File

tests/src/Kernel/ContentGenerationTrait.php, line 63

Class

ContentGenerationTrait

Namespace

Drupal\Tests\wbm2cm\Kernel

Code

protected function populate(ContentEntityInterface $entity, array $matrix) {
  $saved_matrix = [];
  foreach ($matrix as $revision) {
    $entity
      ->setNewRevision();
    foreach ($revision as $language => $fields) {
      if (!$entity
        ->hasTranslation($language)) {
        $entity
          ->addTranslation($language);
      }
      $translation = $entity
        ->getTranslation($language);
      foreach ($fields as $field => $value) {
        $translation
          ->set($field, $value);
      }
    }
    $this->storage
      ->save($entity);
    $vid = $entity
      ->getRevisionId();
    $saved_matrix[$vid] = $revision;
  }
  return $saved_matrix;
}