[!!!][FEATURE] FormEngine element level refactoring
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Form / Container / AbstractContainer.php
index b105f1d..4109b50 100644 (file)
@@ -15,10 +15,7 @@ namespace TYPO3\CMS\Backend\Form\Container;
  */
 
 use TYPO3\CMS\Backend\Form\AbstractNode;
-use TYPO3\CMS\Backend\Form\NodeFactory;
-use TYPO3\CMS\Backend\Utility\BackendUtility;
-use TYPO3\CMS\Core\Imaging\Icon;
-use TYPO3\CMS\Core\Imaging\IconFactory;
+use TYPO3\CMS\Core\Utility\ArrayUtility;
 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Fluid\View\StandaloneView;
@@ -29,30 +26,61 @@ use TYPO3\CMS\Fluid\View\StandaloneView;
 abstract class AbstractContainer extends AbstractNode
 {
     /**
-     * Instance of the node factory to create sub elements and container.
+     * Merge field information configuration with default and render them.
      *
-     * @var NodeFactory
+     * @return array Result array
      */
-    protected $nodeFactory;
+    protected function renderFieldInformation(): array
+    {
+        $options = $this->data;
+        $fieldInformation = $this->defaultFieldInformation;
+        $currentRenderType = $this->data['renderType'];
+        $fieldInformationFromTca = $options['processedTca']['ctrl']['container'][$currentRenderType]['fieldInformation'] ?? [];
+        ArrayUtility::mergeRecursiveWithOverrule($fieldInformation, $fieldInformationFromTca);
+        $options['renderType'] = 'fieldInformation';
+        $options['renderData']['fieldInformation'] = $fieldInformation;
+        return $this->nodeFactory->create($options)->render();
+    }
+
+    /**
+     * Merge field control configuration with default controls and render them.
+     *
+     * @return array Result array
+     */
+    protected function renderFieldControl(): array
+    {
+        $options = $this->data;
+        $fieldControl = $this->defaultFieldControl;
+        $currentRenderType = $this->data['renderType'];
+        $fieldControlFromTca = $options['processedTca']['ctrl']['container'][$currentRenderType]['fieldControl'] ?? [];
+        ArrayUtility::mergeRecursiveWithOverrule($fieldControl, $fieldControlFromTca);
+        $options['renderType'] = 'fieldControl';
+        $options['renderData']['fieldControl'] = $fieldControl;
+        return $this->nodeFactory->create($options)->render();
+    }
 
     /**
-     * Container objects give $nodeFactory down to other containers.
+     * Merge field wizard configuration with default wizards and render them.
      *
-     * @param NodeFactory $nodeFactory
-     * @param array $data
+     * @return array Result array
      */
-    public function __construct(NodeFactory $nodeFactory, array $data)
+    protected function renderFieldWizard(): array
     {
-        parent::__construct($nodeFactory, $data);
-        $this->nodeFactory = $nodeFactory;
+        $options = $this->data;
+        $fieldWizard = $this->defaultFieldWizard;
+        $currentRenderType = $this->data['renderType'];
+        $fieldWizardFromTca = $options['processedTca']['ctrl']['container'][$currentRenderType]['fieldWizard'] ?? [];
+        ArrayUtility::mergeRecursiveWithOverrule($fieldWizard, $fieldWizardFromTca);
+        $options['renderType'] = 'fieldWizard';
+        $options['renderData']['fieldWizard'] = $fieldWizard;
+        return $this->nodeFactory->create($options)->render();
     }
 
     /**
-     * A single field of TCA 'types' 'showitem' can have four semicolon separated configuration options:
+     * A single field of TCA 'types' 'showitem' can have three semicolon separated configuration options:
      *   fieldName: Name of the field to be found in TCA 'columns' section
      *   fieldLabel: An alternative field label
      *   paletteName: Name of a palette to be found in TCA 'palettes' section that is rendered after this field
-     *   extra: Special configuration options of this field
      *
      * @param string $field Semicolon separated field configuration
      * @throws \RuntimeException
@@ -96,57 +124,4 @@ abstract class AbstractContainer extends AbstractNode
         ]);
         return $view->render();
     }
-
-    /**
-     * Rendering preview output of a field value which is not shown as a form field but just outputted.
-     *
-     * @param string $value The value to output
-     * @param array $config Configuration for field.
-     * @param string $field Name of field.
-     * @return string HTML formatted output
-     */
-    protected function previewFieldValue($value, $config, $field = '')
-    {
-        if ($config['config']['type'] === 'group' && ($config['config']['internal_type'] === 'file' || $config['config']['internal_type'] === 'file_reference')) {
-            // Ignore upload folder if internal_type is file_reference
-            if ($config['config']['internal_type'] === 'file_reference') {
-                $config['config']['uploadfolder'] = '';
-            }
-            $table = 'tt_content';
-            // Making the array of file items:
-            $itemArray = GeneralUtility::trimExplode(',', $value, true);
-            // Showing thumbnails:
-            $imgs = [];
-            $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
-            foreach ($itemArray as $imgRead) {
-                $imgParts = explode('|', $imgRead);
-                $imgPath = rawurldecode($imgParts[0]);
-                $rowCopy = [];
-                $rowCopy[$field] = $imgPath;
-                // Icon + click menu:
-                $absFilePath = GeneralUtility::getFileAbsFileName($config['config']['uploadfolder'] ? $config['config']['uploadfolder'] . '/' . $imgPath : $imgPath);
-                $fileInformation = pathinfo($imgPath);
-                $title = $fileInformation['basename'] . ($absFilePath && @is_file($absFilePath))
-                    ? ' (' . GeneralUtility::formatSize(filesize($absFilePath)) . ')'
-                    : ' - FILE NOT FOUND!';
-                $fileIcon = '<span title="' . htmlspecialchars($title) . '">' . $iconFactory->getIconForFileExtension($fileInformation['extension'], Icon::SIZE_SMALL)->render() . '</span>';
-                $imgs[] =
-                    '<span class="text-nowrap">' .
-                    BackendUtility::thumbCode(
-                        $rowCopy,
-                        $table,
-                        $field,
-                        '',
-                        '',
-                        $config['config']['uploadfolder'], 0, ' align="middle"'
-                    ) .
-                    ($absFilePath ? BackendUtility::wrapClickMenuOnIcon($fileIcon, $absFilePath, 0, 1, '', '+copy,info,edit,view') : $fileIcon) .
-                    $imgPath .
-                    '</span>';
-            }
-            return implode('<br />', $imgs);
-        } else {
-            return nl2br(htmlspecialchars($value));
-        }
-    }
 }