ModuleData¶
New in version 12.0
The moduleData
backend request attribute is available when a backend
module is requested. It holds the object \TYPO3\CMS\Backend\Module\ModuleData
which contains the stored module data that might have been overwritten through
the current request (with GET
/POST
).
Through the module registration one can define, which properties can be
overwritten via GET
/POST
and their default value.
The whole determination is done before the requested route target - usually a backend controller - is called. This means, the route target can just read the final module data.
Note
It is still possible to store and retrieve arbitrary module data. The
definition of moduleData
in the module registration only defines, which
properties can be overwritten in a request (with GET/POST).
To restrict the values of module data properties, the given ModuleData
object can be cleaned, for example, in a controller:
$allowedValues = ['foo', 'bar'];
$this->moduleData->clean('property', $allowedValues);
If ModuleData
contains property
, the value is checked against the
$allowedValues
list. If the current value is valid, nothing happens.
Otherwise the value is either changed to the default or if this value is also
not allowed, to the first allowed value.
API¶
- class \TYPO3\CMS\Backend\Module\ ModuleData¶
-
A simple DTO containing the user specific module settings, e.g. whether the clipboard is shown.
The DTO is created in the PSR-15 middleware BackendModuleValidator, in case a backend module is requested and the user has necessary access permissions. The created DTO is then added as attribute to the PSR-7 Request and can be further used in components, such as middlewares or the route target (usually a backend controller).
- createFromModule ( TYPO3\\CMS\\Backend\\Module\\ModuleInterface $module, array $data) ¶
-
- param TYPO3\\CMS\\Backend\\Module\\ModuleInterface $module
-
the module
- param array $data
-
the data
- returntype
-
self
- getModuleIdentifier ( ) ¶
-
- returntype
-
string
- get ( string $propertyName, mixed $default = NULL) ¶
-
- param string $propertyName
-
the propertyName
- param mixed $default
-
the default, default: NULL
- returntype
-
mixed
- has ( string $propertyName) ¶
-
- param string $propertyName
-
the propertyName
- returntype
-
bool
- set ( string $propertyName, mixed $value) ¶
-
- param string $propertyName
-
the propertyName
- param mixed $value
-
the value
- clean ( string $propertyName, array $allowedValues) ¶
-
Cleans a single property by the given allowed list. First fallback is the default data list. If this list does also not contain an allowed value, the first value from the allowed list is taken.
- param string $propertyName
-
the propertyName
- param array $allowedValues
-
the allowedValues
- returntype
-
bool
- Returns:
-
bool True if something has been cleaned up
- cleanUp ( array $allowedData, bool $useKeys = true) ¶
-
Cleans up all module data, which are defined in the given allowed data list. Usually called with $MOD_MENU.
- param array $allowedData
-
the allowedData
- param bool $useKeys
-
the useKeys, default: true
- returntype
-
bool
- toArray ( ) ¶
-
- returntype
-
array