[BUGFIX] Fetch configuration of FlexForm fields in edit wizard 39/58339/3
authorChristian Kuhn <lolli@schwarzbu.ch>
Wed, 19 Sep 2018 11:37:49 +0000 (13:37 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Thu, 20 Sep 2018 10:14:00 +0000 (12:14 +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/58339
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/backend/Classes/Controller/Wizard/EditController.php
typo3/sysext/backend/Classes/Form/FieldControl/EditPopup.php

index 6c16d1a..590bd5f 100644 (file)
@@ -17,6 +17,7 @@ namespace TYPO3\CMS\Backend\Controller\Wizard;
 use Psr\Http\Message\ResponseInterface;
 use Psr\Http\Message\ServerRequestInterface;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
+use TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools;
 use TYPO3\CMS\Core\Database\RelationHandler;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Utility\HttpUtility;
@@ -100,9 +101,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'];
 
+        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' => BackendUtility::getModuleUrl('wizard_edit', ['doClose' => 1])
         ];
@@ -111,11 +129,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 = BackendUtility::getModuleUrl('record_edit', $urlParameters);
             HttpUtility::redirect($url);
index b498b48..4c27108 100644 (file)
@@ -42,11 +42,37 @@ class EditPopup extends AbstractNode
         $itemName = $parameterArray['itemFormElName'];
         $windowOpenParameters = $options['windowOpenParameters'] ?? 'height=800,width=600,status=0,menubar=0,scrollbars=1';
 
-        $urlParameters  = [
+        $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'])),