-
-
Notifications
You must be signed in to change notification settings - Fork 531
Open
Labels
featureRequest about implementing a brand new function or possibility.Request about implementing a brand new function or possibility.
Description
Feature request
Summary
Support persistent event listeners registered by $modx->addEventListener($eventname, $pluginId)
in bootstrap.php
files and allow attaching anonymous functions as event handlers.
Why is it needed?
In MODX 3, packages can use bootstrap.php
for initialization, which is very convenient. However:
- When adding events with
$modx->addEventListener($event, $pluginId)
insidebootstrap.php
, they do not work as expected because later theeventMap
is reloaded and overwrites these changes. - This forces developers to always create plugins even for simple cases, which adds unnecessary boilerplate.
Having the ability to:
- Register persistent events directly in
bootstrap.php
. - Attach closures or callable functions as event handlers.
…would make package development cleaner and more flexible.
Suggested solution(s)
- Ensure that event listeners registered in
bootstrap.php
are not removed/overwritten when theeventMap
is reinitialized. - Extend
$modx->addEventListener()
to support callbacks/closures, for example:
$modx->addEventListener('OnWebPageInit', function($modx, $event) {
// custom logic here
});
or create new method like addEventListenerClosure
.
This would allow developers to bind logic directly in code without creating a separate plugin element.
Related issue(s)/PR(s)
Not found yet.
catsmeatman
Metadata
Metadata
Assignees
Labels
featureRequest about implementing a brand new function or possibility.Request about implementing a brand new function or possibility.