[TASK] Extract html into fluid template from cache module in admin panel 10/56110/7
authorJoerg Boesche <typo3@joergboesche.de>
Mon, 12 Mar 2018 13:31:29 +0000 (14:31 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Mon, 12 Mar 2018 21:47:28 +0000 (22:47 +0100)
The Cache module should use a fluid template instead of
the old php-html mixed data structure.

Resolves: #84209
Releases: master
Change-Id: Ib1a564c7af7e99007b890017037b9b095e7208b0
Reviewed-on: https://review.typo3.org/56110
Reviewed-by: Frank Naegler <frank.naegler@typo3.org>
Tested-by: Frank Naegler <frank.naegler@typo3.org>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Tobi Kretschmann <tobi@tobishome.de>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
Reviewed-by: Benjamin Kott <benjamin.kott@outlook.com>
Tested-by: Benjamin Kott <benjamin.kott@outlook.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/adminpanel/Classes/Modules/CacheModule.php
typo3/sysext/adminpanel/Resources/Private/Language/locallang_cache.xlf [new file with mode: 0644]
typo3/sysext/adminpanel/Resources/Private/Partials/Modules/Cache/ClearCacheButton.html [new file with mode: 0644]
typo3/sysext/adminpanel/Resources/Private/Partials/Modules/Cache/ClearLevels.html [new file with mode: 0644]
typo3/sysext/adminpanel/Resources/Private/Partials/Modules/Cache/NoCache.html [new file with mode: 0644]
typo3/sysext/adminpanel/Resources/Private/Partials/Modules/Cache/UpdateButton.html [new file with mode: 0644]
typo3/sysext/adminpanel/Resources/Private/Templates/Modules/Cache.html [new file with mode: 0644]
typo3/sysext/lang/Resources/Private/Language/locallang_tsfe.xlf

index d419e61..c4238a1 100644 (file)
@@ -1,5 +1,5 @@
 <?php
-declare(strict_types=1);
+declare(strict_types = 1);
 
 namespace TYPO3\CMS\Adminpanel\Modules;
 
@@ -17,10 +17,16 @@ namespace TYPO3\CMS\Adminpanel\Modules;
  */
 
 use TYPO3\CMS\Core\Type\Bitmask\Permission;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Fluid\View\StandaloneView;
 use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
 
 class CacheModule extends AbstractModule
 {
+    /**
+     * @var string
+     */
+    private $extResources = 'EXT:adminpanel/Resources/Private';
 
     /**
      * Creates the content for the "cache" section ("module") of the Admin Panel
@@ -29,53 +35,19 @@ class CacheModule extends AbstractModule
      */
     public function getContent(): string
     {
-        $output = [];
-        if ($this->getBackendUser()->uc['TSFE_adminConfig']['display_cache']) {
-            $output[] = '<div class="typo3-adminPanel-form-group">';
-            $output[] = '  <div class="typo3-adminPanel-form-group-checkbox">';
-            $output[] = '    <input type="hidden" name="TSFE_ADMIN_PANEL[cache_noCache]" value="0" />';
-            $output[] = '    <label for="cache_noCache">';
-            $output[] = '      <input type="checkbox" id="cache_noCache" name="TSFE_ADMIN_PANEL[cache_noCache]" value="1"' .
-                        ($this->getBackendUser()->uc['TSFE_adminConfig']['cache_noCache'] ? ' checked="checked"' : '') .
-                        ' />';
-            $output[] = '      ' . $this->extGetLL('cache_noCache');
-            $output[] = '    </label>';
-            $output[] = '  </div>';
-            $output[] = '</div>';
+        $view = GeneralUtility::makeInstance(StandaloneView::class);
+        $templateNameAndPath = $this->extResources . '/Templates/Modules/Cache.html';
+        $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName($templateNameAndPath));
+        $view->setPartialRootPaths([$this->extResources . '/Partials']);
 
-            $levels = $this->getBackendUser()->uc['TSFE_adminConfig']['cache_clearCacheLevels'];
-            $output[] = '<div class="typo3-adminPanel-form-group">';
-            $output[] = '  <label for="cache_clearCacheLevels">';
-            $output[] = '    ' . $this->extGetLL('cache_clearLevels');
-            $output[] = '  </label>';
-            $output[] = '  <select id="cache_clearCacheLevels" name="TSFE_ADMIN_PANEL[cache_clearCacheLevels]">';
-            $output[] = '    <option value="0"' . ((int)$levels === 0 ? ' selected="selected"' : '') . '>';
-            $output[] = '      ' . $this->extGetLL('div_Levels_0');
-            $output[] = '    </option>';
-            $output[] = '    <option value="1"' . ($levels == 1 ? ' selected="selected"' : '') . '>';
-            $output[] = '      ' . $this->extGetLL('div_Levels_1');
-            $output[] = '    </option>';
-            $output[] = '    <option value="2"' . ($levels == 2 ? ' selected="selected"' : '') . '>';
-            $output[] = '      ' . $this->extGetLL('div_Levels_2');
-            $output[] = '    </option>';
-            $output[] = '  </select>';
-            $output[] = '</div>';
+        $view->assignMultiple([
+            'isEnabled' => $this->getBackendUser()->uc['TSFE_adminConfig']['display_cache'],
+            'noCache' => $this->getBackendUser()->uc['TSFE_adminConfig']['cache_noCache'],
+            'cacheLevels' => $this->getBackendUser()->uc['TSFE_adminConfig']['cache_clearCacheLevels'],
+            'currentId' => $this->getTypoScriptFrontendController()->id
+        ]);
 
-            $output[] = '<div class="typo3-adminPanel-form-group">';
-            $output[] = '  <input type="hidden" name="TSFE_ADMIN_PANEL[cache_clearCacheId]" value="' .
-                        $GLOBALS['TSFE']->id .
-                        '" />';
-            $output[] = '  <input class="typo3-adminPanel-btn typo3-adminPanel-btn-default" type="submit" value="' .
-                        $this->extGetLL('update') .
-                        '" />';
-            $output[] = '</div>';
-            $output[] = '<div class="typo3-adminPanel-form-group">';
-            $output[] = '  <input class="typo3-adminPanel-btn typo3-adminPanel-btn-default" type="submit" name="TSFE_ADMIN_PANEL[action][clearCache]" value="' .
-                        $this->extGetLL('cache_doit') .
-                        '" />';
-            $output[] = '</div>';
-        }
-        return implode('', $output);
+        return $view->render();
     }
 
     /**
@@ -91,7 +63,8 @@ class CacheModule extends AbstractModule
      */
     public function getLabel(): string
     {
-        return $this->extGetLL('cache');
+        $locallangFileAndPath = 'LLL:' . $this->extResources . '/Language/locallang_cache.xlf:module.label';
+        return $this->getLanguageService()->sL($locallangFileAndPath);
     }
 
     /**
@@ -111,8 +84,7 @@ class CacheModule extends AbstractModule
      */
     public function onSubmit(array $input): void
     {
-        if (($input['action']['clearCache'] ?? false) ||
-            isset($input['preview_showFluidDebug'])) {
+        if (($input['action']['clearCache'] ?? false) || isset($input['preview_showFluidDebug'])) {
             $theStartId = (int)$input['cache_clearCacheId'];
             $this->getTypoScriptFrontendController()
                 ->clearPageCacheContent_pidList(
diff --git a/typo3/sysext/adminpanel/Resources/Private/Language/locallang_cache.xlf b/typo3/sysext/adminpanel/Resources/Private/Language/locallang_cache.xlf
new file mode 100644 (file)
index 0000000..c06aaa8
--- /dev/null
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xliff version="1.0" xmlns:t3="http://typo3.org/schemas/xliff">
+    <file t3:id="1520862804" source-language="en" datatype="plaintext" original="messages" date="2018-03-12T13:52:00Z"
+          product-name="adminpanel">
+        <header/>
+        <body>
+            <trans-unit id="module.label">
+                <source>Cache</source>
+            </trans-unit>
+            <trans-unit id="cache_noCache">
+                <source>No caching</source>
+            </trans-unit>
+            <trans-unit id="cache_doit">
+                <source>Clear cache now!</source>
+            </trans-unit>
+            <trans-unit id="cache_clearLevels">
+                <source>Clear levels</source>
+            </trans-unit>
+            <trans-unit id="div_Levels_0">
+                <source>This page</source>
+            </trans-unit>
+            <trans-unit id="div_Levels_1">
+                <source>+ 1 sublevel</source>
+            </trans-unit>
+            <trans-unit id="div_Levels_2">
+                <source>+ 2 sublevels</source>
+            </trans-unit>
+            <trans-unit id="update">
+                <source>Update</source>
+            </trans-unit>
+        </body>
+    </file>
+</xliff>
diff --git a/typo3/sysext/adminpanel/Resources/Private/Partials/Modules/Cache/ClearCacheButton.html b/typo3/sysext/adminpanel/Resources/Private/Partials/Modules/Cache/ClearCacheButton.html
new file mode 100644 (file)
index 0000000..f44eef5
--- /dev/null
@@ -0,0 +1,6 @@
+<div class="typo3-adminPanel-form-group">
+    <input class="typo3-adminPanel-btn typo3-adminPanel-btn-default"
+           type="submit"
+           name="TSFE_ADMIN_PANEL[action][clearCache]"
+           value="{f:translate(key:'LLL:EXT:adminpanel/Resources/Private/Language/locallang_cache.xlf:cache_doit')}"/>
+</div>
diff --git a/typo3/sysext/adminpanel/Resources/Private/Partials/Modules/Cache/ClearLevels.html b/typo3/sysext/adminpanel/Resources/Private/Partials/Modules/Cache/ClearLevels.html
new file mode 100644 (file)
index 0000000..8ef6d63
--- /dev/null
@@ -0,0 +1,16 @@
+<div class="typo3-adminPanel-form-group">
+    <label for="cache_clearCacheLevels">
+        <f:translate key="LLL:EXT:adminpanel/Resources/Private/Language/locallang_cache.xlf:cache_clearLevels" />
+    </label>
+    <select id="cache_clearCacheLevels" name="TSFE_ADMIN_PANEL[cache_clearCacheLevels]">
+        <option value="0" {f:if(condition:'{cacheLevels} == 0', then:' selected="selected"')} >
+        <f:translate key="LLL:EXT:adminpanel/Resources/Private/Language/locallang_cache.xlf:div_Levels_0" />
+        </option>
+        <option value="1" {f:if(condition:'{cacheLevels} == 1', then:' selected="selected"')}>
+        <f:translate key="LLL:EXT:adminpanel/Resources/Private/Language/locallang_cache.xlf:div_Levels_1" />
+        </option>';
+        <option value="2" {f:if(condition:'{cacheLevels} == 2', then:' selected="selected"')}>
+        <f:translate key="LLL:EXT:adminpanel/Resources/Private/Language/locallang_cache.xlf:div_Levels_2" />
+        </option>
+    </select>
+</div>
diff --git a/typo3/sysext/adminpanel/Resources/Private/Partials/Modules/Cache/NoCache.html b/typo3/sysext/adminpanel/Resources/Private/Partials/Modules/Cache/NoCache.html
new file mode 100644 (file)
index 0000000..097c06d
--- /dev/null
@@ -0,0 +1,13 @@
+<div class="typo3-adminPanel-form-group">
+    <div class="typo3-adminPanel-form-group-checkbox">
+        <input type="hidden" name="TSFE_ADMIN_PANEL[cache_noCache]" value="0"/>
+        <label for="cache_noCache">
+            <input type="checkbox"
+                   id="cache_noCache"
+                   name="TSFE_ADMIN_PANEL[cache_noCache]"
+                   value="1"
+                   {f:if(condition:'{noCache}', then:' checked="checked"')} />
+            <f:translate key="LLL:EXT:adminpanel/Resources/Private/Language/locallang_cache.xlf:cache_noCache"/>
+        </label>
+    </div>
+</div>
diff --git a/typo3/sysext/adminpanel/Resources/Private/Partials/Modules/Cache/UpdateButton.html b/typo3/sysext/adminpanel/Resources/Private/Partials/Modules/Cache/UpdateButton.html
new file mode 100644 (file)
index 0000000..2cc732c
--- /dev/null
@@ -0,0 +1,6 @@
+<div class="typo3-adminPanel-form-group">
+    <input type="hidden" name="TSFE_ADMIN_PANEL[cache_clearCacheId]" value="{currentId}"/>
+    <input class="typo3-adminPanel-btn typo3-adminPanel-btn-default"
+           type="submit"
+           value="{f:translate(key:'LLL:EXT:adminpanel/Resources/Private/Language/locallang_cache.xlf:update')}"/>
+</div>
diff --git a/typo3/sysext/adminpanel/Resources/Private/Templates/Modules/Cache.html b/typo3/sysext/adminpanel/Resources/Private/Templates/Modules/Cache.html
new file mode 100644 (file)
index 0000000..35d3e8d
--- /dev/null
@@ -0,0 +1,6 @@
+<f:if condition="{isEnabled} == 1">
+    <f:render partial="Modules/Cache/NoCache" arguments="{_all}"/>
+    <f:render partial="Modules/Cache/ClearLevels" arguments="{_all}"/>
+    <f:render partial="Modules/Cache/UpdateButton" arguments="{_all}"/>
+    <f:render partial="Modules/Cache/ClearCacheButton"/>
+</f:if>
index 426f9e8..bb2aec8 100644 (file)
                        <trans-unit id="preview_simulateUserGroup">
                                <source>Simulate user group</source>
                        </trans-unit>
-                       <trans-unit id="cache">
-                               <source>Cache</source>
-                       </trans-unit>
-                       <trans-unit id="cache_noCache">
-                               <source>No caching</source>
-                       </trans-unit>
-                       <trans-unit id="cache_doit">
-                               <source>Clear cache now!</source>
-                       </trans-unit>
-                       <trans-unit id="cache_clearLevels">
-                               <source>Clear levels</source>
-                       </trans-unit>
                        <trans-unit id="publish">
                                <source>Publish</source>
                        </trans-unit>
                        <trans-unit id="info_totalParsetime">
                                <source>Total parsetime</source>
                        </trans-unit>
-                       <trans-unit id="div_Levels_0">
-                               <source>This page</source>
-                       </trans-unit>
-                       <trans-unit id="div_Levels_1">
-                               <source>+ 1 sublevel</source>
-                       </trans-unit>
-                       <trans-unit id="div_Levels_2">
-                               <source>+ 2 sublevels</source>
-                       </trans-unit>
                        <trans-unit id="update">
                                <source>Update</source>
                        </trans-unit>