- Issue created by @adam_b
- Assigned to darkdim
- Issue was unassigned.
- Status changed to Needs review
9 months ago 6:26am 25 April 2024 - πΊπ¦Ukraine darkdim Kyiv
darkdim β changed the visibility of the branch 3380038-how-to-conditionally to hidden.
- πΊπΈUnited States mlncn Minneapolis, MN, USA
Oooh very interesting. Could you describe how the event can be intercepted/used?
- πΊπ¦Ukraine darkdim Kyiv
Yes, sure.
1. Create a module
2. You need to describe the service as an event subscriber
3. Create an EventSubscriber directory in the src folder
4. Create the subscriber class itselfThere is a book with a code, at the address you can see events https://selwynpolit.github.io/d9book/events
services: my_module.roles_subscriber: class: Drupal\my_module\EventSubscriber\ClassSubscriber arguments: [] tags: - { name: event_subscriber }
<?php namespace Drupal\my_module\EventSubscriber; use Drupal\registration_role\Event\SelectRoleEvent; use Symfony\Component\EventDispatcher\EventSubscriberInterface; class ClassSubscriber implements EventSubscriberInterface { public static function getSubscribedEvents() { $events[SelectRoleEvent::SELECT_ROLE_EVENT][] = ['registrationRole', 0]; return $events; } public function registrationRole(SelectRoleEvent $event) { $user = $event->getUser(); ... logic ... } }