function ContentTranslationWorkflowsTest::setUp

Same name in other branches
  1. 9 core/modules/content_translation/tests/src/Functional/ContentTranslationWorkflowsTest.php \Drupal\Tests\content_translation\Functional\ContentTranslationWorkflowsTest::setUp()
  2. 8.9.x core/modules/content_translation/tests/src/Functional/ContentTranslationWorkflowsTest.php \Drupal\Tests\content_translation\Functional\ContentTranslationWorkflowsTest::setUp()
  3. 10 core/modules/content_translation/tests/src/Functional/ContentTranslationWorkflowsTest.php \Drupal\Tests\content_translation\Functional\ContentTranslationWorkflowsTest::setUp()

Overrides BrowserTestBase::setUp

File

core/modules/content_translation/tests/src/Functional/ContentTranslationWorkflowsTest.php, line 75

Class

ContentTranslationWorkflowsTest
Tests the content translation workflows for the test entity.

Namespace

Drupal\Tests\content_translation\Functional

Code

protected function setUp() : void {
    parent::setUp();
    $this->doSetup();
    $field_storage = FieldStorageConfig::create([
        'field_name' => 'field_reference',
        'type' => 'entity_reference',
        'entity_type' => $this->entityTypeId,
        'cardinality' => 1,
        'settings' => [
            'target_type' => $this->entityTypeId,
        ],
    ]);
    $field_storage->save();
    FieldConfig::create([
        'field_storage' => $field_storage,
        'bundle' => $this->entityTypeId,
        'label' => 'Reference',
        'translatable' => FALSE,
    ])
        ->save();
    $this->container
        ->get('entity_display.repository')
        ->getViewDisplay($this->entityTypeId, $this->entityTypeId, 'default')
        ->setComponent('field_reference', [
        'type' => 'entity_reference_entity_view',
    ])
        ->save();
    $this->setupEntity();
    // Create a second entity that references the first to test how the
    // translation can be viewed through an entity reference field.
    $this->referencingEntity = EntityTestMulRevPub::create([
        'name' => 'referencing',
        'field_reference' => $this->entity
            ->id(),
    ]);
    $this->referencingEntity
        ->addTranslation($this->langcodes[2], $this->referencingEntity
        ->toArray());
    $this->referencingEntity
        ->save();
}

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