class NotFound in Unpublished 404 8
Redirects 403 node page error responses to 404 page.
Hierarchy
- class \Drupal\Core\EventSubscriber\HttpExceptionSubscriberBase implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
- class \Drupal\unpublished_404\EventSubscriber\NotFound
Expanded class hierarchy of NotFound
1 string reference to 'NotFound'
1 service uses NotFound
File
- src/
EventSubscriber/ NotFound.php, line 13
Namespace
Drupal\unpublished_404\EventSubscriberView source
class NotFound extends HttpExceptionSubscriberBase {
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountProxyInterface
*/
protected $account;
/**
* Constructs a NotFound object.
*
* @param \Drupal\Core\Session\AccountProxyInterface $account
* The current user.
*/
public function __construct(AccountProxyInterface $account) {
$this->account = $account;
}
/**
* {@inheritdoc}
*/
protected static function getPriority() {
return 1000;
}
/**
* {@inheritdoc}
*/
protected function getHandledFormats() {
return [
'html',
];
}
/**
* Handles all 4xx errors for all serialization failures.
*
* @param \Symfony\Component\HttpKernel\Event\ExceptionEvent $event
* The event to process.
*/
public function on403(ExceptionEvent $event) {
// Check if current user has pemission to view own unpublished content.
if ($this->account && !$this->account
->hasPermission('view own unpublished content')) {
$request = $event
->getRequest();
if ($node = $request->attributes
->get('node')) {
if (!$node
->isPublished()) {
$event
->setThrowable(new NotFoundHttpException());
}
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
HttpExceptionSubscriberBase:: |
public static | function | Registers the methods in this class that should be listeners. | |
HttpExceptionSubscriberBase:: |
public | function | Handles errors for this subscriber. | |
NotFound:: |
protected | property | The current user. | |
NotFound:: |
protected | function |
Specifies the request formats this subscriber will respond to. Overrides HttpExceptionSubscriberBase:: |
|
NotFound:: |
protected static | function |
Specifies the priority of all listeners in this class. Overrides HttpExceptionSubscriberBase:: |
|
NotFound:: |
public | function | Handles all 4xx errors for all serialization failures. | |
NotFound:: |
public | function | Constructs a NotFound object. |