Skip to content

Instantly share code, notes, and snippets.

@vyspiansky
Created April 18, 2024 13:08
Show Gist options
  • Save vyspiansky/c842f7702bce81f92968ffe80a79b96d to your computer and use it in GitHub Desktop.
Save vyspiansky/c842f7702bce81f92968ffe80a79b96d to your computer and use it in GitHub Desktop.
Drupal: return a 403 response from a controller
<?php
namespace Drupal\your_module\Controller;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
class YourController {
public function yourPage() {
// Some logic here...
if (!$access) {
throw new AccessDeniedHttpException();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment