[BUGFIX] Registration of multiple additional view models 06/58106/3
authorRalf Zimmermann <ralf.zimmermann@tritum.de>
Fri, 31 Aug 2018 17:17:22 +0000 (19:17 +0200)
committerBenni Mack <benni@typo3.org>
Sun, 28 Oct 2018 14:41:30 +0000 (15:41 +0100)
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>
typo3/sysext/form/Documentation/ApiReference/Index.rst
typo3/sysext/form/Documentation/Concepts/FormEditor/Index.rst
typo3/sysext/form/Resources/Public/JavaScript/Backend/FormEditor.js
typo3/sysext/form/Resources/Public/JavaScript/Backend/FormEditor/ViewModel.js

index 36d13ea..4237438 100644 (file)
@@ -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/'
@@ -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:
index 086b781..1e3837e 100644 (file)
@@ -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``.
index ea37378..72866d9 100644 (file)
@@ -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);
index c7e4e7f..094ff84 100644 (file)
@@ -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;