public function AgreementSubscriber::checkForRedirection in Agreement 3.0.x
Same name and namespace in other branches
- 8.2 src/EventSubscriber/AgreementSubscriber.php \Drupal\agreement\EventSubscriber\AgreementSubscriber::checkForRedirection()
Check if the user needs to accept an agreement.
Parameters
\Symfony\Component\HttpKernel\Event\ExceptionEvent|\Symfony\Component\HttpKernel\Event\RequestEvent $event: The response event.
2 calls to AgreementSubscriber::checkForRedirection()
- AgreementSubscriber::exceptionRedirect in src/
EventSubscriber/ AgreementSubscriber.php - Performs redirect for access denied exceptions.
- AgreementSubscriber::requestForRedirection in src/
EventSubscriber/ AgreementSubscriber.php - Executes function to set redirect response if it is required.
File
- src/
EventSubscriber/ AgreementSubscriber.php, line 76
Class
- AgreementSubscriber
- Checks if the current user is required to accept an agreement.
Namespace
Drupal\agreement\EventSubscriberCode
public function checkForRedirection($event) {
// Users with the bypass agreement permission are always excluded from any
// agreement.
if (!$this->account
->hasPermission('bypass agreement')) {
$path = $this->pathStack
->getPath($event
->getRequest());
$info = $this->handler
->getAgreementByUserAndPath($this->account, $path);
if ($info) {
// Save intended destination.
// @todo figure out which of this is still necessary.
if (!isset($_SESSION['agreement_destination'])) {
if (preg_match('/^user\\/reset/i', $path)) {
$_SESSION['agreement_destination'] = 'change password';
}
else {
$_SESSION['agreement_destination'] = $path;
}
}
// Redirect to the agreement page.
$redirect_path = $event
->getRequest()
->getBasePath() . $info
->get('path');
$event
->setResponse(new RedirectResponse($redirect_path));
}
}
}