Extension registration

AEM UI extensions are specialized App Builder app, based on React and use the React Spectrum UI framework.

To define where and how the AEM UI extension appears, two configurations are required in the extension’s App Builder app: app routing and the extension registration.

App routes app-routes

The extension’s App.js declares the React router that includes an index route that registers the extension in the AEM UI.

The index route is invoked when the AEM UI initially loads, and target of this route defines how the extension is exposed in the console.

  • ./src/aem-ui-extension/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>
  )
  ...
}

Extension registration

ExtensionRegistration.js must be immediately loaded via the index route of the extension, and acts the registration point of the extension.

Based on the AEM UI extension template selected when initializing the App Builder app extension, different extension points are supported.

Conditionally include extensions

AEM UI extensions can execute custom logic to limit the AEM environments the extension appears in. 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 AEM host that the extension is loading on.
  • The current user’s AEM access token.

The most common checks for loading an extension are:

  • Using the AEM host (new URLSearchParams(window.location.search).get('repo')) to determine if the extension should load.

    • Only show the extension on AEM environments that are part of a specific program (as shown in the example below).
    • Only show the extension on a specific AEM environment (AEM host).
  • Using an Adobe I/O Runtime action to make an HTTP call to AEM to determine if the current user should see the extension.

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);
}
recommendation-more-help
4859a77c-7971-4ac9-8f5c-4260823c6f69