You are here

protected function PanelizerEntityViewBuilder::buildPanelized in Panelizer 8.5

Same name and namespace in other branches
  1. 8.3 src/PanelizerEntityViewBuilder.php \Drupal\panelizer\PanelizerEntityViewBuilder::buildPanelized()
  2. 8.4 src/PanelizerEntityViewBuilder.php \Drupal\panelizer\PanelizerEntityViewBuilder::buildPanelized()

Build the render array for a single panelized entity.

Parameters

\Drupal\Core\Entity\EntityInterface $entity:

\Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant $panels_display:

string $view_mode:

string $langcode:

Return value

array

1 call to PanelizerEntityViewBuilder::buildPanelized()
PanelizerEntityViewBuilder::buildMultiplePanelized in src/PanelizerEntityViewBuilder.php
Build the render array for a list of panelized entities.

File

src/PanelizerEntityViewBuilder.php, line 378

Class

PanelizerEntityViewBuilder
Entity view builder for entities that can be panelized.

Namespace

Drupal\panelizer

Code

protected function buildPanelized(EntityInterface $entity, PanelsDisplayVariant $panels_display, $view_mode, $langcode) {
  $contexts = $panels_display
    ->getContexts();
  $contexts['@panelizer.entity_context:entity'] = $this
    ->getEntityContext($entity);
  $panels_display
    ->setContexts($contexts);
  $build = [
    '#theme' => [
      'panelizer_view_mode__' . $this->entityTypeId . '__' . $entity
        ->id(),
      'panelizer_view_mode__' . $this->entityTypeId . '__' . $entity
        ->bundle(),
      'panelizer_view_mode__' . $this->entityTypeId,
      'panelizer_view_mode',
    ],
    '#panelizer_plugin' => $this
      ->getPanelizerPlugin(),
    '#panels_display' => $panels_display,
    '#entity' => $entity,
    '#view_mode' => $view_mode,
    '#langcode' => $langcode,
    'content' => $panels_display
      ->build(),
  ];
  if (isset($build['content']['#title'])) {
    $build['#title'] = $build['content']['#title'];
  }

  // @todo: I'm sure more is necessary to get the cache contexts right...
  $entity_metadata = CacheableMetadata::createFromObject($entity);
  CacheableMetadata::createFromObject($panels_display)
    ->merge($entity_metadata)
    ->applyTo($build);
  $this
    ->getPanelizerPlugin()
    ->alterBuild($build, $entity, $panels_display, $view_mode);
  return $build;
}