Skip to the content
Documentation
Help Start
Reading in:
  • German: 9,113 of 9,113 pages
About the help in other languages
All help pages

Events, listeners and filters

React to the kernel without changing it: ezpEvent, [Event] Listeners[], notify versus filter events, the events the kernel announces, and the rule that a filter returns its value.

Download as PDF

Address: https://doc.exponential.earth/exphelp/viewer/help/extension-development/part-3-extension-developer/events-and-filters.md

On this page

Events, listeners and filters

Part 3, chapter 28. The lightest way to change system behavior is to listen to an event the kernel announces. Nothing is replaced, nothing is overridden; your function is simply called. This chapter explains the event system, ezpEvent (kernel/private/classes/ezpevent.php), and lists the events you can use.

Two kinds

KindKernel callsYour listener
notifyezpEvent::getInstance()->notify( $name, $params )is called with the parameters; its return value is ignored
filterezpEvent::getInstance()->filter( $name, $value, ... )receives the value (and extra arguments), must return it, changed or not

A filter listener that forgets to return the value destroys it: the page, the cache keys, the list of functions. This is the one rule to remember.

Attaching a listener

In your extension's settings/site.ini.append.php:

<?php /* #?ini charset="utf-8"?

[Event]
Listeners[]=content/state/assign@mysiteHelloListeners::stateAssigned
Listeners[]=response/output@mysiteHelloListeners::output

*/ ?>

The form is <event>@<callback>, the callback a function or Class::method. A malformed entry, an unknown callback, or the same entry twice is skipped or attached once, with a note in the log (ezpEvent::registerEventListeners()). [Event] Listeners[] is attached for web requests; the runnables' events below are attached everywhere.

The listener class

<?php
/**
 * Event listeners of mysite_hello, attached in settings/site.ini.append.php:
 *   [Event]
 *   Listeners[]=content/state/assign@mysiteHelloListeners::stateAssigned
 *   Listeners[]=response/output@mysiteHelloListeners::output
 */
class mysiteHelloListeners
{
    /** notify: called with ( $objectID, $selectedStateIDList ) after object states were assigned */
    public static function stateAssigned( $objectID, $stateIDList )
    {
        eZLog::write( sprintf( 'Object %d got states %s', (int)$objectID, implode( ',', array_map( 'intval', (array)$stateIDList ) ) ),
                      'mysite_hello.log' );
    }

    /** filter: receives the page and MUST return it (changed or not) */
    public static function output( $html )
    {
        if ( !is_string( $html ) )
            return $html;
        return str_replace( '</body>', "<!-- served with mysite_hello -->\n</body>", $html );
    }
}

Attached to a fresh ezpEvent instance with the kernel loaded, filter( 'response/output', '<html><body>x</body></html>' ) returned the page with the comment inserted, and notify() of an event nobody listens to returned false.

The kernel's events

Found in the kernel's code with grep -rn "getInstance()->notify\|getInstance()->filter" kernel lib:

EventKindParameters / value
request/preinput, request/inputnotifythe request, early
response/preoutput, response/outputfilterthe output before it is sent
content/viewfilterthe result of a content view
content/view/cachekeysfilterthe keys of the view cache (add a key, for example per user group)
content/cache, content/cache/version, content/cache/allnotifycaches of nodes and objects were cleared: ( $nodeList, $contentObjectList )
content/class/cache, content/section/cache, content/state/cache, content/translations/cache, user/cache/allnotifyother caches cleared
content/state/assignnotify( $objectID, $selectedStateIDList )
content/download/access, content/edit/access, collaboration/item/accessfiltera say in access decisions
content/notification/createfilterwhether a notification is created
module/functionlistfilterthe policy functions of a module (content limitations of extensions use it)
image/aliasnotifyan image alias was created
session/regenerate, session/destroy, session/gc, session/cleanupnotifysession life cycle
httpcache/store/headersfilterheaders stored with an HTTP cache entry

The access filters and view cache keys are documented in Access and view cache filters, content limitations in Content policy limitations of extensions.

Events of commands, cronjobs and views

Runnables announce runnable/<kind>/before (notify, with $runnable, $class, $scope) and runnable/<kind>/after (filter of the result), <kind> being command, cronjob or view, and runcronjobs.php asks the filter cronjob/part/run before a part runs (Leaving out a cronjob part). They are registered in site.ini [RunnableSettings] Listeners[], which also allows replacing a runnable class with Implementation[<class>]=<subclass>.

Announcing your own events

Your extension can let others extend it the same way:

<?php
$items = ezpEvent::getInstance()->filter( 'mysite_hello/greetings', $items );
ezpEvent::getInstance()->notify( 'mysite_hello/greeted', array( $name ) );

Name your events after your extension, and document their parameters.

Rules

  • Keep listeners fast: response/output runs on every page.
  • Return the value from every filter, on every path.
  • Do not throw from a listener; log and continue.
  • Under a persistent server (Velocity), never attach listeners in code that runs per request without checking: they would accumulate. Settings-based listeners are attached once.

Become an Exponential Partner

Partners share their information, provide funding, contribute back and develop the products with us, and that is how Exponential grows. A partner website and dashboard are planned for mid-2027: please become a partner today to speed up our growth rate and land new features faster.

Something wrong on this page? Report an error

Documentation license

This documentation is free documentation, licensed under the GNU Free Documentation License 1.3 or later.

Exponential Copyright © 1998-2026 Exponential Foundation and 7x