Skip to content

Handlers ​

The MODX events the package subscribes to, and what the framework does on each. Your own class with the same name runs after the framework one — see Events.

Request lifecycle ​

EventWhat the framework does
OnMODXInitNothing yet. Registered with priority: 1000 so the component boots before other plugins that may depend on it.
OnHandleRequestAliases modUser and modUserProfile to their MODX\Revolution\ counterparts, starts the session, mints the CSRF token if the session has none, switches the locale when the URI carries a language prefix, and hands the request to routing. Skips asset extensions (.css, .js, images, fonts) and, with pageblocks_routing = off, everything outside mgr/.
OnWebPageInitFront-end setup for the requested page: sends the security headers, registers the style layer through regClientCSS (unless pageblocks_load_styles is off), adds the reCAPTCHA script when a public key is filled in, and — unless pageblocks_load_scripts is off — the web scripts plus their configuration.
OnCacheUpdateClears the route cache, the Fenom view cache, the component cache and the menu cache, and drops $_SESSION['pageblocks']. Runs whenever MODX clears its cache.

The one case where the style layer needs a tag in the template

Because OnWebPageInit registers the block styles itself, an ordinary MODX page needs nothing from you — no {pb_styles()}, no manual <link>. But a page rendered by the component's own router never reaches that event: OnHandleRequest sends the response and returns first. In that template, and only there, put {pb_styles()} in the <head>.

Clearing the MODX cache clears ours

OnCacheUpdate means the manager's "Clear cache" button already covers PageBlocks — routes, compiled templates and cached lists. You rarely need to clear anything by hand.

Resource form ​

EventWhat the framework does
OnDocFormPrerenderOn an existing resource, loads the component's manager scripts. Skipped in new mode.
OnDocFormRenderRenders the resource's section fields into the form. Skipped in new mode.
OnBeforeDocFormSaveCollects the section field values from the submitted form and writes them into the resource.
OnResourceDuplicateCopies the resource's PageBlocks content to the copy: blocks, their nested tables and galleries, and rows attached to the resource's section fields. Custom field values ride along inside properties, which MODX copies itself.

User form ​

EventWhat the framework does
OnUserFormPrerenderLoads manager scripts for an existing user. Skipped in new mode.
OnUserFormRenderRenders the user's section fields into the form.
OnUserSaveWrites custom user fields into modx_user_attributes.extended. Runs after the core processor on purpose — otherwise the processor would overwrite extended.
OnUserDuplicateThe user counterpart of OnResourceDuplicate. Accepts several spellings of the processor's parameters, because they differ between MODX builds.
OnUserRemoveNo framework handler. Registered so a site can hook it from core/App/Events/OnUserRemove.php.

Manager ​

EventWhat the framework does
OnManagerPageBeforeRenderLoads the base scripts, the data scripts and the rich text editor on every manager page.
OnSiteSettingsRenderAdds modx.combo.js to the system settings page.

Where the code is ​

Framework handlers live in core/components/pageblocks/src/Events/, one file per event. They are short and readable — when this page is not enough, the class itself usually is.

© PageBlocks 2019-present