- Issue created by @adam_b
- Assigned to darkdim
- Issue was unassigned.
- Status changed to Needs review
10 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 ... } }
- π¨π¦Canada mandclu
It's worth pointing out that you could probably also handle this in configuration by using ECA.
- πΊπΈUnited States mlncn Minneapolis, MN, USA
@darkdim rather than having the overhead (and harder-to-follow code) of actually implementing the the event handler, is it OK to treat it as an "alter" event and only have an example of implementing it, perhaps in a registration_role.api.php file?
Thanks so much, i do think we should bring this in before we change anything that would break applying this merge request as a patch.
Current code in: https://git.drupalcode.org/project/registration_role/-/merge_requests/3/...
Also is the gitlab-ci.yml something all contrib projects should have now?