You are here

protected function EntityEmbedBuilder::buildEntityEmbedDisplayPlugin in Entity Embed 8

Builds the render array for an entity using an Entity Embed Display plugin.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity to be rendered.

string $plugin_id: The Entity Embed Display plugin ID.

array $plugin_configuration: (optional) Array of plugin configuration values.

array $context: (optional) Array of additional context values, usually the embed HTML tag's attributes.

Return value

array A render array for the Entity Embed Display plugin.

1 call to EntityEmbedBuilder::buildEntityEmbedDisplayPlugin()
EntityEmbedBuilder::buildEntityEmbed in src/EntityEmbedBuilder.php
Builds the render array for an embedded entity.

File

src/EntityEmbedBuilder.php, line 146

Class

EntityEmbedBuilder
Builds embedded entities.

Namespace

Drupal\entity_embed

Code

protected function buildEntityEmbedDisplayPlugin(EntityInterface $entity, $plugin_id, array $plugin_configuration = [], array $context = []) {

  // Build the Entity Embed Display plugin.

  /** @var \Drupal\entity_embed\EntityEmbedDisplay\EntityEmbedDisplayBase $display */
  $display = $this->displayPluginManager
    ->createInstance($plugin_id, $plugin_configuration);
  $display
    ->setContextValue('entity', $entity);
  $display
    ->setAttributes($context);

  // Check if the Entity Embed Display plugin is accessible. This also checks
  // entity access, which is why we never call $entity->access() here.
  if (!$display
    ->access()) {
    return [];
  }
  return $display
    ->build();
}