CWA 2 is a prerelease (2.0.0-alpha), heading for a beta. It runs production sites; configuration can still change between releases, always with upgrade notes. View versions and support
Extending the CWA

Admin Pages

Adding an extension's pages under /_cwa with a role and a menu entry, and building a list and an item dialog from the admin's own parts.

An extension can add pages to the admin, such as a list of orders with a dialog for each one. They sit under /_cwa beside the built-in pages, in the same layout, behind the same sign-in check. This page adds an orders list and an order dialog, built from the parts the built-in lists use.

Registering an Admin Page

Each entry in adminPages is one page:

// cwa-shop/module.ts, in register({ … })
adminPages: [
  {
    path: 'shop-orders',    file: resolve('./admin/orders.vue'),    item: resolve('./admin/order.vue'),    menu: { label: 'Orders' },  },
  { path: 'shop-reports', file: resolve('./admin/reports.vue'), role: 'ROLE_SHOP_ACCOUNTS', menu: { label: 'Reports' } },
],
OptionRequiredWhat it does
pathYesThe path under /_cwa: shop-orders is /_cwa/shop-orders. It can have more than one segment
fileYesAn absolute path to the page's Vue file
itemNoAn absolute path to a dialog for one item, opened over the list at /_cwa/<path>/<iri>. See The Item Dialog
roleNoThe role a user needs to open the page. Default ROLE_ADMIN, which a content admin with only ROLE_CMS_ADMIN doesn't have
menuNo{ label } adds the page to the admin menu, under Extensions

Each page's route is named _cwa- followed by its path with / turned into -: shop-orders is _cwa-shop-orders, and its item dialog is _cwa-shop-orders-iri.

An admin path can't start with a built-in admin page's name.users, pages, layouts, routes, data, settings and orphaned are taken, so /_cwa/users/shop fails the build. Starting the path with the extension's own name, as shop-orders does, keeps clear of them and of other extensions.

Like every page under /_cwa, an extension's admin pages render only in the browser.

Who Can Open It

A signed-out visitor is sent to /login and back after signing in. A signed-in user without the page's role is sent to /. The menu entry is shown only to users with the role.

role must start with ROLE_ and can't be ROLE_USER, which every signed-in user has. A role the user reaches through the role hierarchy counts, because /me lists every role a user reaches. See Admin Roles › The Role Hierarchy.

A role other than ROLE_ADMIN appears in the admin's user dialog as a toggle, named after the menu labels of the pages that need it, so a user admin can grant it (see CWA Layer › Admin Panel › Admin Routes).

The role only decides who sees the page. The API decides what they can read and change, so secure the extension's resources in its Symfony bundle too.
Image placeholder: the admin menu with the Extensions heading and its Orders and Reports entries.

The List Page

<CwaAdminList> is the built-in lists' page: a heading, the search and sort row, the list with its loading, empty and error states, pages of 20, and the outlet the item dialog opens in. You give it the endpoint and render each row:

<!-- cwa-shop/admin/orders.vue -->
<template>
  <CwaAdminList
    title="Orders"
    fetch-url="/shop/orders"
    noun="orders"
    :columns="columns"
    :order-options="orderOptions"
    search-label="Search orders"
  >
    <template #item="{ data, link }">      <CwaAdminListRow :to="link" :title="data.number" :sub="data.customerEmail">        <CwaAdminListCell>
          <CwaUiBadge :tone="data.state === 'paid' ? 'success' : 'neutral'">
            {{ data.state }}
          </CwaUiBadge>
        </CwaAdminListCell>
        <CwaAdminListCell align="end">
          {{ data.total }}
        </CwaAdminListCell>
      </CwaAdminListRow>
    </template>
  </CwaAdminList>
</template>

<script setup lang="ts">
const columns = [
  { label: 'Order' },
  { label: 'State', width: '8rem' },
  { label: 'Total', width: '7rem', align: 'end' as const },
]
const orderOptions = [
  { label: 'Newest first', value: { createdAt: 'desc' } },
  { label: 'Highest total', value: { total: 'desc' } },
]

</script>

The extension names the routes for you: the list page is _cwa- plus its path (_cwa-shop-orders), and its item dialog is that name plus -iri. The list builds each row's link from them, and gives the item dialog its route key, so an extension's admin pages need no definePageMeta for routing.

PropRequiredWhat it does
titleYesThe page heading and the browser tab's title
fetch-urlYesThe collection endpoint to list
nounYesThe plural used in the count and the empty and error messages, such as "No orders match these filters."
columnsYesOne { label, width?, align?, labelHidden? } per column. The first takes the remaining width; align: 'end' lines up numbers on the right
order-optionsYesThe sort choices. Each value is sent as order[<field>]=<direction>; the first is the default
search-labelYesThe search field's label. What's typed is sent as search=
create-nounNoAdds a create button (and one on the empty list) that opens the item dialog at add. Leave it out for records that aren't created in the admin, such as orders

The list sends the page's query to fetch-url, so the API's collection needs filters for search, the order fields and anything else you add. The slots are:

SlotWhat goes in it
itemOne row, given data (the resource), rawData and link (the item dialog's route)
filtersMore filters beside the search, bound to the page's query
noticeA notice above the list
emptyWhat an empty list shows, in place of the create button

Filters

A filter is a field bound to the page's query with useQueryBoundModel. Every query parameter except page, perPage and order is sent to the API and counts as a filter, so the list offers to clear it when nothing matches:

<template #filters>
  <CwaUiMultiSelect
    v-model="states"
    label="State"
    label-hidden
    placeholder="Any state"
    search-placeholder="Search states"
    :options="stateOptions"
  />
</template>

<script setup lang="ts">
const stateOptions = ['awaiting_payment', 'paid', 'cancelled', 'refunded'].map(state => ({ label: state, value: state }))
const { model: stateModel } = useQueryBoundModel('state[]', { defaultValue: [] })
const states = computed({
  get: () => (stateModel.value ?? []) as string[],
  set: (value: string[]) => { stateModel.value = value },
})
</script>

Rows

ComponentProps
<CwaAdminListRow>title (required), to (the row's link, usually link), sub (a second line), dim. With actions, it shows an edit button, and a view button when view is set; name labels them. The default slot holds its <CwaAdminListCell>s
<CwaAdminListCell>One cell after the title. align="end" for numbers

The row's title takes the first column, so give columns one entry more than the row has cells.

Image placeholder: the orders list with its search, a State filter, the sort menu and rows showing an order number, the customer's email, a state badge and a total.

The Item Dialog

The item file opens over the list when a row is clicked, at /_cwa/shop-orders/<iri>. useCwaAdminItem loads the resource from the route, as the built-in dialogs do, and <CwaUiDialog> lays it out:

<!-- cwa-shop/admin/order.vue -->
<template>
  <CwaUiDialog
    v-if="localResourceData || isLoading || loadFailed"
    placement="right"
    :title="localResourceData?.number ?? 'Order'"
    :tabs="tabs"
    :loading="isLoading"
    :load-failed="loadFailed"
    noun="order"
    @close="$emit('close')"
    @retry="loadResource()"
  >
    <template #details>
      <CwaUiFormSection title="Order">
        <CwaUiDetailList :items="summary" />
      </CwaUiFormSection>
      <CwaUiFormSection title="Lines">
        <CwaUiDataTable label="Order lines" :columns="lineColumns" :rows="localResourceData?.lines ?? []" />
      </CwaUiFormSection>
      <CwaUiFormSection v-if="localResourceData?.state === 'paid'" title="Refund">
        <CwaUiButton label="Refund" tone="danger" :loading="actionRunning" @click="refund" />
      </CwaUiFormSection>
    </template>
    <template #info>
      <CwaAdminResourceId :iri="localResourceData?.['@id']" />
    </template>
  </CwaUiDialog>
</template>

<script setup lang="ts">
const emit = defineEmits<{ close: [], reload: [] }>()

const { localResourceData, isLoading, loadFailed, loadResource, runAction, actionRunning } = useCwaAdminItem({  createEndpoint: '/shop/orders',  emit,  resourceType: 'Order',  defaultResource: () => ({}),}) 
const tabs = [{ key: 'details', label: 'Details' }, { key: 'info', label: 'Info' }]
const lineColumns = [
  { key: 'title', label: 'Item' },
  { key: 'quantity', label: 'Qty', align: 'end' as const },
  { key: 'total', label: 'Total', align: 'end' as const },
]
const summary = computed(() => [
  { label: 'State', value: localResourceData.value?.state },
  { label: 'Email', value: localResourceData.value?.customerEmail },
  { label: 'Total', value: localResourceData.value?.total },
])

function refund() {
  const iri = localResourceData.value?.['@id']
  return iri && runAction({
    endpoint: `${iri}/refund`,
    confirm: { title: 'Refund this order?', go: 'Refund', tone: 'danger' },
    success: 'Order refunded',
  })
}
</script>

The dialog emits close to go back to the list and reload to refresh it. Each entry in tabs names a slot.

useCwaAdminItem

It takes the options of the built-in dialogs' item composable:

OptionRequiredWhat it does
createEndpointYesWhere a new item is posted, when the dialog is opened at add
emitYesThe dialog's emit, with close and reload
defaultResourceYesThe fields a new item starts with
resourceTypeNoThe resource's type

It returns the loaded resource and its state: localResourceData (the dialog's copy), resource (the stored one), isLoading, loadFailed, loadResource() to load it again, saveResource() and deleteResource() for an editable item, plus runAction and actionRunning.

Running an Action

An action is a request that does something to the item, such as a refund. runAction() sends it, and only then reloads the item and the list:

FieldWhat it does
endpointWhere the request goes
methodPOST (default) or PATCH
bodyThe request body, if any
confirmAsk first, with the admin's confirm dialog: title, go (the button), tone (danger or accent), and optionally description
successA notice shown when the request succeeds

It returns true when the request succeeded (an empty 204 counts), and false when the admin cancelled the confirm or the request failed. A failure shows no success notice and reloads nothing; the API's error appears as an error notice in the admin header, which stays until it's dismissed. The header shows only for content and user admins, so a user whose only admin role is the extension's own sees no notice. actionRunning is true while an action runs, and a second action started meanwhile is ignored, so bind it to the button's loading.

Image placeholder: the order dialog open on the right of the list, showing the order's details, its lines table and the Refund button, with the confirm dialog asking "Refund this order?".

Read-Only Details and Tables

Two kit components show data an admin reads but doesn't edit:

<CwaUiDetailList> shows labelled values, in two columns where there's room. items is a list of { label, value }; an empty value shows a dash, read as "Not set". The value slot, given item and index, formats a value.

<CwaUiDataTable> shows rows of data. columns is a list of { key, label, align? }, rows a list of objects read by each column's key, and label names the table for screen readers. empty is what it says with no rows (default "None"). A wide table scrolls sideways inside the dialog. The cell slot, given row, column and value, formats a cell:

<CwaUiDataTable label="Order lines" :columns="lineColumns" :rows="lines">
  <template #cell="{ column, value }">
    {{ column.key === 'total' ? formatMoney(value) : value }}
  </template>
</CwaUiDataTable>

<CwaAdminResourceId :iri> shows a resource's ID with a Copy ID button, as on the built-in Info tabs.

The other kit components (<CwaUiDialog>, <CwaUiFormSection>, <CwaUiButton>, <CwaUiBadge> and the fields) are listed in The CWA Layer › Reusable UI Components.

Next: Sign-In and Sign-Out Events.