You are here

public function ExtraFieldEntityLinkPlugin::build in Entity Extra Field 2.0.x

Same name and namespace in other branches
  1. 8 src/Plugin/ExtraFieldType/ExtraFieldEntityLinkPlugin.php \Drupal\entity_extra_field\Plugin\ExtraFieldType\ExtraFieldEntityLinkPlugin::build()

Build the render array of the extra field type contents.

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.

Throws

\Drupal\Core\Entity\EntityMalformedException

Overrides ExtraFieldTypePluginInterface::build

File

src/Plugin/ExtraFieldType/ExtraFieldEntityLinkPlugin.php, line 173

Class

ExtraFieldEntityLinkPlugin
Define the extra field entity link type.

Namespace

Drupal\entity_extra_field\Plugin\ExtraFieldType

Code

public function build(EntityInterface $entity, EntityDisplayInterface $display) : array {
  $link = $this
    ->buildEntityLink($entity);

  // Link and Url seem not to have convenience methods for access including
  // cacheability. So inlining a variant of \Drupal\Core\Url::access.
  $accessResult = $this
    ->urlAccessResult($link
    ->getUrl());
  $build = $accessResult
    ->isAllowed() ? $link
    ->toRenderable() : [];
  BubbleableMetadata::createFromObject($accessResult)
    ->applyTo($build);
  return $build;
}