Deprecation: #111116 - BackendUtility::getModuleData()
See forge#111116
Description
The method
\TYPO3\ has been
deprecated. It managed module settings in the backend user configuration
based on a
$MOD_ array, a pattern from before backend modules
were registered via Configuration/Backend/Modules.php.
Backend modules receive their settings as
\TYPO3\ object in the request attribute
module, which is created, filled and persisted by the backend
module middleware.
Impact
Calling the method triggers a PHP
E_ error. The
extension scanner reports usages.
Affected installations
Installations with extensions calling
Backend in custom backend modules.
Migration
Declare the module settings and their default values in the
module option of the module registration. Values sent with the
request under the same names are then persisted automatically. Read the
settings from the
module request attribute and use
Module to restrict menu settings to allowed values.
Before:
use TYPO3\CMS\Backend\Utility\BackendUtility;
$menu = [
'mode' => ['list' => 'List', 'tiles' => 'Tiles'],
];
$settings = BackendUtility::getModuleData(
$menu,
$request->getParsedBody()['SET'] ?? [],
'my_module'
);
$mode = $settings['mode'];
After:
return [
'my_module' => [
// ...
'moduleData' => [
'mode' => 'list',
],
],
];
use TYPO3\CMS\Backend\Module\ModuleData;
/** @var ModuleData $moduleData */
$moduleData = $request->getAttribute('moduleData');
if ($moduleData->clean('mode', ['list', 'tiles'])) {
$this->getBackendUser()->pushModuleData(
$moduleData->getModuleIdentifier(),
$moduleData->toArray()
);
}
$mode = $moduleData->get('mode');