function ContentTranslationTestBase::setupTestFields

Same name in this branch
  1. 8.9.x core/modules/content_translation/src/Tests/ContentTranslationTestBase.php \Drupal\content_translation\Tests\ContentTranslationTestBase::setupTestFields()
Same name in other branches
  1. 9 core/modules/content_translation/tests/src/Functional/ContentTranslationTestBase.php \Drupal\Tests\content_translation\Functional\ContentTranslationTestBase::setupTestFields()
  2. 10 core/modules/content_translation/tests/src/Functional/ContentTranslationTestBase.php \Drupal\Tests\content_translation\Functional\ContentTranslationTestBase::setupTestFields()
  3. 11.x core/modules/content_translation/tests/src/Functional/ContentTranslationTestBase.php \Drupal\Tests\content_translation\Functional\ContentTranslationTestBase::setupTestFields()

Creates the test fields.

2 calls to ContentTranslationTestBase::setupTestFields()
ContentTranslationTestBase::setUp in core/modules/content_translation/tests/src/Functional/ContentTranslationTestBase.php
ContentTranslationUntranslatableFieldsTest::setupTestFields in core/modules/content_translation/tests/src/Functional/ContentTranslationUntranslatableFieldsTest.php
Creates the test fields.
2 methods override ContentTranslationTestBase::setupTestFields()
ContentTranslationSyncImageTest::setupTestFields in core/modules/content_translation/tests/src/Functional/ContentTranslationSyncImageTest.php
Creates the test image field.
ContentTranslationUntranslatableFieldsTest::setupTestFields in core/modules/content_translation/tests/src/Functional/ContentTranslationUntranslatableFieldsTest.php
Creates the test fields.

File

core/modules/content_translation/tests/src/Functional/ContentTranslationTestBase.php, line 178

Class

ContentTranslationTestBase
Base class for content translation tests.

Namespace

Drupal\Tests\content_translation\Functional

Code

protected function setupTestFields() {
    if (empty($this->fieldName)) {
        $this->fieldName = 'field_test_et_ui_test';
    }
    FieldStorageConfig::create([
        'field_name' => $this->fieldName,
        'type' => 'string',
        'entity_type' => $this->entityTypeId,
        'cardinality' => 1,
    ])
        ->save();
    FieldConfig::create([
        'entity_type' => $this->entityTypeId,
        'field_name' => $this->fieldName,
        'bundle' => $this->bundle,
        'label' => 'Test translatable text-field',
    ])
        ->save();
    
    /** @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface $display_repository */
    $display_repository = \Drupal::service('entity_display.repository');
    $display_repository->getFormDisplay($this->entityTypeId, $this->bundle, 'default')
        ->setComponent($this->fieldName, [
        'type' => 'string_textfield',
        'weight' => 0,
    ])
        ->save();
}

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