Skip to main content

Module hooks

Module hooks 

Source
Expand description

Runtime extension-point registry.

Hooks are typed: each hook has a precise signature, and registration is compile-time via inventory::submit! rather than runtime HashMap<&str, Box<dyn Fn>>. Plugins crate-side submit! a handler; CMS-side call sites collect every registered handler and fan out.

§Available hooks

The v1 surface is intentionally narrow — the 6 hooks below cover the common plugin use cases. More can land as customers ask.

HookWhenSignature
AfterPublishPageAfter page_edit_submit saves a Published rowfn(&Page)
BeforeServePageJust before the public renderer firesfn(&Page, &HeaderMap) -> Option<Response>
AdminMenuItemRegisters a sidebar entrystatic struct
PageActionMenuItemRegisters a kebab-menu entry on the page editorstatic struct
PageListingButtonRegisters a per-row action on the page treestatic struct
AdminSearchAreaRegisters an extra source for global searchstatic fn returning hits

§Registering

ⓘ
use rustango_cms::hooks::{register_after_publish_page, AfterPublishPage};
use rustango_cms::Page;

fn warm_cdn_cache(page: &Page) {
    tracing::info!("warming CDN for {}", page.url_path);
}

register_after_publish_page!(warm_cdn_cache);

§Failure semantics

Hooks fire in registration order. A panicking hook does NOT abort the request — the call site catches the panic, logs it, and continues to the next handler. The only exception is BeforeServePage, which can return Some(Response) to short-circuit the renderer.

Structs§

AccountSettingsPanel
One panel contributed to the per-user /cms-admin/me page. Pre-rendered HTML the template emits via | safe — hosts wire their own POST endpoints (the registry stays read-only).
AdminCss
A blob of CSS injected into every admin page’s <head>. The string is emitted verbatim inside a <style> tag (host-trusted), so plugins can restyle the chrome, hide elements, or theme their own admin pages without shipping a separate stylesheet route.
AdminJs
A blob of JS injected just before </body> on every admin page. Emitted verbatim inside a <script> tag (host-trusted).
AdminMenuItem
One sidebar entry contributed by a plugin. Renders below the built-in Settings section. The icon name is a Material-symbols glyph (e.g. "analytics", "chat", "science").
AdminSearchArea
Plugin-contributed search source for /cms-admin/search. Receives the query string; returns up to N hits to merge into the global search response.
AdminSearchHit
One hit row from a plugin-contributed search source.
AfterPublishPage
Fired after a page transitions to (or stays in) Published following page_edit_submit. Use for fire-and-forget side effects: warm a CDN, ping a webhook, push to a feed indexer.
BeforeServePage
Fired in the public router just after resolve_path returns a page and before the renderer fires. Return Some(Response) to short-circuit (redirect, 403, custom render, etc.); None to let the normal renderer handle it.
BulkActionSpec
Plugin-contributed bulk action declaration.
DashboardWidget
One widget contributed to /cms-admin/dashboard. Pre-rendered HTML; hosts compose whatever data shape they like (charts, counts, recent rows, etc.) and emit the fragment.
HelpMenuItem
One sidebar entry rendered under a dedicated “Help” section. Same field shape as AdminMenuItem — kept distinct so plugins can contribute docs / shortcuts links without polluting the generic plugin section.
PageActionMenuItem
One kebab-menu entry on the page editor (next to the existing “View live” / “Open preview” / “Form fields” entries).
PageHeaderButton
One button rendered alongside Save / Publish on the page editor header. Differs from PageActionMenuItem — that lives inside the kebab dropdown; this is a top-level button always visible.
PageListingButton
One per-row action on the page tree (next to “Edit” / “+ Child” / “Clone” / “Delete”).
UserbarItem
Plugin-contributed entry in the on-site editor userbar. href_template may include {page_id} — the renderer substitutes the live page id (or empty string when no page context).

Functions§

account_settings_panels
admin_css
Every registered global admin CSS blob, in registration order.
admin_js
Every registered global admin JS blob, in registration order.
admin_menu_items
Collect every registered AdminMenuItem for the sidebar templates. Stable ordering by key.
bulk_actions_for
Every plugin-contributed bulk action whose resource matches resource. Stable ordering by key.
dashboard_widgets
fire_after_publish_page
Fan out: call every registered AfterPublishPage handler in registration order. Panics are caught + logged so one buggy plugin can’t break the publish path.
fire_before_serve_page
Fan out: returns the first short-circuit response or None.
help_menu_items
page_action_menu_items
Collect every registered PageActionMenuItem, with the page id interpolated into each entry’s href_template.
page_header_buttons
Resolve every registered header button against page_id, substituting {page_id} into each href.
page_listing_buttons
page_listing_buttons_raw
Collect raw page-listing buttons (no {page_id} substitution). Used by the page-list template which loops over rows and does the substitution per row inside Tera.
run_admin_search_areas
Run every registered AdminSearchArea against query and return a flattened (area_label, hits) list.
userbar_items