class BlockPlaceEventSubscriber in Drupal 8
Hierarchy
- class \Drupal\block_place\EventSubscriber\BlockPlaceEventSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of BlockPlaceEventSubscriber
See also
\Drupal\block_place\Plugin\DisplayVariant\PlaceBlockPageVariant
1 string reference to 'BlockPlaceEventSubscriber'
- block_place.services.yml in core/
modules/ block_place/ block_place.services.yml - core/modules/block_place/block_place.services.yml
1 service uses BlockPlaceEventSubscriber
File
- core/
modules/ block_place/ src/ EventSubscriber/ BlockPlaceEventSubscriber.php, line 14
Namespace
Drupal\block_place\EventSubscriberView source
class BlockPlaceEventSubscriber implements EventSubscriberInterface {
/**
* The request stack.
*
* @var \Symfony\Component\HttpFoundation\RequestStack
*/
protected $requestStack;
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountInterface
*/
protected $account;
/**
* Constructs a \Drupal\block_place\EventSubscriber\BlockPlaceEventSubscriber object.
*
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
* The request stack used to retrieve the current request.
* @param \Drupal\Core\Session\AccountInterface $account
* The current user.
*/
public function __construct(RequestStack $request_stack, AccountInterface $account) {
$this->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;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BlockPlaceEventSubscriber:: |
protected | property | The current user. | |
BlockPlaceEventSubscriber:: |
protected | property | The request stack. | |
BlockPlaceEventSubscriber:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
BlockPlaceEventSubscriber:: |
public | function | Selects the block place override of the block page display variant. | |
BlockPlaceEventSubscriber:: |
public | function | Constructs a \Drupal\block_place\EventSubscriber\BlockPlaceEventSubscriber object. |