Skip to content

Commit

Permalink
[BUGFIX] Registration of multiple additional view models
Browse files Browse the repository at this point in the history
The form setup properties within "additionalViewModelModules" must be
written as numerical associative arrays to make it possible that
multiple extensions can extend the form editor with javascript modules.

Resolves: #85710
Releases: master, 8.7
Change-Id: Iaddf1bfd6f4df8d0c01e0c18be9cef458d8d2caf
Reviewed-on: https://review.typo3.org/58106
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Daniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
  • Loading branch information
waldhacker1 authored and bmack committed Oct 28, 2018
1 parent f5b5585 commit 6939d0d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
4 changes: 2 additions & 2 deletions typo3/sysext/form/Documentation/ApiReference/Index.rst
Expand Up @@ -3955,7 +3955,7 @@ A simple example that registers a custom ``inspector editor`` called 'Inspector-
formEditor:
dynamicRequireJsModules:
additionalViewModelModules:
- 'TYPO3/CMS/MySitePackage/Backend/FormEditor/ViewModel'
10: 'TYPO3/CMS/MySitePackage/Backend/FormEditor/ViewModel'
formEditorFluidConfiguration:
partialRootPaths:
100: 'EXT:my_site_package/Resources/Private/Backend/Partials/FormEditor/'
Expand Down Expand Up @@ -4637,7 +4637,7 @@ In this example, 'GenderSelect' is basically a radio button form element with so
formEditor:
dynamicRequireJsModules:
additionalViewModelModules:
- 'TYPO3/CMS/MySitePackage/Backend/FormEditor/ViewModel'
10: 'TYPO3/CMS/MySitePackage/Backend/FormEditor/ViewModel'
formEditorPartials:
FormElement-GenderSelect: 'Stage/SelectTemplate'
formElementsDefinition:
Expand Down
Expand Up @@ -175,7 +175,7 @@ The following YAML configuration registers an additional JavaScript module.
formEditor:
dynamicRequireJsModules:
additionalViewModelModules:
- 'TYPO3/CMS/MySitePackage/Backend/FormEditor/ViewModel'
10: 'TYPO3/CMS/MySitePackage/Backend/FormEditor/ViewModel'
According to the example shown above, the JavaScript files have to be stored
within the folder ``my_site_package/Resources/Public/JavaScript/Backend/FormEditor/ViewModel.js``.
Expand Down
Expand Up @@ -976,15 +976,12 @@ define(['jquery',
*
* @param object additionalViewModelModules
* @return void
* @throws 1475379752
* @throws 1475492374
*/
function _viewSetup(additionalViewModelModules) {
assert('function' === $.type(_viewModel.bootstrap), 'The view model does not implement the method "bootstrap"', 1475492374);

if (!getUtility().isUndefinedOrNull(additionalViewModelModules)) {
assert('array' === $.type(additionalViewModelModules), 'Invalid parameter "additionalViewModelModules"', 1475379752);
} else {
if (getUtility().isUndefinedOrNull(additionalViewModelModules)) {
additionalViewModelModules = [];
}
_viewModel.bootstrap(_formEditorInstance, additionalViewModelModules);
Expand Down
Expand Up @@ -304,9 +304,21 @@ define(['jquery',
* @throws 1475425785
*/
function _loadAdditionalModules(additionalViewModelModules) {
var additionalViewModelModulesLength, isLastElement, loadedAdditionalViewModelModules;
var additionalViewModelModulesLength, converted, isLastElement, loadedAdditionalViewModelModules;

if ('object' === $.type(additionalViewModelModules)) {
converted = [];
for (var key in additionalViewModelModules) {
if (!additionalViewModelModules.hasOwnProperty(key)) {
continue;
}
converted.push(additionalViewModelModules[key]);
}
additionalViewModelModules = converted;
}

if ('array' !== $.type(additionalViewModelModules)) {
getPublisherSubscriber().publish('view/ready');
return;
}
additionalViewModelModulesLength = additionalViewModelModules.length;
Expand Down

0 comments on commit 6939d0d

Please sign in to comment.