Skip to main content

Module cms_admin

Module cms_admin 

Source
Expand description

A generic admin editor for a host app’s own models.

#[derive(CmsAdmin)] on a #[derive(Model)] type implements CmsAdmin from the struct’s #[cms_admin(...)] and #[field(...)] attributes and registers a CmsAdminPage for it. The page lives at /cms-admin/x/<slug> inside the admin chrome and gives editors:

  • a list with search, the chosen columns and pagination;
  • add and edit forms built from the #[field] widgets (every widget the page editor has, media and page choosers included);
  • delete, with a confirmation.

Access runs through the role matrix: the model gets a row with view, add, edit and delete columns (<resource>.view … .delete), and the dispatcher checks the matching codename on every request.

CmsAdminOverrides holds the hooks a real app needs: fields that cannot be edited, records that cannot be created or deleted, validation, side effects after a save or before a delete, options for a select, and extra widgets for relations the struct has no column for (a many-to-many list).

Structs§

CmsAdminMeta
Static description of one model’s editor, built by the derive.
CmsAdminPage
The admin page serving model T. #[derive(CmsAdmin)] registers it; register it by hand with register_admin_page!(CmsAdminPage<T>) only when implementing CmsAdmin yourself.
FieldError
A validation failure for one field, or for the whole form when field is "_form".

Traits§

CmsAdmin
What #[derive(CmsAdmin)] implements. Host code rarely calls these directly; CmsAdminPage does.
CmsAdminOverrides
Hooks for a model’s editor. Every method has a default, so impl CmsAdminOverrides for MyModel {} is enough to start.

Functions§

delete_record
Delete row after CmsAdminOverrides::can_delete and CmsAdminOverrides::before_delete. Ok(false) when can_delete refuses.
save_record
Apply a posted form to row and store it, running the hooks in order: CmsAdmin::admin_apply (skipping CmsAdminOverrides::read_only_fields), CmsAdminOverrides::validate, the save, CmsAdminOverrides::save_extra, then CmsAdminOverrides::after_save. A row without a primary key is added, and only when CmsAdminOverrides::can_create allows it.
section_from
Parse a section attribute value: content, site and settings are the built-in sections; anything else names a new one.