You are here

protected function ContentTranslationTestBase::setupTestFields in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/content_translation/tests/src/Functional/ContentTranslationTestBase.php \Drupal\Tests\content_translation\Functional\ContentTranslationTestBase::setupTestFields()
  2. 9 core/modules/content_translation/tests/src/Functional/ContentTranslationTestBase.php \Drupal\Tests\content_translation\Functional\ContentTranslationTestBase::setupTestFields()

Creates the test fields.

File

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

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();
}