You are here

protected function AmpTestBase::createTextField in Accelerated Mobile Pages (AMP) 8.3

Adds a text field to the test content type.

2 calls to AmpTestBase::createTextField()
AmpFormatterFacebookTest::setUp in tests/src/Functional/AmpFormatterFacebookTest.php
AmpFormatterTwitterTest::setUp in tests/src/Functional/AmpFormatterTwitterTest.php

File

tests/src/Functional/AmpTestBase.php, line 233

Class

AmpTestBase
Base AMP testing setup.

Namespace

Drupal\Tests\amp\Functional

Code

protected function createTextField($field_name) {
  FieldStorageConfig::create([
    'field_name' => $field_name,
    'entity_type' => 'node',
    'type' => 'string',
    'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
    'translatable' => FALSE,
    'settings' => [
      'max_length' => 255,
    ],
  ])
    ->save();
  FieldConfig::create([
    'field_name' => $field_name,
    'bundle' => $this->contentType,
    'entity_type' => 'node',
    'settings' => [],
  ])
    ->save();
  $this->displayRepository
    ->getFormDisplay('node', $this->contentType)
    ->setComponent($field_name, [
    'type' => 'string_textfield',
  ])
    ->save();
  $this->displayRepository
    ->getViewDisplay('node', $this->contentType)
    ->setComponent($field_name, [
    'type' => 'string',
  ])
    ->save();
}