pub trait LibraryTypeHandler:
Send
+ Sync
+ 'static {
Show 23 methods
// Required methods
fn app_label(&self) -> &'static str;
fn type_name(&self) -> &'static str;
fn verbose_name(&self) -> &'static str;
// Provided methods
fn extension_table(&self) -> Option<&'static str> { ... }
fn render_template(&self) -> Option<&'static str> { ... }
fn allows_element_template(&self) -> bool { ... }
fn list_display(&self) -> Vec<ListColumn> { ... }
fn search_fields(&self) -> Vec<&'static str> { ... }
fn list_filter(&self) -> Vec<&'static str> { ... }
fn render_cell(&self, _name: &str, _snippet: &Snippet) -> String { ... }
fn default_ordering(&self) -> Vec<(&'static str, OrderDir)> { ... }
fn bulk_actions(&self) -> Vec<BulkAction> { ... }
fn row_actions(&self) -> Vec<BulkAction> { ... }
fn list_row_template(&self) -> Option<&'static str> { ... }
fn edit_template(&self) -> Option<&'static str> { ... }
fn revisions_enabled(&self) -> bool { ... }
fn preview_enabled(&self) -> bool { ... }
fn can_view(&self, _snippet: &Snippet) -> bool { ... }
fn can_edit(&self, _snippet: &Snippet) -> bool { ... }
fn can_delete(&self, _snippet: &Snippet) -> bool { ... }
fn validate(
&self,
_form: &HashMap<String, String>,
) -> Result<(), Vec<(String, String)>> { ... }
fn menu_picker_entries<'life0, 'life1, 'async_trait>(
&'life0 self,
_pool: &'life1 Pool,
) -> Pin<Box<dyn Future<Output = Result<Vec<MenuPickerEntry>, ExecError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn handle_bulk_action<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
_pool: &'life1 Pool,
action: &'life2 str,
_ids: &'life3 [i64],
) -> Pin<Box<dyn Future<Output = Result<usize, ExecError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait { ... }
}Expand description
Trait every library type implements. Mirrors
crate::PageTypeHandler — same registration story, same
per-tenant seeding pass.
Required Methods§
Sourcefn verbose_name(&self) -> &'static str
fn verbose_name(&self) -> &'static str
Human-readable name for the admin sidebar.
Provided Methods§
Sourcefn extension_table(&self) -> Option<&'static str>
fn extension_table(&self) -> Option<&'static str>
SQL table where the typed extension data lives, or None for
a metadata-only registration (rare; useful for “Author” rows
that just hold name + bio in cms_library_type itself).
Sourcefn render_template(&self) -> Option<&'static str>
fn render_template(&self) -> Option<&'static str>
Optional Tera template for this type’s rows on public pages.
When Some("<path>"), {{ snippet_html(type="Category", id=4) }}
renders that row through it, with { snippet: <row JSON> } in
context. Only the rows a page asks for are fetched and rendered,
once each however often the page references them.
None (default) — snippet has no public-side surface; the
only consumers are admin / API.
Sourcefn allows_element_template(&self) -> bool
fn allows_element_template(&self) -> bool
Whether an individual element of this type may name its own
template, overriding Self::render_template for that row
alone. The name is read from the element’s data.template.
false (default) — every row of the type renders through the
one template the handler declares, which is what a “Category”
or “Author” wants: uniform presentation is the point.
true — the element is the presentation. A reporting widget
that carries its own query and its own markup, a campaign
banner an editor restyles per placement: these differ per row
by design, and a type-wide template would just be a dispatch
table keyed on the row.
Opt-in rather than always-on so a stray template key in a
row’s data can’t silently repoint an existing type’s render.
Types that opt in render through snippet_html even when
Self::render_template is None — an element template alone
is enough. Rows that name nothing and have no type default
render empty.
Sourcefn list_display(&self) -> Vec<ListColumn>
fn list_display(&self) -> Vec<ListColumn>
Columns rendered in this type’s list view. Defaults to the title + slug + updated_at trio when not overridden.
Sourcefn search_fields(&self) -> Vec<&'static str>
fn search_fields(&self) -> Vec<&'static str>
Fields the search bar matches against. Defaults to
["title", "slug"]; case-insensitive ILIKE '%q%'.
Sourcefn list_filter(&self) -> Vec<&'static str>
fn list_filter(&self) -> Vec<&'static str>
data.<key> keys exposed as filter dropdowns. The admin
reads distinct values + counts per key and renders one chip
per option. Defaults to no filters.
Sourcefn render_cell(&self, _name: &str, _snippet: &Snippet) -> String
fn render_cell(&self, _name: &str, _snippet: &Snippet) -> String
Render a method-field cell. Called for every
ListColumn::Method and ListColumn::Computed entry.
Return pre-escaped HTML — the admin emits it via Tera’s
| safe. The default empty implementation is fine when a
handler declares no method / computed columns.
Sourcefn default_ordering(&self) -> Vec<(&'static str, OrderDir)>
fn default_ordering(&self) -> Vec<(&'static str, OrderDir)>
Default ordering for the list view — applied in order. The
admin’s ?ordering= query param overrides this. Defaults to
“most-recently-updated first” so freshly-edited rows surface
at the top without authors needing to think about ordering.
Sourcefn bulk_actions(&self) -> Vec<BulkAction>
fn bulk_actions(&self) -> Vec<BulkAction>
Bulk actions exposed above the list table. Each entry adds
a labeled button next to a “Select all” checkbox; the
multi-select checkbox column is auto-mounted when this returns
any entry. Implementations that declare bulk actions MUST
override Self::handle_bulk_action — the default panics.
Sourcefn row_actions(&self) -> Vec<BulkAction>
fn row_actions(&self) -> Vec<BulkAction>
Per-row action chips overriding the built-in Edit / Delete
pair when set. Each BulkAction becomes a small inline
button; the name is sent as the form action via a fetch
POST /cms-admin/library/{type}/row-action/{id}?action=<name>.
Defaults to empty (built-in chips render).
Sourcefn list_row_template(&self) -> Option<&'static str>
fn list_row_template(&self) -> Option<&'static str>
Override the per-row HTML template. Defaults to None — the
admin renders rows via the built-in column loop. Setting this
gives full control of the row markup; the template receives
row (the snippet + computed cells) and columns
(list_display metadata) in scope.
Sourcefn edit_template(&self) -> Option<&'static str>
fn edit_template(&self) -> Option<&'static str>
Override the edit-form template body. Defaults to None —
the admin renders the default linear field stack. Setting
this gives full control of the form layout; the template
runs inside the page-edit <form> element so inputs submit
alongside the canonical save.
Sourcefn revisions_enabled(&self) -> bool
fn revisions_enabled(&self) -> bool
Opt this library type in to versioned snapshots.
When true, every successful save on a
snippet of this type also captures a crate::snippet::SnippetRevision
row, and the editor surfaces a History card with revert.
Defaults to false — fixed-shape snippet types keep the
existing zero-overhead lifecycle.
Sourcefn preview_enabled(&self) -> bool
fn preview_enabled(&self) -> bool
Opt this library type in to preview-on-save.
When true, the editor surfaces an
"Open preview" action that renders the unsaved form state.
Defaults to false. Hosts that want preview implement their
own preview route + override this.
Sourcefn can_view(&self, _snippet: &Snippet) -> bool
fn can_view(&self, _snippet: &Snippet) -> bool
Permission hook — return false to hide a row from the list
view + reject direct GET access to its edit page. The default grants
every row (true). Hosts wire role-aware logic by overriding.
Sourcefn can_edit(&self, _snippet: &Snippet) -> bool
fn can_edit(&self, _snippet: &Snippet) -> bool
Permission hook — return false to disable the Edit chip +
reject POST edits on the row. The default grants every row (true).
Sourcefn can_delete(&self, _snippet: &Snippet) -> bool
fn can_delete(&self, _snippet: &Snippet) -> bool
Permission hook — return false to hide the Delete chip +
reject DELETE on the row. The default grants every row (true).
Sourcefn validate(
&self,
_form: &HashMap<String, String>,
) -> Result<(), Vec<(String, String)>>
fn validate( &self, _form: &HashMap<String, String>, ) -> Result<(), Vec<(String, String)>>
Cross-field validation hook. Called BEFORE save with the
form payload as a key/value map. Return Err with one or
more field-scoped error messages to fail the save and render
them inline. Defaults to “always ok”.
Opt-in hook for the WP-style menu builder. Return a
list of MenuPickerEntry values to surface this library
type’s snippets in the Library picker tab on the menu
edit screen. Each entry contributes a draggable picker card
that drops into the menu as an external-URL MenuItem.
Default: empty — most library types (authors, callouts, blocks) don’t have a single canonical URL and shouldn’t show up in the menu picker. Override on types whose snippets represent linkable resources (e.g. external partner sites, downloadable docs, microsite shortcuts).
§Errors
Driver errors from the snippet fetch when an implementation
queries the pool. The default returns Ok(Vec::new()) so
implementors only opt-in when they have real data to surface.
Sourcefn handle_bulk_action<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
_pool: &'life1 Pool,
action: &'life2 str,
_ids: &'life3 [i64],
) -> Pin<Box<dyn Future<Output = Result<usize, ExecError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn handle_bulk_action<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
_pool: &'life1 Pool,
action: &'life2 str,
_ids: &'life3 [i64],
) -> Pin<Box<dyn Future<Output = Result<usize, ExecError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Async bulk-action dispatcher. Called when the list view
submits a bulk action. Returns the number of rows touched.
Default panics — handlers that declare Self::bulk_actions
MUST override this.
§Errors
Driver errors from the underlying ORM calls.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".