class SimpleMegaMenuAccessCanonicalPageSubscriber in Simple Mega Menu 8
Same name and namespace in other branches
- 2.0.x src/EventSubscriber/SimpleMegaMenuAccessCanonicalPageSubscriber.php \Drupal\simple_megamenu\EventSubscriber\SimpleMegaMenuAccessCanonicalPageSubscriber
Class SimpleMegaMenuAccessCanonicalPageSubscriber.
@package Drupal\simple_megamenu
Hierarchy
- class \Drupal\simple_megamenu\EventSubscriber\SimpleMegaMenuAccessCanonicalPageSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of SimpleMegaMenuAccessCanonicalPageSubscriber
1 string reference to 'SimpleMegaMenuAccessCanonicalPageSubscriber'
1 service uses SimpleMegaMenuAccessCanonicalPageSubscriber
File
- src/
EventSubscriber/ SimpleMegaMenuAccessCanonicalPageSubscriber.php, line 18
Namespace
Drupal\simple_megamenu\EventSubscriberView source
class SimpleMegaMenuAccessCanonicalPageSubscriber implements EventSubscriberInterface {
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountInterface
*/
protected $currentUser;
/**
* Constructor.
*
* @param \Drupal\Core\Session\AccountInterface $current_user
* The current user.
* @param \Drupal\Core\Routing\UrlGeneratorInterface $url_generator
* The url generator.
*/
public function __construct(AccountInterface $current_user, UrlGeneratorInterface $url_generator) {
$this->currentUser = $current_user;
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events[KernelEvents::REQUEST] = [
'onRequestCheckAccess',
];
return $events;
}
/**
* This method is called whenever the kernel.request event is dispatched.
*
* @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
* The event object.
*/
public function onRequestCheckAccess(GetResponseEvent $event) {
$request = $event
->getRequest();
// If we've got an exception, nothing to do here.
if ($request
->get('exception') != NULL) {
return;
}
/** @var \Drupal\simple_megamenu\Entity\SimpleMegaMenu $simple_mega_menu */
$simple_mega_menu = $request
->get('simple_mega_menu');
if ($simple_mega_menu && $simple_mega_menu instanceof SimpleMegaMenuInterface) {
if (!$this->currentUser
->hasPermission('access simple mega menu entities canonical page')) {
throw new NotFoundHttpException();
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SimpleMegaMenuAccessCanonicalPageSubscriber:: |
protected | property | The current user. | |
SimpleMegaMenuAccessCanonicalPageSubscriber:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
SimpleMegaMenuAccessCanonicalPageSubscriber:: |
public | function | This method is called whenever the kernel.request event is dispatched. | |
SimpleMegaMenuAccessCanonicalPageSubscriber:: |
public | function | Constructor. |