You are here

protected function BlazyCreationTestTrait::buildEntityReferenceRenderArray in Blazy 8

Same name and namespace in other branches
  1. 8.2 tests/src/Traits/BlazyCreationTestTrait.php \Drupal\Tests\blazy\Traits\BlazyCreationTestTrait::buildEntityReferenceRenderArray()

Sets field values as built by FieldItemListInterface::view().

Parameters

\Drupal\Core\Entity\EntityInterface[] $referenced_entities: An array of entity objects that will be referenced.

string $type: The formatter plugin ID.

array $settings: Settings specific to the formatter. Defaults to the formatter's defaults.

Return value

array A render array.

File

tests/src/Traits/BlazyCreationTestTrait.php, line 367

Class

BlazyCreationTestTrait
A Trait common for Blazy tests.

Namespace

Drupal\Tests\blazy\Traits

Code

protected function buildEntityReferenceRenderArray(array $referenced_entities, $type = '', array $settings = []) {
  $type = empty($type) ? $this->entityPluginId : $type;
  $items = $this->referencingEntity
    ->get($this->entityFieldName);

  // Assign the referenced entities.
  foreach ($referenced_entities as $referenced_entity) {
    $items[] = [
      'entity' => $referenced_entity,
    ];
  }

  // Build the renderable array for the field.
  $data['type'] = $type;
  if ($settings) {
    $data['settings'] = $settings;
  }
  return $items
    ->view($data);
}