New updates.
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\nodepath_access\EventSubscriber;
|
||||
|
||||
use Symfony\Component\HttpKernel\KernelEvents;
|
||||
use Symfony\Component\HttpKernel\Event\RequestEvent;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
/**
|
||||
* Class EntityTypeSubscriber.
|
||||
*
|
||||
* @package Drupal\nodepath_access\EventSubscriber
|
||||
*/
|
||||
class KernelRequestNodePathCheck implements EventSubscriberInterface {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return array
|
||||
* The event names to listen for, and the methods that should be executed.
|
||||
*/
|
||||
public static function getSubscribedEvents() {
|
||||
return [
|
||||
KernelEvents::REQUEST => 'onRequest',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* React to a config object being saved.
|
||||
*/
|
||||
public function onRequest(RequestEvent $event) {
|
||||
$user = \Drupal::currentUser();
|
||||
$user_roles = $user->getRoles();
|
||||
if (!in_array('anonymous', $user_roles)) {
|
||||
return;
|
||||
}
|
||||
$current_request = \Drupal::requestStack()->getCurrentRequest();
|
||||
$path = \Drupal::request()->getRequestUri();
|
||||
if (str_contains($path, '/node/')) {
|
||||
throw new NotFoundHttpException();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user