Chris@14: currentUser = $current_user; Chris@14: } Chris@14: Chris@14: /** Chris@14: * {@inheritdoc} Chris@14: */ Chris@14: public static function getSubscribedEvents() { Chris@14: $events[LayoutBuilderEvents::SECTION_COMPONENT_BUILD_RENDER_ARRAY] = ['onBuildRender', 100]; Chris@14: return $events; Chris@14: } Chris@14: Chris@14: /** Chris@14: * Builds render arrays for block plugins and sets it on the event. Chris@14: * Chris@14: * @param \Drupal\layout_builder\Event\SectionComponentBuildRenderArrayEvent $event Chris@14: * The section component render event. Chris@14: */ Chris@14: public function onBuildRender(SectionComponentBuildRenderArrayEvent $event) { Chris@14: $block = $event->getPlugin(); Chris@14: if (!$block instanceof BlockPluginInterface) { Chris@14: return; Chris@14: } Chris@14: Chris@14: // Only check access if the component is not being previewed. Chris@14: if ($event->inPreview()) { Chris@14: $access = AccessResult::allowed()->setCacheMaxAge(0); Chris@14: } Chris@14: else { Chris@14: $access = $block->access($this->currentUser, TRUE); Chris@14: } Chris@14: Chris@14: $event->addCacheableDependency($access); Chris@14: if ($access->isAllowed()) { Chris@14: $event->addCacheableDependency($block); Chris@14: Chris@14: $build = [ Chris@14: // @todo Move this to BlockBase in https://www.drupal.org/node/2931040. Chris@14: '#theme' => 'block', Chris@14: '#configuration' => $block->getConfiguration(), Chris@14: '#plugin_id' => $block->getPluginId(), Chris@14: '#base_plugin_id' => $block->getBaseId(), Chris@14: '#derivative_plugin_id' => $block->getDerivativeId(), Chris@14: '#weight' => $event->getComponent()->getWeight(), Chris@14: 'content' => $block->build(), Chris@14: ]; Chris@14: $event->setBuild($build); Chris@14: } Chris@14: } Chris@14: Chris@14: }