[TASK] Make type=passthrough a formEngine element 35/58135/3
authorChristian Kuhn <lolli@schwarzbu.ch>
Mon, 3 Sep 2018 02:42:02 +0000 (04:42 +0200)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Mon, 3 Sep 2018 09:01:04 +0000 (11:01 +0200)
To be more consistent and have one special case less,
type=passthrough columns are now casual elements that
go through the NodeFactory of FormEngine just as all
other types.

Resolves: #86094
Releases: master
Change-Id: I08df7a15101aa8835cf3f1da9b8eb389add2c96e
Reviewed-on: https://review.typo3.org/58135
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: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
typo3/sysext/backend/Classes/Form/Container/FlexFormElementContainer.php
typo3/sysext/backend/Classes/Form/Container/SingleFieldContainer.php
typo3/sysext/backend/Classes/Form/Element/PassThroughElement.php [new file with mode: 0644]
typo3/sysext/backend/Classes/Form/NodeFactory.php

index 8592857..dbfae43 100644 (file)
@@ -49,8 +49,6 @@ class FlexFormElementContainer extends AbstractContainer
                 !is_array($flexFormFieldArray)
                 // Not a section or container and not a list of single items
                 || (!isset($flexFormFieldArray['type']) && !is_array($flexFormFieldArray['config']))
-                // Type passthrough is not rendered
-                || (isset($flexFormFieldArray['config']['type']) && $flexFormFieldArray['config']['type'] === 'passthrough')
             ) {
                 continue;
             }
@@ -140,23 +138,23 @@ class FlexFormElementContainer extends AbstractContainer
                 }
                 $childResult = $this->nodeFactory->create($options)->render();
 
-                // Possible line breaks in the label through xml: \n => <br/>, usage of nl2br() not possible, so it's done through str_replace (?!)
-                $processedTitle = str_replace('\\n', '<br />', htmlspecialchars($fakeParameterArray['fieldConf']['label']));
-
-                $html = [];
-                $html[] = '<div class="form-section">';
-                $html[] =    '<div class="form-group t3js-formengine-palette-field t3js-formengine-validation-marker">';
-                $html[] =        '<label class="t3js-formengine-label">';
-                $html[] =            BackendUtility::wrapInHelp($parameterArray['_cshKey'], $flexFormFieldName, $processedTitle);
-                $html[] =        '</label>';
-                $html[] =        '<div class="formengine-field-item t3js-formengine-field-item">';
-                $html[] =            $childResult['html'];
-                $html[] =        '</div>';
-                $html[] =    '</div>';
-                $html[] = '</div>';
-
-                $resultArray['html'] .= implode(LF, $html);
-                $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $childResult, false);
+                if (!empty($childResult['html'])) {
+                    // Possible line breaks in the label through xml: \n => <br/>, usage of nl2br() not possible, so it's done through str_replace (?!)
+                    $processedTitle = str_replace('\\n', '<br />', htmlspecialchars($fakeParameterArray['fieldConf']['label']));
+                    $html = [];
+                    $html[] = '<div class="form-section">';
+                    $html[] =   '<div class="form-group t3js-formengine-palette-field t3js-formengine-validation-marker">';
+                    $html[] =       '<label class="t3js-formengine-label">';
+                    $html[] =           BackendUtility::wrapInHelp($parameterArray['_cshKey'], $flexFormFieldName, $processedTitle);
+                    $html[] =       '</label>';
+                    $html[] =       '<div class="formengine-field-item t3js-formengine-field-item">';
+                    $html[] =           $childResult['html'];
+                    $html[] =       '</div>';
+                    $html[] =   '</div>';
+                    $html[] = '</div>';
+                    $resultArray['html'] .= implode(LF, $html);
+                    $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $childResult, false);
+                }
             }
         }
 
index 261de87..e0e6cc5 100644 (file)
@@ -76,7 +76,6 @@ class SingleFieldContainer extends AbstractContainer
         // Check if this field is configured and editable according to exclude fields and other configuration
         if (// Return if BE-user has no access rights to this field, @todo: another user access rights check!
             $parameterArray['fieldConf']['exclude'] && !$backendUser->check('non_exclude_fields', $table . ':' . $fieldName)
-            || $parameterArray['fieldConf']['config']['type'] === 'passthrough'
             // Return if field should not be rendered in translated records
             || $isOverlay && empty($parameterArray['fieldConf']['l10n_display']) && $parameterArray['fieldConf']['l10n_mode'] === 'exclude'
             || $this->inlineFieldShouldBeSkipped()
diff --git a/typo3/sysext/backend/Classes/Form/Element/PassThroughElement.php b/typo3/sysext/backend/Classes/Form/Element/PassThroughElement.php
new file mode 100644 (file)
index 0000000..3c9c2dd
--- /dev/null
@@ -0,0 +1,33 @@
+<?php
+declare(strict_types = 1);
+namespace TYPO3\CMS\Backend\Form\Element;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+/**
+ * PassThroughElement is the dummy element for type="passthrough".
+ * It does not render anything.
+ */
+class PassThroughElement extends AbstractFormElement
+{
+    /**
+     * Return the empty initialized result array
+     *
+     * @return array
+     */
+    public function render(): array
+    {
+        return $this->initializeResultArray();
+    }
+}
index fb88e49..63fb6c6 100644 (file)
@@ -93,6 +93,7 @@ class NodeFactory
         'user' => Element\UserElement::class,
         'fileInfo' => Element\FileInfoElement::class,
         'slug' => Element\InputSlugElement::class,
+        'passthrough' => Element\PassThroughElement::class,
 
         // Default classes to enrich single elements
         'fieldControl' => NodeExpansion\FieldControl::class,