You are here

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

Adds a link field to the test content type.

File

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

Class

AmpTestBase
Base AMP testing setup.

Namespace

Drupal\Tests\amp\Functional

Code

protected function createLinkField($field_name) {
  FieldStorageConfig::create([
    'field_name' => $field_name,
    'entity_type' => 'node',
    'type' => 'link',
    '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' => 'link_default',
  ])
    ->save();
  $this->displayRepository
    ->getViewDisplay('node', $this->contentType)
    ->setComponent($field_name, [
    'type' => 'link',
  ])
    ->save();
}