Page Data Tabs and Lists
An extension can add to the admin's page data screens as well as its own pages. A shop that adds product variants to page data can give the page data dialog a Formats and prices tab, and give its own area a Products list of the page data that has variants.
Both are matched to page data types by a property, never by the type's name: a tab or list applies to every page data type whose API documentation lists the property named in forTypesWithProperty. The site decides which types have it, so the extension works with any of them.
// cwa-shop/module.ts, in register({ … })
pageDataTabs: [
{ key: 'formats', label: 'Formats and prices', file: resolve('./admin/formats.vue'), forTypesWithProperty: 'variants' },],
pageDataLists: [
{
path: 'products', label: 'Products', forTypesWithProperty: 'variants', columns: [{ label: 'From', file: resolve('./admin/from-price.vue') }],
},
],
A Tab in the Page Data Dialog
| Option | Required | What it does |
|---|---|---|
key | Yes | The tab's key, and its hash: #formats opens the dialog on this tab |
label | Yes | The tab's name |
file | Yes | An absolute path to the tab's Vue file |
forTypesWithProperty | Yes | The API property a page data type must have for the tab to show |
role | No | The role a user needs to see the tab. Default ROLE_CMS_ADMIN, the role that opens the page data dialog |
The tab sits after Details and before Routes, in the order the extensions declare their tabs. It isn't shown while a new record is being added, because there's nothing saved for it to work on yet.
The tab's component gets two props: iri, the page data record's IRI, and data, the record as loaded. It saves through the API itself, for example with useCwaAdminItem or its own requests. Its saves are separate from the dialog's: they don't count towards Save, and leaving the tab unsaved doesn't mark the dialog as unsaved.
<!-- cwa-shop/admin/formats.vue -->
<script setup lang="ts">
const props = defineProps<{ iri: string, data: Record<string, any> }>()
</script>
details, routes or info, the built-in tabs' keys, and two extensions can't use the same key. Either one fails the build.Hiding a Tab for One Type
A site that doesn't want the tab on one of its types turns it off in that type's pageData config:
// app/nuxt.config.ts
cwa: {
pageData: {
BookPageData: { hideExtensionTabs: ['formats'] }, },
},
See Nuxt Config › Full cwa: Reference.
A List of Page Data in the Extension's Area
| Option | Required | What it does |
|---|---|---|
path | Yes | The list's path in the extension's area: products is /_cwa/shop/products |
label | Yes | The list's tab in the area |
forTypesWithProperty | Yes | The API property a page data type must have to be listed |
role | No | The role a user needs to open the list. Default ROLE_ADMIN, as for admin pages |
columns | No | Extra columns after Title, each { label, file } |
A list is a tab of the extension's area, after its admin pages (see Admin Pages › The Extension's Area). It shows one page data type at a time:
/_cwa/shop/productslists the types that have the property. When only one type has it, it goes straight to that type's list./_cwa/shop/products/<type>lists that type's records, with search and sorting by date or title.<type>is the class's short name with a lower-case first letter, such asbookPageData.- A row opens the record's page data dialog over the list, at
/_cwa/shop/products/<type>/<iri>, with the extension's page data tabs in it.
The routes are named _cwa-shop-products, _cwa-shop-products-type and _cwa-shop-products-type-iri.
A column's component gets the row's record as its data prop:
<!-- cwa-shop/admin/from-price.vue -->
<template>
<span>{{ from }}</span>
</template>
<script setup lang="ts">
import { computed } from 'vue'
const props = defineProps<{ data: Record<string, any> }>()
const from = computed(() => Math.min(...(props.data.variants ?? []).map((variant: { price: number }) => variant.price)))
</script>
When the Build Fails
Besides the checks in Registering an Extension › When the Build Fails:
| Problem | Message |
|---|---|
| A tab with a built-in tab's key | @acme/cwa-shop's page-data tab "details" has the key of the built-in Details tab |
| Two extensions with one tab key | @acme/cwa-shop and @acme/store both have the page-data tab "formats" |
A tab without forTypesWithProperty | @acme/cwa-shop's page-data tab "formats" needs forTypesWithProperty, the API property a page data type must have to show it |
| A tab without a label | @acme/cwa-shop's page-data tab "formats" needs a label |
A list without forTypesWithProperty | @acme/cwa-shop's page-data list /_cwa/shop/products needs forTypesWithProperty, the API property a page data type must have to be listed |
| A list with an admin page's path | @acme/cwa-shop's page-data list /_cwa/shop/products has the path of its own admin page /_cwa/shop/products |
A tab or list role must start with ROLE_ and can't be ROLE_USER, as for admin pages.
Next: Sign-In and Sign-Out Events.
Admin Pages
Adding an extension's pages to its own area under /_cwa, with tabs, roles and links, and building a list and an item dialog, with fields from descriptors and secrets, from the admin's own parts.
Sign-In and Sign-Out Events
The cwa:auth:signed-in and cwa:auth:signed-out hooks, when each one is called, and what happens when a handler throws.