Feature: #96733 - New backend module registration API
See forge#96733
Description
The registration and usage of backend modules was previously based
on the global array $TBE_
. This however had a couple
of drawbacks, e.g. module registration could be changed at runtime,
which had been resolved by introducing a new registration API.
Therefore, instead of using the Extension
and Extension
(Extbase) API methods in
ext_
files, the configuration is now placed in the
dedicated Configuration/
configuration file.
Those files are then read and processed when building the container. This means the state is fixed and can't be changed at runtime. This approach follows the general Core strategy (see e.g. Icons.php), since it highly improves the loading speed of every request as the registration can be handled at once and cached during warmup of the Core caches. Besides caching, this will also allow additional features in the future, which were blocked due to the loose state.
Previous configuration in ext_
:
ExtensionManagementUtility::addModule(
'web',
'example',
'top',
'',
[
'routeTarget' => MyExampleModuleController::class . '::handleRequest',
'name' => 'web_example',
'access' => 'admin',
'workspaces' => 'online',
'iconIdentifier' => 'module-example',
'labels' => 'LLL:EXT:example/Resources/Private/Language/locallang_mod.xlf',
'navigationComponentId' => 'TYPO3/CMS/Backend/PageTree/PageTreeElement',
]
);
ExtensionUtility::registerModule(
'Extkey',
'web',
'example',
'after:info',
[
MyExtbaseExampleModuleController::class => 'list, detail',
],
[
'access' => 'admin',
'workspaces' => 'online',
'iconIdentifier' => 'module-example',
'labels' => 'LLL:EXT:extkey/Resources/Private/Language/locallang_mod.xlf',
'navigationComponentId' => 'TYPO3/CMS/Backend/PageTree/PageTreeElement',
]
);
Will now be registered in Configuration/
:
return [
'web_module' => [
'parent' => 'web',
'position' => ['before' => '*'],
'access' => 'admin',
'workspaces' => 'live',
'path' => '/module/web/example',
'iconIdentifier' => 'module-example',
'navigationComponent' => 'TYPO3/CMS/Backend/PageTree/PageTreeElement',
'labels' => 'LLL:EXT:example/Resources/Private/Language/locallang_mod.xlf',
'routes' => [
'_default' => [
'target' => MyExampleModuleController::class . '::handleRequest',
],
],
],
'web_ExtkeyExample' => [
'parent' => 'web',
'position' => ['after' => 'web_info'],
'access' => 'admin',
'workspaces' => 'live',
'iconIdentifier' => 'module-example',
'path' => '/module/web/ExtkeyExample',
'labels' => 'LLL:EXT:beuser/Resources/Private/Language/locallang_mod.xlf',
'extensionName' => 'Extkey',
'controllerActions' => [
MyExtbaseExampleModuleController::class => [
'list',
'detail'
],
],
],
];
Note
Each modules array key is used as the module identifier, which
will also be the route identifier. It's no longer necessary to
use the main
pattern, since a possible parent
will be defined with the parent
option.
Module configuration options
Option | Description |
---|---|
parent (string ) | If the module should be a submodule, the parent identifier, e.g.
web has to be set here. |
path (string ) | Define the path to the default endpoint. The path can be
anything, but will fallback to the known
/module/<main pattern, if not set. |
standalone (bool ) | Whether the module is a standalone module (parent without submodules). |
access (string ) | Can be user (editor permissions), admin , or
system . |
workspaces (string ) | Can be * (= always), live or offline . If not set, the
value of the parent module - if any - is used. |
position (array ) | The module position. Allowed values are before => <identifier>
and after => <identifier> . To define modules on top or at the
bottom, before => * and after => * can be used. Using the
top and bottom values (without key) is deprecated and will
be removed in upcoming versions. |
appearance (array ) |
Allows to define additional appearance options:
|
iconIdentifier (string ) | The module icon identifier |
icon (string ) | Path to a module icon (Deprecated: Use icon instead) |
labels (array or string ) |
An
The value can either be a static string or a locallang label reference. It's also possible to define the path to a locallang file. The referenced file should contain the following label keys:
|
component (string ) | The view component, responsible for rendering the module.
Defaults to TYPO3/ . |
navigationComponent (string ) | The module navigation component, e.g.
TYPO3/ . |
navigationComponentId (string ) | The module navigation component (Deprecated: Use
navigation instead). |
inheritNavigationComponentFromMainModule (bool ) | Whether the module should use the parents navigation component.
This option defaults to true and can therefore be used to
stop the inheritance for submodules. |
moduleData (array ) | The allowed module data properties and their default value.
Module data are the module specific settings of a backend user.
The properties, defined in the registration, can be overwritten
in a request via GET or POST . For more information
about the usage of this option, see the corresponding
changelog. |
aliases (array ) | List of identifiers that are aliases to this module. Those are
added as route aliases, which allows to use them for building
links, e.g. with the Uri . Additionally, the
aliases can also be used for references in other modules, e.g.
to specify a modules' parent . |
routeOptions (array ) | Generic side information that will be merged with each generated
\TYPO3\ array. This can be
used for information, that is not relevant for a module aspect,
but more relevant for the routing aspect (e.g. sudo-mode). |
Module-dependent configuration options
Default:
Option | Description |
---|---|
routes (array ) |
Define the routes to this module. Each route requires at least the
'routes' => [ '_default' => [ 'target' => ControllerA::class . '::handleRequest', ], 'edit' => [ 'path' => '/edit-me', 'target' => ControllerA::class . '::edit', ], 'manage' => [ 'target' => ControllerB::class . '::manage', 'methods' => ['POST'], ], ], |
Extbase:
Option | Description |
---|---|
extensionName (string ) | The extension name, the module is registered for. |
controllerActions (array ) |
Define the controller action pair. The array keys are the controller class names and the values are the actions, which can either be defined as array or comma-separated list: 'controllerActions' => [ Controller::class => [ 'aAction', 'anotherAction', ], ], |
The BeforeModuleCreationEvent
The new PSR-14 Before
allows extension authors
to manipulate the module configuration, before it is used to create and
register the module.
Registration of an event listener in the Services.
:
MyVendor\MyPackage\Backend\ModifyModuleIcon:
tags:
- name: event.listener
identifier: 'my-package/backend/modify-module-icon'
The corresponding event listener class:
use TYPO3\CMS\Backend\Module\BeforeModuleCreationEvent;
class ModifyModuleIcon {
public function __invoke(BeforeModuleCreationEvent $event): void
{
// Change module icon of page module
if ($event->getIdentifier() === 'web_layout') {
$event->setConfigurationValue('iconIdentifier', 'my-custom-icon-identifier');
}
}
}
BeforeModuleCreationEvent methods
Method | Parameters | Description |
---|---|---|
getIdentifier() | Returns the identifier of the module in question. | |
getConfiguration() | Get the module configuration, as defined in the
Configuration/ file. | |
setConfiguration() | $configuration | Overrides the module configuration. |
hasConfigurationValue() | $key | Checks whether the given key is set. |
getConfigurationValue() | $key
$default | Returns the value for the given $key , or
the $default , if not set. |
setConfigurationValue() | $key
$value | Updates the configuration $key with the
given value . |
New ModuleProvider API
The other piece is the new Module
API, which allows extension
authors to work with the registered modules in a straightforward way.
Previously, there had been a couple of different classes and methods, which
did mostly the same but in other ways. Also handling of those classes had
been tough, especially the Module
component.
See changelog for all removed classes and methods.
The new API is now the central point to retrieve modules, since it will automatically perform necessary access checks and prepare specific structures, e.g. for the use in menus.
ModuleProvider API methods
Method | Parameters | Description |
---|---|---|
isModuleRegistered() | $identifier | Checks whether a module is registered for the given identifier. Does NOT perform any access check! |
getModule() | $identifier
$user
$respect | Returns a module for the given identifier. In case a user is given, also access checks are performed. Additionally, one can define whether workspace restrictions should be respected. |
getModules() | $user
$respect
$grouped | Returns all modules either grouped by main modules or flat. In case a user is given, also access checks are performed. Additionally, one can define whether workspace restrictions should be respected. |
getModuleForMenu() | $identifier
$user
$respect | Returns the requested main module prepared for menu generation or similar structured output (nested), if it exists and the user has necessary permissions. Additionally, one can define whether workspace restrictions should be respected. |
getModulesForModuleMenu() | $user
$respect | Returns all allowed modules for the current user, prepared for module menu generation or similar structured output (nested). Additionally, one can define whether workspace restrictions should be respected. |
accessGranted() | $identifier | Check access of a module for a given user. Additionally, one can define whether workspace restrictions should be respected. |
ModuleInterface
Instead of a global array structure, the registered modules are stored as
objects in a registry. The module objects implement all the Module
.
This allows a well-defined OOP-based approach to work with registered models.
The Module
basically provides getters for the options,
defined in the module registration and additionally provides methods for
relation handling (main modules and submodules).
Method | Return type | Description |
---|---|---|
getIdentifier() | string | Returns the internal name of the module, used for referencing in permissions etc. |
getPath() | string | Returns the module main path |
getIconIdentifier() | $string | Returns the module icon identifier |
getTitle() | string | Returns the module title (see:
mlang_ ). |
getDescription() | string | Returns the module description (see:
mlang_ ). |
getShortDescription() | string | Returns the module short description (see:
mlang_ ). |
isStandalone() | bool | Returns, whether the module is standalone (main module without submodules). |
getComponent() | string | Returns the view component responsible for rendering the module (iFrame or name of the web component). |
getNavigationComponent() | string | Returns the web component to be rendering the navigation area. |
getPosition() | array | Returns the position of the module, such as
top or bottom or after => another
or before => another . |
getAppearance() | array | Returns a modules' appearance options, e.g. used for module menu. |
getAccess() | string | Returns defined access level, can be user ,
admin or system . |
getWorkspaceAccess() | string | Returns defined workspace access, can be *
(all), live or offline . |
getParentIdentifier() | string | In case this is a submodule, returns the parent module identifier. |
getParentModule() | ?Module | In case this is a submodule, returns the parent module. |
hasParentModule() | bool | Returns whether the module has a parent module defined (is a submodule). |
hasSubModule($identifier) | bool | Returns whether the module has a specific submodule assigned. |
hasSubModules() | bool | Returns whether the module has submodules assigned. |
getSubModule($identifier) | ?Module | If set, returns the requested submodule. |
getSubModules() | Module | Returns all assigned submodules. |
getDefaultRouteOptions() | array | Returns options to be added to the main
module route. Usually module , module
and access . |
getAliases() | array | List of identifiers (e.g. to an old name of the module), which is also used to link and reference in access checks. |
Impact
Registration of backend modules is now done in extension's
Configuration/
file. This allows
to have all modules registered at build-time.
The new Module
API takes care of permission handling
and returns objects based on the Module
. The rendering
is now based on a well-defined OOP-based approach, which is used throughout
all places in TYPO3 Backend now in a unified way.