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)
Parameters
Return type

self

getModuleIdentifier()
Return type

string

get(string $propertyName, mixed $default = NULL)
Parameters
  • $propertyName (string) -- the propertyName

  • $default (mixed) -- the default, default: NULL

Return type

mixed

has(string $propertyName)
Parameters
  • $propertyName (string) -- the propertyName

Return type

bool

set(string $propertyName, mixed $value)
Parameters
  • $propertyName (string) -- the propertyName

  • $value (mixed) -- 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.

Parameters
  • $propertyName (string) -- the propertyName

  • $allowedValues (array) -- the allowedValues

Return type

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.

Parameters
  • $allowedData (array) -- the allowedData

  • $useKeys (bool) -- the useKeys, default: true

Return type

bool

toArray()
Return type

array