This project is not covered by Drupal’s security advisory policy.
This module replaces all hook/alter functions calls with event subscribers calls, and it dispatches global events too.
After installing it all hooks and alters functions will be executed with system events, this allows remove, overwrite, or replace module implementations. This enables general events too, not linked to modules, for new hooks/alters implementations,
now with an event approach.
REQUIREMENTS
------------
No special requirements.
INSTALLATION
------------
* Install as you would normally install a contributed Drupal module. Visit
https://www.drupal.org/node/1897420 for further information.
* You could use: composer require drupal/eventer
CONFIGURATION
-------------
* After enabling this module all hooks and alters will be executed in the same way that without the module, but using events. You not must-see any site change.
* The module has a block to see events subscribers added to build the current page, it's a nice tool to debug events.
FAQ
---
* How to use this module?
The module include a development block to see the fired events on a page, it's called "List events block". We must add it in the footer, the last module rendered, to see fired events.
The block shows you a list of events fired with her listeners sorted by priority. Something like this:
Event key: routing.route_finished
Listeners:
[Pri. 200] Drupal\Core\EventSubscriber\CacheRouterRebuildSubscriber::onRouterFinished
[Pri. 100] Drupal\Core\EventSubscriber\MenuRouterRebuildSubscriber::onRouterRebuild
[Pri. 0] Drupal\Core\Routing\RouteProvider::reset
[Pri. 0] Drupal\Core\Routing\RoutePreloader::onFinishedRoutes
[Pri. 0] Drupal\Core\EventSubscriber\PathRootsSubscriber::onRouteFinished
[Pri. 0] Drupal\views\EventSubscriber\RouteSubscriber::routeRebuildFinished
[Pri. -3000] Drupal\Core\Routing\RouteProviderLazyBuilder::routerRebuildFinished
An example of hook event may be:
Event key: eventer.module.system.theme_suggestions_html
Listeners:
[Pri. 0] Drupal\eventer\EventSubscriber\LegacyHookSubscriber::execute
With this information, you can create a new listener to do the changes that you need.
Then, in mymodule.services.yml can add:
services:
mymodule.event_subscriber:
class: Drupal\mymodule\EventSubscriber\MyModuleSubscriber
arguments: ['@messenger']
tags:
- { name: event_subscriber }
And the new listener:
<?php
namespace Drupal\mymodule\EventSubscriber;
use Drupal\Core\Messenger\MessengerInterface;
use Drupal\eventer\Event\HookEvent;
use Drupal\eventer\EventerEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
/**
* mymodule event subscriber.
*/
class MyModuleSubscriber implements EventSubscriberInterface {
/**
* The messenger.
*
* @var \Drupal\Core\Messenger\MessengerInterface
*/
protected $messenger;
/**
* Constructs event subscriber.
*
* @param \Drupal\Core\Messenger\MessengerInterface $messenger
* The messenger.
*/
public function __construct(MessengerInterface $messenger) {
$this->messenger = $messenger;
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
return [
EventerEvents::MODULE_HOOK . 'system.theme_suggestions_html' => ['onSystemSuggestions', 100],
];
}
/**
* Event handler.
*
* @param \Drupal\eventer\Event\HookEvent $event
* Response event.
*/
public function onSystemSuggestions(HookEvent $event) {
$this->messenger->addStatus(__FUNCTION__);
// Stop the module hook execution.
$event->stopPropagation();
}
}
* How is the event key naming?
- Event prefixes:
EventerEvents::MODULE_HOOK = 'eventer.module.'
EventerEvents::MODULE_HOOK_ALTER = 'eventer.module.alter.'
EventerEvents::THEME_HOOK_ALTER = 'eventer.theme.alter.'
- Variable naming:
$module: Module machine name.
$hook: Hook base type, f.e. 'entity_field_access'
$type: Same as $hook.
$extra_type: Same as $hook.
$theme_key: Theme machine name.
- Event naming:
EventerEvents::MODULE_HOOK . $module . '.' . $hook
EventerEvents::MODULE_HOOK . $hook
EventerEvents::MODULE_HOOK_ALTER . $type
EventerEvents::MODULE_HOOK_ALTER . $module . '.' . $type
EventerEvents::MODULE_HOOK_ALTER . $extra_type
EventerEvents::MODULE_HOOK_ALTER . $module . '.' . $extra_type
EventerEvents::THEME_HOOK_ALTER . $type
EventerEvents::THEME_HOOK_ALTER . $theme_key . '.' . $type
EventerEvents::THEME_HOOK_ALTER . $extra_type
EventerEvents::THEME_HOOK_ALTER . $theme_key . '.' . $extra_type
- Event examples:
Event key: eventer.module.alter.content_translation.language_types_info
Hook: language_types_info
Module: content_translation
Prefix: EventerEvents::MODULE_HOOK_ALTER
Hook function: content_translation_language_types_info_alter
Not hook event key: eventer.module.alter.language_types_info
Event key: eventer.module.charts.views_pre_view
Hook: views_pre_view
Module: charts
Prefix: EventerEvents::MODULE_HOOK
Hook function: charts_views_pre_view
Not hook event key: eventer.module.views_pre_view
Event key: eventer.module.group.entity_field_access
Hook: entity_field_access
Module: group
Prefix: EventerEvents::MODULE_HOOK
Hook function: group_entity_field_access
Not hook event key: eventer.module.entity_field_access
Event key: eventer.module.alter.content_translation.module_implements
Hook: module_implements
Module: content_translation
Prefix: EventerEvents::MODULE_HOOK_ALTER
Hook function: content_translation_module_implements_alter
Not hook event key: eventer.module.alter.module_implements
Event key: eventer.module.alter.group.form
Hook: form
Module: N/A
Prefix: EventerEvents::MODULE_HOOK_ALTER
Hook function: N/A
Not hook event key: N/A
Event key: eventer.theme.alter.mytheme.page_attachments
Hook: page_attachments
Theme: mytheme
Prefix: EventerEvents::THEME_HOOK_ALTER
Hook function: mytheme_page_attachments_alter
Not hook event key: eventer.theme.alter.page_attachments
MAINTAINERS
-----------
Current maintainers:
* Pedro Pelaez (psf_) - https://www.drupal.org/u/psf_
This project has been sponsored by:
* Front.id
Front ID is a distributed web development company of Drupal experts, but not limited to it. Our services include Frontend and Backend development, Drupal consultancy and Drupal training.
Project information
Minimally maintained
Maintainers monitor issues, but fast responses are not guaranteed.Maintenance fixes only
Considered feature-complete by its maintainers.- Project categories: Developer tools, Performance
- Created by psf_ on , updated
This project is not covered by the security advisory policy.
Use at your own risk! It may have publicly disclosed vulnerabilities.
Releases
Development version: 1.x-dev updated 21 Aug 2020 at 09:56 UTC
