[!!!][TASK] Make TypoScriptTemplateConstantEditorModuleFunctionController Fluid 84/49884/6
authorMichael Oehlhof <typo3@oehlhof.de>
Fri, 9 Sep 2016 07:16:41 +0000 (09:16 +0200)
committerJan Helke <typo3@helke.de>
Fri, 7 Oct 2016 13:26:20 +0000 (15:26 +0200)
Fluidification of TypoScriptTemplateConstantEditorModuleFunctionController

Resolves: #75032
Releases: master
Change-Id: Iacd826c958989b4afe9cbed57367226e486c42af
Reviewed-on: https://review.typo3.org/49884
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Daniel Goerz <ervaude@gmail.com>
Tested-by: Daniel Goerz <ervaude@gmail.com>
Reviewed-by: Jan Helke <typo3@helke.de>
Tested-by: Jan Helke <typo3@helke.de>
typo3/sysext/core/Documentation/Changelog/master/Breaking-75032-FluidificationOfTypoScriptTemplateConstantEditorModuleFunctionController.rst [new file with mode: 0644]
typo3/sysext/tstemplate/Classes/Controller/TypoScriptTemplateConstantEditorModuleFunctionController.php
typo3/sysext/tstemplate/Resources/Private/Templates/ConstantEditor.html [new file with mode: 0644]

diff --git a/typo3/sysext/core/Documentation/Changelog/master/Breaking-75032-FluidificationOfTypoScriptTemplateConstantEditorModuleFunctionController.rst b/typo3/sysext/core/Documentation/Changelog/master/Breaking-75032-FluidificationOfTypoScriptTemplateConstantEditorModuleFunctionController.rst
new file mode 100644 (file)
index 0000000..4eb293d
--- /dev/null
@@ -0,0 +1,28 @@
+.. include:: ../../Includes.txt
+
+=============================================================================================
+Breaking: #75032 - Fluidification of TypoScriptTemplateConstantEditorModuleFunctionController
+=============================================================================================
+
+Description
+===========
+
+:php:`TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateConstantEditorModuleFunctionController->displayExample();` has been removed.
+
+
+Impact
+======
+
+Using this function will throw a fatal error.
+
+
+Affected Installations
+======================
+
+All installations using :php:`TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateConstantEditorModuleFunctionController->displayExample();`
+
+
+Migration
+=========
+
+There is no migration available, pleas write your own function.
\ No newline at end of file
index 43cde3e..dcc53b9 100644 (file)
@@ -17,10 +17,9 @@ namespace TYPO3\CMS\Tstemplate\Controller;
 use TYPO3\CMS\Backend\Module\AbstractFunctionModule;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Core\DataHandling\DataHandler;
-use TYPO3\CMS\Core\Imaging\Icon;
-use TYPO3\CMS\Core\Imaging\IconFactory;
 use TYPO3\CMS\Core\TypoScript\ExtendedTemplateService;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Fluid\View\StandaloneView;
 use TYPO3\CMS\Frontend\Page\PageRepository;
 
 /**
@@ -70,22 +69,20 @@ class TypoScriptTemplateConstantEditorModuleFunctionController extends AbstractF
     }
 
     /**
-     * Display example
+     * Get the data for display of an example
      *
-     * @param string $theOutput
-     * @return string
+     * @return array
      */
-    public function displayExample($theOutput)
+    public function getHelpConfig()
     {
+        $result = [];
         $templateService = $this->getExtendedTemplateService();
         if ($templateService->helpConfig['description'] || $templateService->helpConfig['header']) {
-            $theOutput .= '<div style="padding-top: 30px;"></div>';
-            $theOutput .= '<div>' . htmlspecialchars($templateService->helpConfig['header'])
-                . ($templateService->helpConfig['description'] ? implode(explode('//', $templateService->helpConfig['description']), '<br>') . '<br>' : '')
-                . ($templateService->helpConfig['bulletlist'] ? '<ul><li>' . implode(explode('//', $templateService->helpConfig['bulletlist']), '<li>') . '</ul>' : '<br>')
-                . '</div>';
+            $result['header'] = $templateService->helpConfig['header'];
+            $result['description'] = explode('//', $templateService->helpConfig['description']);
+            $result['bulletList'] = explode('//', $templateService->helpConfig['bulletlist']);
         }
-        return $theOutput;
+        return $result;
     }
 
     /**
@@ -95,10 +92,8 @@ class TypoScriptTemplateConstantEditorModuleFunctionController extends AbstractF
      */
     public function main()
     {
-        $lang = $this->getLanguageService();
-
-        $lang->includeLLFile('EXT:tstemplate/Resources/Private/Language/locallang_ceditor.xlf');
-        $theOutput = '';
+        $assigns = [];
+        $assigns['LLPrefix'] = 'LLL:EXT:tstemplate/Resources/Private/Language/locallang_ceditor.xlf:';
         // Create extension template
         $this->pObj->createTemplate($this->pObj->id);
         // Checking for more than one template an if, set a menu...
@@ -114,8 +109,13 @@ class TypoScriptTemplateConstantEditorModuleFunctionController extends AbstractF
             $templateService = $this->getExtendedTemplateService();
             $tplRow = $this->getTemplateRow();
             $theConstants = $this->getConstants();
+            $assigns['siteTitle'] = trim($tplRow['sitetitle']);
+            $assigns['templateRecord'] = $tplRow;
+            if ($manyTemplatesMenu) {
+                $assigns['manyTemplatesMenu'] = $manyTemplatesMenu;
+            }
 
-            $this->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Tstemplate/ConstantEditor');
+            $this->getPageRenderer();
             $saveId = $tplRow['_ORIG_uid'] ? $tplRow['_ORIG_uid'] : $tplRow['uid'];
             // Update template ?
             if (GeneralUtility::_POST('_savedok')) {
@@ -143,22 +143,10 @@ class TypoScriptTemplateConstantEditorModuleFunctionController extends AbstractF
             $this->pObj->MOD_MENU['constant_editor_cat'] = $templateService->ext_getCategoryLabelArray();
             $this->pObj->MOD_SETTINGS = BackendUtility::getModuleData($this->pObj->MOD_MENU, GeneralUtility::_GP('SET'), $this->pObj->MCONF['name']);
             // Resetting the menu (stop)
-            $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
-            $content = $iconFactory->getIconForRecord('sys_template', $tplRow, Icon::SIZE_SMALL)->render() . '<strong>&nbsp;' . $this->pObj->linkWrapTemplateTitle($tplRow['title'], 'constants') . '</strong>' . (trim($tplRow['sitetitle']) ? htmlspecialchars(' (' . $tplRow['sitetitle'] . ')') : '');
-            $theOutput .= '<h3>' . htmlspecialchars($lang->getLL('editConstants')) . '</h3><div>' . $content . '</div>';
-            if ($manyTemplatesMenu) {
-                $theOutput .= '<div>' . $manyTemplatesMenu . '</div>';
-            }
-            $theOutput .= '<div style="padding-top: 10px;"></div>';
+            $assigns['title'] = $this->pObj->linkWrapTemplateTitle($tplRow['title'], 'constants');
             if (!empty($this->pObj->MOD_MENU['constant_editor_cat'])) {
-                $menu = '<div class="form-inline form-inline-spaced">';
-                $menu .= BackendUtility::getDropdownMenu($this->pObj->id, 'SET[constant_editor_cat]', $this->pObj->MOD_SETTINGS['constant_editor_cat'], $this->pObj->MOD_MENU['constant_editor_cat']);
-                $menu .= '</div>';
-                $theOutput .= '<h3>' . htmlspecialchars($lang->getLL('category')) . '</h3><div><span class="text-nowrap">' . $menu . '</span></div>';
-            } else {
-                $theOutput .= '<h3>' . $iconFactory->getIcon('status-dialog-notification', Icon::SIZE_SMALL)->render() . htmlspecialchars($lang->getLL('noConstants')) . '</h3><div>' . htmlspecialchars($lang->getLL('noConstantsDescription')) . '</div>';
+                $assigns['constantsMenu'] = BackendUtility::getDropdownMenu($this->pObj->id, 'SET[constant_editor_cat]', $this->pObj->MOD_SETTINGS['constant_editor_cat'], $this->pObj->MOD_MENU['constant_editor_cat']);
             }
-            $theOutput .= '<div style="padding-top: 15px;"></div>';
             // Category and constant editor config:
             $category = $this->pObj->MOD_SETTINGS['constant_editor_cat'];
             $templateService->ext_getTSCE_config($category);
@@ -169,14 +157,21 @@ class TypoScriptTemplateConstantEditorModuleFunctionController extends AbstractF
             }
 
             if ($printFields) {
-                $theOutput .= '<div>' . $printFields . '</div>';
+                $assigns['printFields'] = $printFields;
             }
             $BE_USER_modOptions = BackendUtility::getModTSconfig(0, 'mod.' . $this->pObj->MCONF['name']);
             if ($BE_USER_modOptions['properties']['constantEditor.']['example'] != 'top') {
-                $theOutput = $this->displayExample($theOutput);
+                $assigns['helpConfig'] = $this->getHelpConfig();
             }
+            // Rendering of the output via fluid
+            $view = GeneralUtility::makeInstance(StandaloneView::class);
+            $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
+                'EXT:tstemplate/Resources/Private/Templates/ConstantEditor.html'
+            ));
+            $view->assignMultiple($assigns);
+            $theOutput = $view->render();
         } else {
-            $theOutput .= $this->pObj->noTemplate(1);
+            $theOutput = $this->pObj->noTemplate(1);
         }
         return $theOutput;
     }
diff --git a/typo3/sysext/tstemplate/Resources/Private/Templates/ConstantEditor.html b/typo3/sysext/tstemplate/Resources/Private/Templates/ConstantEditor.html
new file mode 100644 (file)
index 0000000..c8ff849
--- /dev/null
@@ -0,0 +1,55 @@
+{namespace core=TYPO3\CMS\Core\ViewHelpers}
+
+<f:be.pageRenderer includeRequireJsModules="{0: 'TYPO3/CMS/Tstemplate/ConstantEditor'}" />
+<h3><f:translate key="{LLPrefix}editConstants"/></h3>
+<div>
+    <core:iconForRecord table="sys_template" row="{templateRecord}" />
+    <strong>&nbsp;<f:format.raw>{title}</f:format.raw></strong>
+    <f:if condition="{siteTitle}">({siteTitle})</f:if>
+    <f:if condition="{manyTemplatesMenu}">
+        <div>
+            <f:format.raw>
+                {manyTemplatesMenu}
+            </f:format.raw>
+        </div>
+    </f:if>
+    <div style="padding-top: 10px;"></div>
+    <f:if condition="{constantsMenu}">
+        <f:then>
+            <h3><f:translate key="{LLPrefix}category"/></h3>
+            <div><span class="text-nowrap">
+                <div class="form-inline form-inline-spaced"><f:format.raw>{constantsMenu}</f:format.raw></div>
+            </span></div>
+        </f:then>
+        <f:else>
+            <h3><core:icon identifier="status-dialog-notification" /><f:translate key="{LLPrefix}noConstants"/></h3>
+            <div><f:translate key="{LLPrefix}noConstantsDescription"/></div>
+        </f:else>
+    </f:if>
+    <div style="padding-top: 15px;"></div>
+    <f:if condition="{printFields}">
+        <div>
+            <f:format.raw>
+                {printFields}
+            </f:format.raw>
+        </div>
+    </f:if>
+    <f:if condition="{helpConfig.header}">
+        <div style="padding-top: 30px;"></div>
+        <div>
+            {helpConfig.header}<br>
+            <f:if condition="{helpConfig.description}">
+                <f:for each="{helpConfig.description}" as="line">
+                    {line}<br>
+                </f:for>
+            </f:if>
+            <f:if condition="{helpConfig.bulletList}">
+                <ul>
+                <f:for each="{helpConfig.bulletList}" as="line">
+                    <li>{line}</li>
+                </f:for>
+                </ul>
+            </f:if>
+        </div>
+    </f:if>
+</div>