Deprecation: #95200 - RequireJS callbacks as inline JavaScript
See forge#95200
Description
Custom Form
components allowed to load RequireJS modules
with arbitrary inline JavaScript to initialize those modules. In favor
of introducing content security policy headers, the amount of inline
JavaScript shall be reduced and replaced by corresponding declarations.
Using callback functions has been marked as deprecated and shall be replaced by new
\TYPO3\
declarations. In
Form
, loading RequireJS module via arrays has been marked as deprecated and
has to be migrated as well.
Impact
Using $result
with scalar string
values will
trigger a PHP E_
error.
Affected Installations
Installations implementing custom Form
components and loading
RequireJS modules via $result
are affected.
Migration
New Java
allows to declare the following
aspects when loading RequireJS modules:
$instruction = Java
creates corresponding loading instruction that can be enriched with following declarationsScript Module Instruction:: for Require JS ('TYPO3/ CMS/ Module') $instruction->assign
allows to assign key-value pairs directly to the loaded RequireJS module object or instance( ['key' => 'value']) $instruction->invoke
allows to invoke a particular method of the loaded RequireJS instance with given argument values('method', 'value- a', 'value- b') $instruction->instance
allows to invoke the constructor of the loaded RequireJS class with given argument values('value- a', 'value- b')
Initializations other than the provided aspects have to be implemented in custom module implementations, for example triggered by corresponding on-ready handlers.
Example in FormEngine
component
$resultArray['requireJsModules'][] = ['TYPO3/CMS/Backend/FormEngine/Element/InputDateTimeElement' => '
function(InputDateTimeElement) {
new InputDateTimeElement(' . GeneralUtility::quoteJSvalue($fieldId) . ');
}'
];
... has to be migrated to the following ...
// use use TYPO3\CMS\Core\Page\JavaScriptModuleInstruction;
$resultArray['requireJsModules'][] = JavaScriptModuleInstruction::forRequireJS(
'TYPO3/CMS/Backend/FormEngine/Element/InputDateTimeElement'
)->instance($fieldId);
Java
forwards arguments as JSON
data - and thus
handles proper context-aware encoding implicitly (General
and similar custom encoding can be omitted in this case).