You are here

protected function HtmlTitleFormatterTest::buildEntityField in HTML Title 8

Helper method that builds a renderable array for a given entity field.

Parameters

\Drupal\Core\Entity\FieldableEntityInterface $entity: The entity.

string $field_name: The field name.

string $formatter_type: The formatter type.

array $formatter_settings: The formatter settings.

Return value

array The field renderable array.

1 call to HtmlTitleFormatterTest::buildEntityField()
HtmlTitleFormatterTest::testHtmlTitleFormatter in tests/src/Kernel/HtmlTitleFormatterTest.php
Test html_title formatter.

File

tests/src/Kernel/HtmlTitleFormatterTest.php, line 141

Class

HtmlTitleFormatterTest
Test the HTML Title formatter.

Namespace

Drupal\Tests\html_title\Kernel

Code

protected function buildEntityField(FieldableEntityInterface $entity, string $field_name, string $formatter_type, array $formatter_settings = []) : array {
  $display = $this->entityDisplayRepository
    ->getViewDisplay($entity
    ->getEntityTypeId(), $entity
    ->bundle());
  $display
    ->setComponent($field_name, [
    'type' => $formatter_type,
    'settings' => $formatter_settings,
  ]);
  $display
    ->save();
  $build = $display
    ->build($entity);
  return $build[$field_name];
}