You are here

protected function ElementClassFormatterTestBase::createEntityField in Element Class Formatter 8

Creates a field and set's the correct formatter.

Parameters

string $formatter: The formatter ID.

string $field_type: The type of field to create.

array $formatter_settings: Settings for the formatter.

Return value

\Drupal\field\Entity\FieldConfig Newly created file field.

14 calls to ElementClassFormatterTestBase::createEntityField()
EmailLinkClassFormatterTest::testClassFormatter in tests/src/Functional/EmailLinkClassFormatterTest.php
EntityReferenceLabelClassFormatterTest::testClassFormatter in tests/src/Functional/EntityReferenceLabelClassFormatterTest.php
Tests element reference label class formatter.
EntityReferenceListLabelClassFormatterTest::testClassFormatter in tests/src/Functional/EntityReferenceListLabelClassFormatterTest.php
FileLinkClassFormatterTest::testClassFormatter in tests/src/Functional/FileLinkClassFormatterTest.php
ImageClassFormatterTest::testClassFormatter in tests/src/Functional/ImageClassFormatterTest.php

... See full list

File

tests/src/Functional/ElementClassFormatterTestBase.php, line 63

Class

ElementClassFormatterTestBase
Defines a base class for testing element_class_formatter functionality.

Namespace

Drupal\Tests\element_class_formatter\Functional

Code

protected function createEntityField($formatter, $field_type, array $formatter_settings = []) {
  $entity_type = $bundle = 'entity_test';
  $field_name = mb_strtolower($this
    ->randomMachineName());
  FieldStorageConfig::create([
    'entity_type' => $entity_type,
    'field_name' => $field_name,
    'type' => $field_type,
    'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
  ])
    ->save();
  $field_config = FieldConfig::create([
    'entity_type' => $entity_type,
    'field_name' => $field_name,
    'bundle' => $bundle,
  ]);
  $field_config
    ->save();
  $values = [
    'targetEntityType' => 'entity_test',
    'bundle' => 'entity_test',
    'mode' => 'full',
    'status' => TRUE,
  ];
  $display = EntityViewDisplay::create($values);
  $display
    ->setComponent($field_name, [
    'type' => $formatter,
    'settings' => $formatter_settings,
  ])
    ->save();
  return $field_config;
}