Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [event-subscriber]

The tag has no usage guidance.

0
votes
3answers
39 views

How can you remove another modules events?

So, I have an event subscriber for Drupal commerce that listens for "commerce_order.place.post_transition" and will send a bespoke order email (due to not being able to change some of the things like ...
-1
votes
0answers
27 views

Replacing hook_boot() by using an Event Subscriber vs settings.php

OK, I’m trying the best way to handle this: On a Drupal 7 site I had a poor man’s URL shortener. I created a slug by encoding a node’s NID using an algorithm that wouldn’t contain a vowel. In ...
0
votes
0answers
40 views

Why are KernelEvents not triggered on cached pages? [duplicate]

Why Kernal events not triggering on cached pages.I have tried using priorities.. $events[KernelEvents::REQUEST][] = ['onRequest', 27]; Services.yml file tags: - { name: 'event_subscriber', ...
5
votes
2answers
131 views

Can't find cookie for validation in EventSubscriber

There's this module Splash Redirect in which src/EventSubscriber/SplashRedirectEventSubscriber.php is supposed to check if the cookie $config_cookie exists or not, if it already exists then the user ...
1
vote
1answer
28 views

How to change a field value in a product variation when someone edited the order manually?

I had implemented a "Event Subscriber" controller to change the stock value in the product variation. Stock is a field in product variation. Depending upon the quantity in order items I am ...
0
votes
1answer
35 views

Plugins before event subscribers

Not sure if there's a way out of this problem but... I have a custom log module which listens for events that could come from multiple sources. All it does is listen for an event, and if it occurs ...
0
votes
0answers
58 views

Subscribe to content type creation event

I'm using Drupal 8 (8.6.2). My main objective is to read fields of newly created content type (or changed, it doesn't matter) and create few helper data structures. To achieve this, I'm trying to ...
1
vote
1answer
60 views

Handling access denied result

In Drupal 8, what is the correct way of returning access denied to a user (outside of access requirement on a controller)? I'd say it is to throw an AccessDeniedHttpException most of the time, but I ...
0
votes
0answers
20 views

How to modify drupalSettings JavaScript in an Event?

I have a UserLogin event subscriber. I want this subscriber to output a variable from marketing tracking purposes to Javascript, however, I don't see how I could accomplish this, as the Event ...
0
votes
0answers
65 views

Throwing an AccessDeniedHttpException() in an event causes a “max nesting level” error

I am debugging an event subscriber that checks if a user has access based on certain conditions. If they don't have access, then I am doing: throw new AccessDeniedHttpException(); However, this was ...
0
votes
1answer
26 views

Class not found for a new module/service I am building. I am not sure how to debug

I am building a new service, an event subscriber in a custom module. My class which extends EventSubscriberInterface is not being found. [error] Class Drupal\fivewire_commerce\EventSubscriber\...
2
votes
3answers
102 views

How are hooks implemented?

Are hooks a thing in their own right, or are they actually implemented as events under the hood?
2
votes
1answer
41 views

Hook or event before a page gets cached

Is there a hook or event I can tie into before a page gets cached. I need a hook/event that I can call so that I can run some logic on the page that is about to be cached to tell Drupal if I want a ...
0
votes
2answers
73 views

Which events are invoked when an order is removed or cancelled?

I have already an event subscriber class with commerce_order.place.post_transition defined. I need to remove nodes when an order is deleted or canceled. What event could I use in that case?
0
votes
1answer
146 views

Dispatch an Event when the a user logs

I was looking into the new Events system for Drupal 8 and there's something I haven't been able to figure out. I need to dispatch an event when a user logs something to the watchdog table using the ...
0
votes
0answers
71 views

FileNotFoundException for existing file?

I'm using the below EventSubscriber to redirect a media entity's URL to it's file's URL unless that file is one of several file types, in which case I want to force a download. I've gotten it to ...
0
votes
1answer
26 views

How to load a file during the load of drupal 8 bootstrap (hook_init)

I want to make something that in Drupal 7 can easily be done with hook_init, but this hook doesn't exists in Drupal 8. I want to load an .env file and at the same time load the dotenv file from ...
3
votes
1answer
717 views

EventSubscriber endless redirect

I have Drupal 8.5.1 and I am trying to force a redirect for anonymous users to the CAS login page. First I thought that the issue was related with the firing of the checkAuthStatus function below, ...
0
votes
0answers
83 views

How to add event in cron queue by event subscribe in drupal 8?

I have to add an event in cron query. what I am trying to do is to create an event as the order is confirmed and placed that event in the query. so as the cron run email will be sent.Also, i have put ...
2
votes
1answer
401 views

Run KernelEvents::REQUEST event before hook_node_access?

I'm doing some central static variable setup for the request and was hoping to use KernelEvents::REQUEST to run first and set the variables. However, I've found that while the documentation states: ...
0
votes
1answer
300 views

Drupal 8: Class not found from module Controller, but works fine from module EventSubscriber

I created a custom D8 module in: <root>/modules/custom/mymodule In that custom module are src/Controller/MyController.php and src/EventSubscriber/MySubscriber.php. I wrote some custom code ...
1
vote
0answers
418 views

How to understand and fix a Reflection does not exist error?

I am trying to get my head around using EventSubscriber for adding HTTP Headers. In D7 I would have simply used drupal_add_http_header('Content-Type', 'application/javascript'); But I see that this ...
1
vote
1answer
168 views

Using Event Subscriber change the product custom field value after first checkout of that product

Using 'Event Subscriber', I'm able to get $order and $items from the order after completing the checkout. How can I get the product id from the $itemsand modify the product custom field value? ...
0
votes
0answers
46 views

Check for entity before loading

How can I verify a node exists, early during Drupal 8 bootstrapping? I wish to create a node if it doesn't already exist (by reading the URL, testing via entity load, then querying a remote API and ...
5
votes
1answer
480 views

Why is it better to use event subscribers rather than hooks

In drupal 8, we now have the ability to use event subscribers. What's the reason for this? Is it to work with the new cache API better? Recently I had a task of needing to extract data from a node ...
1
vote
0answers
75 views

How can an event subscriber have access to the entity type?

I'm using entity_print for PDF generation on two node types. I'd like each to have its own orientation configuration (or just have one override the default). There is an event in entity_print where ...
1
vote
0answers
149 views

How to fire an Event on node publish on Drupal 8

I am trying to figure out how to fire an event when a node type gets published so I can set up a listener to listen to that event. Can someone explain what is the best practice and how to fire an ...
5
votes
1answer
913 views

Custom 500 Error page: Is there a way to theme a fatal error?

In /core/includes/errors.inc, when there is a fatal error it outputs a response with the message "The website encountered an unexpected error. Please try again later." and a back-trace, if error_level ...
3
votes
1answer
149 views

Create an EventSubscriber for a specific module

I'm attempting to make something occur at a specific event in the GatherContent module found here https://www.drupal.org/project/gathercontent Based on the information here http://help.gathercontent....
0
votes
1answer
535 views

Must implement interface > Drupal\Core\Entity\EntityTypeManagerInterface, none given in __construct() function

I am trying to write a custom eventsubscriber for commerce 2.x for an event after a successful checkout. Everything works and now I want to create a __construct function to initialize an object, but ...
1
vote
2answers
252 views

How to discover events for event dispatcher

I want to write an implementation of EventSubscriberInterface for an event in commerce, there is a handy example, but How do I find out what events are available (as a whole for my site) and/or How ...
0
votes
1answer
297 views

How to use a terminate kernel event to log page access statistics?

In Drupal 7 hook_exit is implemented in the Statistics module to gather statistics for page accesses. This change record suggest the equivalent in Drupal 8 is to listen for kernel.terminate events. ...
1
vote
1answer
362 views

EventSubscriber called on specific node type or path

I'm trying to set an event that will launch function that loads some data from outside server and print it to javascript div element. I tried many ways but I can't figure out how to make this event be ...
0
votes
2answers
420 views

When an anonymous user hits '/user/login' route, how can I trigger an event?

I want to trigger an event when an anonymous user comes to /user/login. I made an event subscriber, but it only fires one time: namespace Drupal\mymodule\EventSubscriber; use Symfony\Component\...
3
votes
2answers
1k views

How to issue 404 from a KernelEvents::REQUEST event

I'm trying to issue a 404 from a KernelEvents::REQUEST event, but it's resulting in the following error: Fatal error: Maximum function nesting level of '256' reached, aborting! in /var/www/vendor/...
2
votes
1answer
828 views

Does not redirect in EventSubscriber [closed]

I want to redirect to specific url in EventSubscriber when I got the error "Page not found". I used Symfony2 redirect for event listener? but the redirect goes to the home Class: use Drupal\Core\Url;...
2
votes
0answers
391 views

Event subscription for EntityTypeEvents

So I'm trying to get an event subscriber working for EntityTypeEvents and I can't figure out why it's not firing. This is a general outline of the code: namespace Drupal\subscriber_class_module; ...
1
vote
0answers
258 views

How to implement redirect in kernel.request event properly?

I can reach site by multiple aliases. Business logic requires to do some redirects in case of accessing be an alias. E.g: alias1.dev -> site.dev/landing-page. I've implemented EventSubscriber for ...
2
votes
1answer
56 views

How to suppress default HtmlException?

I need to turn off 404 & related Exceptions. Need to handle it in custom way. I've implemented an EventSubscriber with listener for kernel.exception event. But $event->setException() cannot ...
6
votes
2answers
600 views

Event Response not firing anonymous user

I have a module in drupal8 which only job is on an event response is to redirect a URL. It works fine for everyone except anonymous users. How do I give the module privileges to fire on every user no ...
15
votes
4answers
5k views

Redirect Anonymous user to login page

I want if user not logged in and visit any page of my website except my REST VIEWS routers I redirect him/her to login page in drupal 8, I found this solutions for drupal 7 but didn't find any ...
7
votes
3answers
3k views

Does Drupal 8 entities have any events I can listen to?

I know we can use hook_entity_update() hook to do something when an entity is updated. But is there an event to listen for node updates/deletes, or other entities such for that matter?
1
vote
1answer
493 views

What to attach event listener to in Drupal behavior

I have a use case where I need to listen to the insertIntoActiveEditor event in the insertIntoActiveEditor event in the Insert module, but with this code: (function ($) { /** * Custom behavior to ...
1
vote
0answers
101 views

url redirections not working for anonymous users - redirecting to homepage

I have set a redirect rule in EventSubscriber. So according to rule, when I hit [example.com/my-page][1] in browser, it should redirect to [example.com/success][1] or some external url also. But ...
1
vote
2answers
156 views

Customizing the register form with a new class: Why do I get this error?

I'm trying to customize the register form. A user has a reference field to content of type A. However, I only want to allow values of A which satisfy a certain condition. To achieve this, I based my ...
2
votes
1answer
167 views

How do I unpromoted existing node when new node is promoted to front page (Programatically)?

In Drupal 8 I want only one node at a time to be promoted to front page. If user promoted new node the existed should un-promoted automatically. Can we implement this with events in Drupal 8?
1
vote
1answer
712 views

Event does not trigger each time I load a page

I'm using event dispatcher in a custom module to auto login users in a Drupal 8 website. I'm using the KernelEvents::REQUEST, with a onRequest fonction. I put an echo for testing that the function was ...
1
vote
1answer
309 views

Drush error: “ContainerAwareEventDispatcher” does't implement EventDispatcherInterface::getListenerPriority

I'm using Drupal 8.1.2 and Drush 8.1.2 (OS X 10.11.5, PHP 5.6.19) In all of my drush-commands, there occurs an error, that there is a missing implementations of the symfony EventDispatcherInterface::...
2
votes
2answers
3k views

How do I make a custom module trigger a function when content is unpublished?

In short: Utilizing Drupal 8, I'm hoping to to "hook" into an entity update event for a specific content type so that I can then take further action when that event occurs. In this case, delete the ...
8
votes
2answers
4k views

Problem with event subscriber - KernelEvents::REQUEST is not fired on cached pages

I am trying to implement a KernelEvents::REQUEST event subscriber to perform some action on page load. I need this event to fire regardless of whether the requested page exists in the Drupal cache - ...