/** * Build the render array for a single panelized entity. * * @param \Drupal\Core\Entity\EntityInterface $entity * @param \Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant $panels_display * @param string $view_mode * @param string $langcode * * @return array */ protected function buildPanelized(EntityInterface $entity, PanelsDisplayVariant $panels_display, $view_mode, $langcode) { $contexts = $panels_display->getContexts(); $entity_context = new Context(new ContextDefinition('entity:' . $this->entityTypeId, NULL, TRUE), $entity); $contexts['@panelizer.entity_context:' . $this->entityTypeId] = $entity_context; $panels_display->setContexts($contexts); $build = $panels_display->build(); // @todo: I'm sure more is necessary to get the cache contexts right... CacheableMetadata::createFromObject($entity)->applyTo($build); $this->getPanelizerPlugin()->alterBuild($build, $entity, $panels_display, $view_mode); return $build; }