You are here

public function EntityExtraField::build in Entity Extra Field 8

Same name and namespace in other branches
  1. 2.0.x src/Entity/EntityExtraField.php \Drupal\entity_extra_field\Entity\EntityExtraField::build()

Build the extra field.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity type the extra field is being attached too.

\Drupal\Core\Entity\Display\EntityDisplayInterface $display: The entity display the extra field is apart of.

Return value

array The extra field renderable array.

Overrides EntityExtraFieldInterface::build

File

src/Entity/EntityExtraField.php, line 273

Class

EntityExtraField
Define entity extra field.

Namespace

Drupal\entity_extra_field\Entity

Code

public function build(EntityInterface $entity, EntityDisplayInterface $display) {
  $field_type_plugin = $this
    ->getFieldTypePlugin();
  if (!$field_type_plugin instanceof ExtraFieldTypePluginInterface) {
    return [];
  }
  return [
    '#field' => $this,
    '#view_mode' => $display
      ->getMode(),
    '#theme' => 'entity_extra_field',
    'label' => [
      '#plain_text' => $this
        ->displayLabel() ? $this
        ->label() : NULL,
    ],
    'content' => $field_type_plugin
      ->build($entity, $display),
  ];
}