Questions tagged [event-subscribers]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0
votes
0answers
29 views

Ajax custom command to clear cache of custom block with flagging [closed]

I created a custom block that shows the number of flagged nodes. Because most hooks for flagging in Drupal 8 are deprecated, I used an event that listens to flagging and unflagging a node. For now ...
1
vote
1answer
60 views

EventSubscriber returning correct content but status code is 404

As the title says, content is being returned correctly but the status code is 404. I have checked the .htaccess file and the Apache config file as well. All seems to be fine. I have the following in ...
0
votes
1answer
20 views

Send email to Commerce customer after order status is changed to Completed

I am attempting to develop a module that will send an email to a customer in my Commerce 2 store when that customer's order's status is updated to "Completed". I am basing my module off of ...
1
vote
1answer
42 views

What is the “contract” for EventSubscriberInterface functions?

The EventSubscriberInterface can be used to listen for events, and getSubscribedEvents is used to announce which events an implementation would like to subscribe to. The getSubscribedEvents must ...
0
votes
0answers
16 views

Ordered Item getting removed & total is incorrect when using \Drupal\commerce_order\OrderRefreshInterface::refresh

As an alternate solution to this issue https://www.drupal.org/project/commerce/issues/3019615, I tried the following EventSubscriber. <?php namespace Drupal\my_module\EventSubscriber; use Drupal\...
0
votes
1answer
19 views

On entity save, identify the user fields that have been changed

I have a need to track changes to users in a separate database, apart from Drupal. When a user changes their email address or their password, I need to communicate that change with a shadow table in ...
0
votes
0answers
40 views

How to subscribe to the “order placed” “order paid” event?

I created a module for generating a license and recording it in the user field, I want to create an event, it should be triggered when the user has completed a purchase (bought an item or paid for an ...
0
votes
1answer
57 views

how to add an event subscriber when the user reaches the login form

I am new on Drupal 8 , I have implemented a hook 'hook_form_alter' in my module to add a new field to the login form , but now I want to handle it with the event , I want to trigger an event when the ...
1
vote
1answer
58 views

My site only listens to the event after I clear all caches

I have a module with an event subscribe that I use to redirect to an age verification page if a cookie is not set, and as long as the current request is not the age verification uri. if(!isset($...
0
votes
0answers
67 views

Does drush stop events from firing and/or bypass event subscribers?

I'm running some migrations and have logic dependent on their Events public static function getSubscribedEvents() { $events[MigrateEvents::POST_IMPORT][] = ['onMigratePostImport']; return $...
2
votes
2answers
49 views

Which event should we subscribe to if we want code to be triggered when a new user registers?

I noticed that the following event is defined for when a user account is 'set const SET_USER = 'account.set'; I want to execute code by creating an event subscriber when a new user registers on the ...
0
votes
0answers
54 views

Enabling module and executing event subscriber from same module in same process

I wrote a Drush command which does multiple things, first of them is to enable some modules, and in the end, it fires an event (event1). During the module enablement process, it enables module_x also, ...
0
votes
0answers
22 views

How do you simulate Google login with the Drupal 8 social auth module in ones local server?

I am trying to test Google login in my local machine to capture the event and activate the user automatically. I had run code to simulate the triggering of the event but that might not be authentic ...
0
votes
0answers
16 views

Whats the file structure and correct implementation of using StackMiddlware for a redirection? [duplicate]

I'm currently using an EventSubscriber to successfully redirect unauthenticated users from my site. However, the redirection still takes place on that specific page even after the user is logged in ...
2
votes
0answers
87 views

How to implement StackMiddleware for a redirection correctly?

I'm working on a redirection (for unauthenticated users) for my Drupal 8 site. Currently, the redirection works however, the redirection persists even after user is authenticated. I found this article ...
0
votes
0answers
39 views

Event Subscriber Response Mismatch - Content Switch

I've got an event subscriber that checks on the entity being requested/returned - and under certain conditions I'd like it to return a different page as a 404. I was thinking about extending ...
1
vote
0answers
51 views

How to make EventSubscriber run on every page load? [duplicate]

Tripped up on how to make my EventSubscriber code run on every page load. In my src/EventSubscriber/RedirectAnonymousSubscriber.php file here's my code: <?php namespace Drupal\mymodule\...
-1
votes
1answer
85 views

Redirecting Anonymous Users to external URL on Drupal 8 site

Still pretty new to Drupal, but I am attempting to create a custom module that redirects anonymous/unauthenticated users away from the site. This site is only supposed to be used by admin's so in ...
0
votes
0answers
49 views

Change system.404 path dynamically based on context

I have a site that makes use of the groups module to denote various locations all with their own content. I'd like to give the ability to programmatically alter the system.404 path depending on the ...
1
vote
1answer
39 views

adding new validation method using HookEventDispatcherInterface::FORM_ALTER event

I'm trying to add a new validation method for 'user_login_form' using HookEventDispatcher module and events: class MyFormEventsSubscriber implements EventSubscriberInterface { public static function ...
0
votes
1answer
45 views

Don't cache custom Front Page domain

I'm working on a module that shows a different frontpage per role. I have three frontpages: the base www.domain.nl for anonymous users, set in the basic site settings for users with role_1 they go to ...
-4
votes
1answer
49 views

Expected \Drupal\User\Interface got Drupal\Core\Entity\EntityInterface [closed]

I am trying to load a user and pass it a UserEvent class to simulate an event trigger. $user = \Drupal::entityTypeManager()->getStorage('user')->load($id); However, the Class only accepts ...
0
votes
1answer
86 views

Looking for a way to trigger an event for testing custom event subscriber

I am looking for ways to trigger an event in my local dev to check out a custom event subscriber. The actual event is triggered by Google social auth and I don't think it is possible to do that ...
0
votes
0answers
51 views

Bypassing page cache for Drupal events

I need some session verification code to be run on each request to Drupal. The most obvious solution that I have found was to use the EventSubscriber interface, and the KernelEvents::REQUEST event. ...
1
vote
0answers
18 views

Limit entity type/bundle for EventSubscriber inside services.yml?

I've got an EventSubscriber that I'd like to run for only a specific content type. Is there a way to do this from the services.yml file as an argument or something, or do I just need to check for the ...
0
votes
1answer
181 views

Run code once on each page load

In the past there were some hooks, such as described here: How to run check on each page load? to execute arbitrary code on each page load. Now this has been replaced with an event based approach. I ...
2
votes
1answer
193 views

Is it possible to override/replace an event subscriber

I would like to replace an event subscriber. Is there any way that I can write my class implementing EventSubscriberInterface which would replace another existing event subscriber instead of being ...
0
votes
1answer
166 views

Event subscriber to invalidate a cache

I am invalidating a cache tag in KernelEvents::REQUEST event: public static function getSubscribedEvents() { $events[KernelEvents::REQUEST][] = ['onRequest', 100]; return $events; } public ...
3
votes
1answer
282 views

How can trusted host patterns be set dynamically?

I'm working on a site which uses the Groups module that will allow users to create groups on the site. The site will then allow for users to point custom domain names at the site, with the content for ...
0
votes
1answer
29 views

Forward authenticated user to user.page on /login uri

If an authenticated user navigates to /login on a Drupal 8 site, she gets the "access denied" error. I want the site to redirect that user to /user (route user.page) instead. Unfortunately my ...
0
votes
0answers
178 views

How can I trigger the EntityTypeEvents::UPDATE event?

I tried to trigger event on each entity update. This is my src/EventSubscriber/MySub.php use Drupal\Core\Entity\EntityTypeEvents; use Symfony\Component\EventDispatcher\...
0
votes
1answer
50 views

Alter existing route's output formats?

I want to alter the entity.node.canonical route so that when it is accessed using ?_format=json it will return the rendered node in JSON. So far I have created a RouteSubscriber that alters the route ...
0
votes
0answers
44 views

How do I redirect a user basing on its roles?

I'm having an issue with writing a redirect based on whether or not the current user's role matches the one listed or not I've been trying to find solutions related to getting the current path for ...
-1
votes
1answer
179 views

Error with Event Subscriber using getRouteName()

I have a problem with event subscriber. Here is the error: The website encountered an unexpected error. Please try again later. Error: Call to a member function getRouteName() on null in Drupal\...
0
votes
0answers
171 views

Return an Ajax Response from EventSubscriber?

I am trying to return an ajax response when a user logs in while the page is loading post-login. /#1 approach was attaching an ajax callback to the user login form submit with form_alter. However ...
0
votes
1answer
577 views

How to alter response headers from module hook

I am puzzled how to alter the response headers from specific hook (hook_file_download)? /** * Implements hook_file_download(). */ function example_file_download($uri) { $scheme = FileSystem::...
1
vote
2answers
440 views

View all subscribed events?

I have a feature where if a user navigates to a specific url (www.mysite.com/special-content) they are redirected to the login page, where we've appended a destination to the request (www.mysite.com/...
1
vote
1answer
73 views

setContainer Error When Registering an EventSubscriber Service

I am trying to create a basic event subscriber, but when I add the services.yml file and attempt to rebuild the cache with drush cr, I get this error. In Drupal.php line 130: \Drupal::$...
0
votes
1answer
186 views

Would replacing hooks with events be a good practice?

Do you think it would be a good practice to replace hooks with events? I mean dispatching an event inside a hook to subscribe afterwards. For example if you have 20 hooks in your module, is it ...
0
votes
3answers
224 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 ...
0
votes
0answers
100 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
909 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
110 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
81 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
405 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
247 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
372 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
245 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
205 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
62 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 ...