requestStack = $request_stack; $this->account = $account; } /** * Selects the block place override of the block page display variant. * * @param \Drupal\Core\Render\PageDisplayVariantSelectionEvent $event * The event to process. */ public function onBlockPageDisplayVariantSelected(PageDisplayVariantSelectionEvent $event) { if ($event->getPluginId() === 'block_page') { if ($this->requestStack->getCurrentRequest()->query->has('block-place') && $this->account->hasPermission('administer blocks')) { $event->setPluginId('block_place_page'); } $event->addCacheContexts(['user.permissions', 'url.query_args']); } } /** * {@inheritdoc} */ public static function getSubscribedEvents() { // Set a very low priority, so that it runs last. $events[RenderEvents::SELECT_PAGE_DISPLAY_VARIANT][] = ['onBlockPageDisplayVariantSelected', -1000]; return $events; } }