Skip to main content

Posts

Showing posts with the label event subscriber

Welcome to the Drupal Playground!

Hey there, Drupal enthusiasts! 🎉

We’re thrilled to welcome you to Drupal Playground, where creativity, innovation, and the power of Drupal come together. This is your space to explore, learn, and build amazing things using one of the most flexible CMS platforms out there.

Happy Drupaling!
— The Drupal Playground Team

Set Custom Header Variables for API in Drupal 9

Create and Install a Custom Module Create an Event Subscriber in the Custom Module . Place the Event Subscriber file in the src/EventSubscriber folder of the custom module. <?php // In your_module/src/EventSubscriber/CustomHeaderSubscriber.php namespace Drupal\custom\EventSubscriber ; use Symfony\Component\EventDispatcher\ EventSubscriberInterface ; use Symfony\Component\HttpKernel\Event\ RequestEvent ; use Symfony\Component\HttpKernel\ KernelEvents ; use Symfony\Component\HttpKernel\Exception\ AccessDeniedHttpException ; use Symfony\Component\HttpFoundation\ Response ; /**  * Event subscriber to check for a custom header in incoming requests.  */ class CustomHeaderSubscriber implements EventSubscriberInterface {   /**    * { @inheritdoc }    */   public static function getSubscribedEvents () {     // Subscribe to the request event, with a priority of 30     $ events [ KernelEvents:: REQUEST ][] = [ 'checkCusto...