function ContentTranslationTestBase::setupTestFields

Same name in this branch
  1. 8.9.x core/modules/content_translation/tests/src/Functional/ContentTranslationTestBase.php \Drupal\Tests\content_translation\Functional\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.

1 call to ContentTranslationTestBase::setupTestFields()
ContentTranslationTestBase::setUp in core/modules/content_translation/src/Tests/ContentTranslationTestBase.php
Sets up a Drupal site for running functional and integration tests.

File

core/modules/content_translation/src/Tests/ContentTranslationTestBase.php, line 185

Class

ContentTranslationTestBase
Base class for content translation tests.

Namespace

Drupal\content_translation\Tests

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();
    \Drupal::service('entity_display.repository')->getFormDisplay($this->entityTypeId, $this->bundle)
        ->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.