AEM Content Fragment Console extensions are specialized App Builder app, based on React and uses the React Spectrum UI framework.
To define where and how the AEM Content Fragment Console the extension appears, two specific configurations are required in the extension’s App Builder app: app routing and the extension registration.
The extension’s App.js
declares the React router that includes an index route that registers the extension in the AEM Content Fragment Console.
The index route is invoked when then AEM Content Fragment Console initially loads, and target of this route defines how the extension is exposed in the console.
./src/aem-cf-console-admin-1/web-src/src/components/App.js
import ExtensionRegistration from "./ExtensionRegistration"
...
function App(props) {
return (
<Router>
<ErrorBoundary onError={onError} FallbackComponent={fallbackComponent}>
<Routes>
{/* The index route maps to the extension registration */}
<Route index element={<ExtensionRegistration />} />
...
</Routes>
</ErrorBoundary>
</Router>
)
...
}
ExtensionRegistration.js
must be immediately loaded via the index route of the extension, and acts the registration point of the extension, defining:
headerMenu
property under methods
.actionBar
property under methods
.getButton()
function. This function returns an object with fields:
id
is a unique ID for the buttonlabel
is the extension button’s label in the AEM Content Fragment consoleicon
is the extension button’s icon in the AEM Content Fragment console. The icon is a React Spectrum icon name, with spaces removed.onClick()
function.
selections
parameter.The Header Menu extension buttons display when no Content Fragments are selected. Because Header Menu extensions do no act upon a Content Fragment selection, no Content Fragments are provided to its onClick()
handler.
./src/aem-cf-console-admin-1/web-src/src/components/ExtensionRegistration.js
function ExtensionRegistration() {
const init = async () => {
const guestConnection = await register({
id: extensionId, // A unique ID for the extension
methods: {
// Configure your Action Bar button here
headerMenu: {
getButton() {
return {
'id': 'example.my-header-menu-extension', // Unique ID for the button
'label': 'My header menu extension', // Button label
'icon': 'Edit' // Button icon from https://spectrum.adobe.com/page/icons/
}
},
// Click handler for the extension button
// Header Menu extensions do not pass parameters to the click handler
onClick() { ... }
}
}
})
}
init().catch(console.error)
}
Skip to building a header menu extension
Learn how to register and define a header menu extension in the AEM Content Fragments Console.
Action Bar extension buttons display when one or more Content Fragments are selected. The selected Content Fragment’s paths are made available to the extension via the selections
parameter, in the button’s onClick(..)
handler.
./src/aem-cf-console-admin-1/web-src/src/components/ExtensionRegistration.js
function ExtensionRegistration() {
const init = async () => {
const guestConnection = await register({
id: extensionId, // A unique ID for the extension
methods: {
// Configure your Action Bar button here
actionBar: {
getButton() {
return {
'id': 'example.my-action-bar-extension', // Unique ID for the button
'label': 'My action bar extension', // Button label
'icon': 'Edit' // Button icon from https://spectrum.adobe.com/page/icons/
}
},
// Click handler for the extension button
// Only Action Bar buttons populate the selections parameter
onClick(selections) { ... }
}
}
})
}
init().catch(console.error)
}
Skip to building an action bar extension
Learn how to register and define an action bar extension in the AEM Content Fragments Console.
AEM Content Fragment Console extensions can execute custom logic to limit when the extension appears in the AEM Content Fragment Console. This check is performed before the register
call in the ExtensionRegistration
component, and immediately returns if the extension should not be displayed.
This check has limited context available:
The most common checks for loading an extension are:
new URLSearchParams(window.location.search).get('repo')
) to determine if the extension should load.
The example below illustrates limiting the extension to all environments in program p12345
.
./src/aem-cf-console-admin-1/web-src/src/components/ExtensionRegistration.js
function ExtensionRegistration() {
const PROGRAM_ID = 'p12345';
// Get the current AEM Host (author-pXXX-eYYY.adobeaemcloud.com) the extension is loading on
const aemHost = new URLSearchParams(window.location.search).get('repo');
// Create a check to determine if the current AEM host matches the AEM program that uses this extension
const aemHostRegex = new RegExp(`^author-${PROGRAM_ID}-e[\\d]+\\.adobeaemcloud\\.com$`)
// Disable the extension if the Cloud Manager Program Id doesn't match the regex.
if (!aemHostRegex.test(aemHost)) {
return; // Skip extension registration if the environment is not in program p12345.
}
// Else, continue initializing the extension
const init = async () => { .. };
init().catch(console.error);
}