[TASK] Fluidification of ClearCacheToolbarItem 77/50377/4
authorMarc Willmann <mw@f7.de>
Tue, 25 Oct 2016 21:02:29 +0000 (23:02 +0200)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Wed, 26 Oct 2016 14:33:26 +0000 (16:33 +0200)
Resolves: #78436
Releases: master
Change-Id: I31e1d290f58ac01749091a05002025ee4598a49c
Reviewed-on: https://review.typo3.org/50377
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Gianluigi Martino <gmartino27@gmail.com>
Tested-by: Gianluigi Martino <gmartino27@gmail.com>
Reviewed-by: Daniel Lorenz <info@extco.de>
Tested-by: Daniel Lorenz <info@extco.de>
Reviewed-by: Michael Oehlhof <typo3@oehlhof.de>
Tested-by: Michael Oehlhof <typo3@oehlhof.de>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
typo3/sysext/backend/Classes/Backend/ToolbarItems/ClearCacheToolbarItem.php
typo3/sysext/backend/Resources/Private/Partials/ToolbarItems/ToolbarItem.html [new file with mode: 0644]
typo3/sysext/backend/Resources/Private/Templates/ToolbarItems/ClearCacheToolbarItem.html [new file with mode: 0644]
typo3/sysext/backend/Resources/Private/Templates/ToolbarItems/ClearCacheToolbarItemDropDown.html [new file with mode: 0644]

index 4742950..5a42015 100644 (file)
@@ -21,6 +21,7 @@ use TYPO3\CMS\Core\Imaging\Icon;
 use TYPO3\CMS\Core\Imaging\IconFactory;
 use TYPO3\CMS\Core\Page\PageRenderer;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Fluid\View\StandaloneView;
 
 /**
  * Render cache clearing toolbar item
@@ -121,12 +122,16 @@ class ClearCacheToolbarItem implements ToolbarItemInterface
      */
     public function getItem()
     {
-        $title = htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:rm.clearCache_clearCache'));
         $icon = $this->iconFactory->getIcon('apps-toolbar-menu-cache', Icon::SIZE_SMALL)->render('inline');
-        return '
-            <span class="toolbar-item-icon" title="' . $title . '">' . $icon . '</span>
-            <span class="toolbar-item-title">' . $title . '</span>
-            ';
+
+        $view = $this->getFluidTemplateObject('ClearCacheToolbarItem.html');
+        $view->assignMultiple([
+                'title' => 'LLL:EXT:lang/locallang_core.xlf:rm.clearCache_clearCache',
+                'icon' => $icon
+            ]
+        );
+
+        return $view->render();
     }
 
     /**
@@ -136,32 +141,14 @@ class ClearCacheToolbarItem implements ToolbarItemInterface
      */
     public function getDropDown()
     {
-        $result = [];
-        $result[] = '<h3 class="dropdown-headline">';
-        $result[] = htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:rm.clearCache_clearCache'));
-        $result[] = '</h3>';
-        $result[] = '<hr>';
-        $result[] = '<div class="dropdown-table">';
-        foreach ($this->cacheActions as $cacheAction) {
-            $title = $cacheAction['description'] ?: $cacheAction['title'];
-
-            $result[] = '<div class="dropdown-table-row">';
-
-            $result[] = '<div class="dropdown-table-column dropdown-table-column-top dropdown-table-icon">';
-            $result[] = $cacheAction['icon'];
-            $result[] = '</div>';
-
-            $result[] = '<div class="dropdown-table-column dropdown-table-column-top dropdown-table-text">';
-            $result[] = '<a href="' . htmlspecialchars($cacheAction['href']) . '">';
-            $result[] = htmlspecialchars($cacheAction['title']);
-            $result[] = '<br><small class="text-muted">' . htmlspecialchars($title) . '</small>';
-            $result[] = '</a>';
-            $result[] = '</div>';
-
-            $result[] = '</div>';
-        }
-        $result[] = '</div>';
-        return implode(LF, $result);
+        $view = $this->getFluidTemplateObject('ClearCacheToolbarItemDropDown.html');
+        $view->assignMultiple([
+                'title' =>  'LLL:EXT:lang/locallang_core.xlf:rm.clearCache_clearCache',
+                'cacheActions' => $this->cacheActions,
+            ]
+        );
+
+        return $view->render();
     }
 
     /**
@@ -223,4 +210,25 @@ class ClearCacheToolbarItem implements ToolbarItemInterface
     {
         return $GLOBALS['LANG'];
     }
+
+    /**
+     * Returns a new standalone view, shorthand function
+     *
+     * @param string $filename Which templateFile should be used.
+     *
+     * @return StandaloneView
+     */
+    protected function getFluidTemplateObject(string $filename):StandaloneView
+    {
+        /** @var StandaloneView $view */
+        $view = GeneralUtility::makeInstance(StandaloneView::class);
+        $view->setLayoutRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Layouts')]);
+        $view->setPartialRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Partials/ToolbarItems')]);
+        $view->setTemplateRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates/ToolbarItems')]);
+
+        $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates/ToolbarItems/' . $filename));
+
+        $view->getRequest()->setControllerExtensionName('Backend');
+        return $view;
+    }
 }
diff --git a/typo3/sysext/backend/Resources/Private/Partials/ToolbarItems/ToolbarItem.html b/typo3/sysext/backend/Resources/Private/Partials/ToolbarItems/ToolbarItem.html
new file mode 100644 (file)
index 0000000..efc8745
--- /dev/null
@@ -0,0 +1,4 @@
+{namespace core = TYPO3\CMS\Core\ViewHelpers}
+
+<span class="toolbar-item-icon" title="{f:translate(key: title, htmlEscape: 'TRUE')}">{icon -> f:format.raw()}</span>
+<span class="toolbar-item-title">{f:translate(key: title, htmlEscape: 'FALSE')}</span>
\ No newline at end of file
diff --git a/typo3/sysext/backend/Resources/Private/Templates/ToolbarItems/ClearCacheToolbarItem.html b/typo3/sysext/backend/Resources/Private/Templates/ToolbarItems/ClearCacheToolbarItem.html
new file mode 100644 (file)
index 0000000..48941d8
--- /dev/null
@@ -0,0 +1 @@
+<f:render partial="ToolbarItem" arguments="{title: title, icon: icon}"/>
\ No newline at end of file
diff --git a/typo3/sysext/backend/Resources/Private/Templates/ToolbarItems/ClearCacheToolbarItemDropDown.html b/typo3/sysext/backend/Resources/Private/Templates/ToolbarItems/ClearCacheToolbarItemDropDown.html
new file mode 100644 (file)
index 0000000..84ec8ab
--- /dev/null
@@ -0,0 +1,19 @@
+<h3 class="dropdown-headline">
+    {f:translate(key: title, htmlEscape: 'FALSE')}
+</h3>
+<hr>
+<div class="dropdown-table">
+    <f:for each="{cacheActions}" as="cacheAction">
+    <div class="dropdown-table-row">
+        <div class="dropdown-table-column dropdown-table-column-top dropdown-table-icon">
+            {cacheAction.icon -> f:format.raw()}
+        </div>
+        <div class="dropdown-table-column dropdown-table-column-top dropdown-table-text">
+            <f:link.typolink parameter="{cacheAction.href}">
+                {cacheAction.title}
+                <br><small class="text-muted">{f:if(condition: cacheAction.description,then: cacheAction.description,else: cacheAction.title)} </small>
+            </f:link.typolink>
+        </div>
+    </div>
+</f:for>
+</div>