EventLoader by ukyo (@trk)

Event Loader module module allow you to load events from event files

EventLoader Module for ProcessWire CMS/CMF

EventLoader module allow you to load events from a event files.

Requirements


  • ProcessWire 3.0 or newer
  • PHP 7.0 or newer

Installation


Install the module from the modules directory:

Via Composer:

composer require trk/processwire-event-loader

Via git clone:

cd your-processwire-project-folder/
cd site/modules/
git clone https://github.com/trk/EventLoader.git
  • Module will check below folders for events:
/site/templates/events
/site/templates/configs/events
/site/modules/*/events
/site/modules/*/configs/events
  • Loading events from site/ready.php file
<?php namespace ProcessWire;

if(!defined("PROCESSWIRE")) die();

EventLoader::load(__DIR__ . '/templates', 'ready.');
  • Event file: site/templates/configs/events/ready.hello-world.php
<?php

namespace ProcessWire;

class HelloController
{
    public function greeting()
    {
        echo 'Hello World !';
        exit;
    }
}

return [
    // 'run' => true, // Also you can pass run option for this file
    'events' => [

        '/hello-world' => [HelloController::class, 'greeting'],

        'Page::private' => [
            'run' => wire()->user->isLoggedin()
            'type' => 'method',
            'fn' => function (HookEvent $e) {
                $e->return = 'This will run, if user logged in';
            }
        ],

        'Page::hello' => [
            'type' => 'method',
            'fn' => function (HookEvent $e) {
                $message = is_string($e->arguments(0)) ? $e->arguments(0) : '';
                $e->return = $message;
            }
        ]

    ]
];
  • Usage
<?php
echo $page->hello('World');

Install and use modules at your own risk. Always have a site and database backup before installing new modules.

Latest news

  • ProcessWire Weekly #520
    In the 520th issue of ProcessWire Weekly we'll check out some of the latest additions to the ProcessWire module's directory, share some highlights from the latest weekly update from Ryan, and more. Read on!
    Weekly.pw / 27 April 2024
  • ProFields Table Field with Actions support
    This week we have some updates for the ProFields table field (FieldtypeTable). These updates are primarily focused on adding new tools for the editor to facilitate input and management of content in a table field.
    Blog / 12 April 2024
  • Subscribe to weekly ProcessWire news

“We were really happy to build our new portfolio website on ProcessWire! We wanted something that gave us plenty of control on the back-end, without any bloat on the front end - just a nice, easy to access API for all our content that left us free to design and build however we liked.” —Castus, web design agency in Sheffield, UK