[BUGFIX] Fetch configuration of FlexForm fields in edit wizard 93/56493/8
authorChristian Kuhn <lolli@schwarzbu.ch>
Wed, 19 Sep 2018 11:37:49 +0000 (13:37 +0200)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Wed, 19 Sep 2018 14:02:19 +0000 (16:02 +0200)
Supply flex data structure identifier and current path to
editPopup field control to fetch correct TCA config if this
wizard is enabled for select or group fields in flex forms.

Resolves: #78422
Releases: master, 8.7
Change-Id: Ic628824abb36e23935ad9b493a2e401fe8e734c7
Reviewed-on: https://review.typo3.org/56493
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Stephan GroƟberndt <stephan.grossberndt@typo3.org>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
typo3/sysext/backend/Classes/Controller/Wizard/EditController.php
typo3/sysext/backend/Classes/Form/FieldControl/EditPopup.php

index e9d6582..002e741 100644 (file)
@@ -18,6 +18,7 @@ namespace TYPO3\CMS\Backend\Controller\Wizard;
 use Psr\Http\Message\ResponseInterface;
 use Psr\Http\Message\ServerRequestInterface;
 use TYPO3\CMS\Core\Compatibility\PublicPropertyDeprecationTrait;
+use TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools;
 use TYPO3\CMS\Core\Database\RelationHandler;
 use TYPO3\CMS\Core\Http\HtmlResponse;
 use TYPO3\CMS\Core\Http\RedirectResponse;
@@ -151,11 +152,26 @@ class EditController extends AbstractWizardController
         // Initialize:
         $table = $this->P['table'];
         $field = $this->P['field'];
-        $config = $GLOBALS['TCA'][$table]['columns'][$field]['config'];
-        $fTable = $config['foreign_table'];
 
-        $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
+        if (empty($this->P['flexFormDataStructureIdentifier'])) {
+            // If there is not flex data structure identifier, field config is found in globals
+            $config = $GLOBALS['TCA'][$table]['columns'][$field]['config'];
+        } else {
+            // If there is a flex data structure identifier, parse that data structure and
+            // fetch config defined by given flex path
+            $flexFormTools = GeneralUtility::makeInstance(FlexFormTools::class);
+            $dataStructure = $flexFormTools->parseDataStructureByIdentifier($this->P['flexFormDataStructureIdentifier']);
+            $config = $flexFormTools->getArrayValueByPath($this->P['flexFormDataStructurePath'], $dataStructure);
+            if (!is_array($config)) {
+                throw new \RuntimeException(
+                    'Something went wrong finding flex path ' . $this->P['flexFormDataStructurePath']
+                    . ' in data structure identified by ' . $this->P['flexFormDataStructureIdentifier'],
+                    1537356346
+                );
+            }
+        }
 
+        $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
         $urlParameters = [
             'returnUrl' => (string)$uriBuilder->buildUriFromRoute('wizard_edit', ['doClose' => 1])
         ];
@@ -164,11 +180,13 @@ class EditController extends AbstractWizardController
         if (is_array($config)
             && $config['type'] === 'select'
             && !$config['MM']
-            && $config['maxitems'] <= 1 && MathUtility::canBeInterpretedAsInteger($this->P['currentValue'])
-            && $this->P['currentValue'] && $fTable
+            && $config['maxitems'] <= 1
+            && MathUtility::canBeInterpretedAsInteger($this->P['currentValue'])
+            && $this->P['currentValue']
+            && $config['foreign_table']
         ) {
             // SINGLE value
-            $urlParameters['edit[' . $fTable . '][' . $this->P['currentValue'] . ']'] = 'edit';
+            $urlParameters['edit[' . $config['foreign_table'] . '][' . $this->P['currentValue'] . ']'] = 'edit';
             // Redirect to FormEngine
             $url = (string)$uriBuilder->buildUriFromRoute('record_edit', $urlParameters);
             return new RedirectResponse($url);
index 77cf3a2..cfc5990 100644 (file)
@@ -41,19 +41,45 @@ class EditPopup extends AbstractNode
         $itemName = $parameterArray['itemFormElName'];
         $windowOpenParameters = $options['windowOpenParameters'] ?? 'height=800,width=600,status=0,menubar=0,scrollbars=1';
 
+        $flexFormDataStructureIdentifier = $this->data['flexFormDataStructureIdentifier'] ?? '';
+        $flexFormDataStructurePath = '';
+        if (!empty($flexFormDataStructureIdentifier)) {
+            if (empty($this->data['flexFormContainerName'])) {
+                // simple flex form element
+                $flexFormDataStructurePath = 'sheets/'
+                    . $this->data['flexFormSheetName']
+                    . '/ROOT/el/'
+                    . $this->data['flexFormFieldName']
+                    . '/TCEforms/config';
+            } else {
+                // flex form section container element
+                $flexFormDataStructurePath = 'sheets/'
+                    . $this->data['flexFormSheetName']
+                    . '/ROOT/el/'
+                    . $this->data['flexFormFieldName']
+                    . '/el/'
+                    . $this->data['flexFormContainerName']
+                    . '/el/'
+                    . $this->data['flexFormContainerFieldName']
+                    . '/TCEforms/config';
+            }
+        }
+
         $urlParameters = [
             'P' => [
                 'table' => $this->data['tableName'],
                 'field' => $this->data['fieldName'],
                 'formName' => 'editform',
+                'flexFormDataStructureIdentifier' => $flexFormDataStructureIdentifier,
+                'flexFormDataStructurePath' => $flexFormDataStructurePath,
                 'hmac' => GeneralUtility::hmac('editform' . $itemName, 'wizard_js'),
                 'fieldChangeFunc' => $parameterArray['fieldChangeFunc'],
                 'fieldChangeFuncHash' => GeneralUtility::hmac(serialize($parameterArray['fieldChangeFunc'])),
             ],
         ];
-        /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
         $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
         $url = (string)$uriBuilder->buildUriFromRoute('wizard_edit', $urlParameters);
+
         $onClick = [];
         $onClick[] = 'this.blur();';
         $onClick[] = 'if (!TBE_EDITOR.curSelected(' . GeneralUtility::quoteJSvalue($itemName) . ')) {';