Skip to content

Use a modern way to centrally register events in your CraftCMS app

License

Notifications You must be signed in to change notification settings

panlatent/craft-event-register

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Event Register

Use a modern way to centrally register events in your CraftCMS app

Requirements

  • PHP 8.0.2 or later.

Installation

Then tell Composer to load the library

composer require panlatent/craft-event-register

Usages

Events Register

The Events Register provides a configuration with annotations to register event handlers in a unified way.

1 Add events.php to config directory. This configuration file supports 3 methods:

Function array:

<?php
return [
  #[RegisterComponentTypes(Elements::class, Elements::EVENT_REGISTER_ELEMENT_TYPES)]
  function(): array {
      return [YourElement::class];
  },
];

Class object

<?php
return new class {
  #[RegisterComponentTypes(Elements::class, Elements::EVENT_REGISTER_ELEMENT_TYPES)]
  public function registerElements(): array {
      return [YourElement::class];
  },
};  // or return new YourClass()

Class config by Yii::createObject() / Craft::createObject()

<?php
return ['class' => YourClass::class]
  1. Register event using annotations class demo

License

The project is open-sourced software licensed under the MIT license.

About

Use a modern way to centrally register events in your CraftCMS app

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages