Skip to content

Add support for file-based event listeners (e.g. elements/events/onModxInit.php) #16767

@OlegAnTo2000

Description

@OlegAnTo2000

Summary
At the moment, all plugins triggered by events must be registered through the site manager. When working with file-based elements under Git, this adds certain limitations — for example, I need to manually create the same basic plugins in the manager on every site.

Why it is needed
It would be very useful to have a file-based event mechanism. For instance, if a file like elements/events/OnMODXInit.php exists, its code would automatically run when the corresponding event is fired. If the file does not exist, the event is simply skipped.

Suggested solution

  • Allow events to check for corresponding files under a configurable path (e.g. elements/events/{EventName}.php).
  • If the file exists, execute it.
  • If not, do nothing.

Benefits

  • Simplifies Git-based workflows.
  • Removes the need to re-create the same plugins in the manager across multiple environments.
  • Keeps project logic self-contained in files.

Example

// elements/events/OnMODXInit.php
<?php
$modx->log(modX::LOG_LEVEL_INFO, 'Custom bootstrap logic executed.');

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureRequest about implementing a brand new function or possibility.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions