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_MODULES
. 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 ExtensionManagementUtility::addModule()
and ExtensionUtility::registerModule()
(Extbase) API methods in
ext_tables.php
files, the configuration is now placed in the
dedicated Configuration/Backend/Modules.php
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_tables.php
:
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/Backend/Modules.php
:
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 mainModule_subModule
pattern, since a possible parent
will be defined with the parent
option.
Module configuration options¶
Option |
Description |
---|---|
parent ( |
If the module should be a submodule, the parent identifier, e.g.
|
path ( |
Define the path to the default endpoint. The path can be
anything, but will fallback to the known
|
standalone ( |
Whether the module is a standalone module (parent without submodules). |
access ( |
Can be |
workspaces ( |
Can be |
position ( |
The module position. Allowed values are |
appearance ( |
Allows to define additional appearance options:
|
iconIdentifier ( |
The module icon identifier |
icon ( |
Path to a module icon (Deprecated: Use |
labels ( |
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 ( |
The view component, responsible for rendering the module.
Defaults to |
navigationComponent ( |
The module navigation component, e.g.
|
navigationComponentId ( |
The module navigation component (Deprecated: Use
|
inheritNavigationComponentFromMainModule ( |
Whether the module should use the parents navigation component.
This option defaults to |
moduleData ( |
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 |
aliases ( |
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 |
routeOptions ( |
Generic side information that will be merged with each generated
|
Module-dependent configuration options¶
Default:
Option |
Description |
---|---|
routes ( |
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 ( |
The extension name, the module is registered for. |
controllerActions ( |
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 BeforeModuleCreationEvent
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.yaml
:
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('iconIdentifider', '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
|
|
setConfiguration() |
|
Overrides the module configuration. |
hasConfigurationValue() |
|
Checks whether the given key is set. |
getConfigurationValue() |
|
Returns the value for the given |
setConfigurationValue() |
|
Updates the configuration |
New ModuleProvider API¶
The other piece is the new ModuleProvider
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 ModuleLoader
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() |
|
Checks whether a module is registered for the given identifier. Does NOT perform any access check! |
getModule() |
|
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() |
|
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() |
|
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() |
|
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() |
|
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 ModuleInterface
.
This allows a well-defined OOP-based approach to work with registered models.
The ModuleInterface
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() |
|
Returns the internal name of the module, used for referencing in permissions etc. |
getPath() |
|
Returns the module main path |
getIconIdentifier() |
|
Returns the module icon identifier |
getTitle() |
|
Returns the module title (see:
|
getDescription() |
|
Returns the module description (see:
|
getShortDescription() |
|
Returns the module short description (see:
|
isStandalone() |
|
Returns, whether the module is standalone (main module without submodules). |
getComponent() |
|
Returns the view component responsible for rendering the module (iFrame or name of the web component). |
getNavigationComponent() |
|
Returns the web component to be rendering the navigation area. |
getPosition() |
|
Returns the position of the module, such as
|
getAppearance() |
|
Returns a modules' appearance options, e.g. used for module menu. |
getAccess() |
|
Returns defined access level, can be |
getWorkspaceAccess() |
|
Returns defined workspace access, can be |
getParentIdentifier() |
|
In case this is a submodule, returns the parent module identifier. |
getParentModule() |
|
In case this is a submodule, returns the parent module. |
hasParentModule() |
|
Returns whether the module has a parent module defined (is a submodule). |
hasSubModule($identifier) |
|
Returns whether the module has a specific submodule assigned. |
hasSubModules() |
|
Returns whether the module has submodules assigned. |
getSubModule($identifier) |
|
If set, returns the requested submodule. |
getSubModules() |
|
Returns all assigned submodules. |
getDefaultRouteOptions() |
|
Returns options to be added to the main
module route. Usually |
getAliases() |
|
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/Backend/Modules.php
file. This allows
to have all modules registered at build-time.
The new ModuleProvider
API takes care of permission handling
and returns objects based on the ModuleInterface
. 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.