From 966351c8ddb5860813f5dfe658774893b1cd477e Mon Sep 17 00:00:00 2001
From: Claus Due <claus@namelesscoder.net>
Date: Fri, 11 Nov 2016 14:50:38 +0100
Subject: [PATCH] [BUGFIX] Compact clear cache button when one item exists

This change makes the clear cache toolbar item dynamically
either render a drop-down as it did before, or render a single
link directly if there is only a single clear cache action.

If any hooks or permissions add additional items the drop-
down is rendered again.

Change-Id: Iadac80405bf1152a849d4d4269a9bc0728b0b459
Releases: master
Resolves: #78656
Reviewed-on: https://review.typo3.org/50594
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Philipp Gampe <philipp.gampe@typo3.org>
Tested-by: Philipp Gampe <philipp.gampe@typo3.org>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
---
 .../ToolbarItems/ClearCacheToolbarItem.php    | 22 +++++++++++++------
 .../Partials/ToolbarItems/ToolbarItem.html    |  2 +-
 .../ClearCacheToolbarItemDropDown.html        |  2 +-
 .../ClearCacheToolbarItemSingle.html          |  4 ++++
 .../JavaScript/Toolbar/ClearCacheMenu.js      |  2 +-
 5 files changed, 22 insertions(+), 10 deletions(-)
 create mode 100644 typo3/sysext/backend/Resources/Private/Templates/ToolbarItems/ClearCacheToolbarItemSingle.html

diff --git a/typo3/sysext/backend/Classes/Backend/ToolbarItems/ClearCacheToolbarItem.php b/typo3/sysext/backend/Classes/Backend/ToolbarItems/ClearCacheToolbarItem.php
index 5a420155fba6..df33469e40ac 100644
--- a/typo3/sysext/backend/Classes/Backend/ToolbarItems/ClearCacheToolbarItem.php
+++ b/typo3/sysext/backend/Classes/Backend/ToolbarItems/ClearCacheToolbarItem.php
@@ -122,14 +122,22 @@ class ClearCacheToolbarItem implements ToolbarItemInterface
      */
     public function getItem()
     {
-        $icon = $this->iconFactory->getIcon('apps-toolbar-menu-cache', Icon::SIZE_SMALL)->render('inline');
-
-        $view = $this->getFluidTemplateObject('ClearCacheToolbarItem.html');
-        $view->assignMultiple([
+        if ($this->hasDropDown()) {
+            $templateReference = 'ClearCacheToolbarItem.html';
+            $icon = $this->iconFactory->getIcon('apps-toolbar-menu-cache', Icon::SIZE_SMALL)->render('inline');
+            $variables = [
                 'title' => 'LLL:EXT:lang/locallang_core.xlf:rm.clearCache_clearCache',
                 'icon' => $icon
-            ]
-        );
+            ];
+        } else {
+            $templateReference = 'ClearCacheToolbarItemSingle.html';
+            $cacheAction = end($this->cacheActions);
+            $variables['link'] = $cacheAction['href'];
+            $variables['title'] = $cacheAction['title'];
+            $variables['icon'] = $cacheAction['icon'];
+        }
+        $view = $this->getFluidTemplateObject($templateReference);
+        $view->assignMultiple($variables);
 
         return $view->render();
     }
@@ -168,7 +176,7 @@ class ClearCacheToolbarItem implements ToolbarItemInterface
      */
     public function hasDropDown()
     {
-        return true;
+        return count($this->cacheActions) > 1;
     }
 
     /**
diff --git a/typo3/sysext/backend/Resources/Private/Partials/ToolbarItems/ToolbarItem.html b/typo3/sysext/backend/Resources/Private/Partials/ToolbarItems/ToolbarItem.html
index efc8745787ce..99e1d94ca8ea 100644
--- a/typo3/sysext/backend/Resources/Private/Partials/ToolbarItems/ToolbarItem.html
+++ b/typo3/sysext/backend/Resources/Private/Partials/ToolbarItems/ToolbarItem.html
@@ -1,4 +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-icon" title="{f:translate(key: title, htmlEscape: 'TRUE', default: title)}">{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/ClearCacheToolbarItemDropDown.html b/typo3/sysext/backend/Resources/Private/Templates/ToolbarItems/ClearCacheToolbarItemDropDown.html
index 9875fa8e70f7..69d1296f27b3 100644
--- a/typo3/sysext/backend/Resources/Private/Templates/ToolbarItems/ClearCacheToolbarItemDropDown.html
+++ b/typo3/sysext/backend/Resources/Private/Templates/ToolbarItems/ClearCacheToolbarItemDropDown.html
@@ -5,7 +5,7 @@
 <div class="dropdown-table">
     <f:for each="{cacheActions}" as="cacheAction">
         <div class="dropdown-table-row">
-            <f:link.typolink parameter="{cacheAction.href}">
+            <f:link.typolink parameter="{cacheAction.href}" class="toolbar-cache-flush-action">
                 <div class="dropdown-table-column dropdown-table-column-top dropdown-table-icon">
                     {cacheAction.icon -> f:format.raw()}
                 </div>
diff --git a/typo3/sysext/backend/Resources/Private/Templates/ToolbarItems/ClearCacheToolbarItemSingle.html b/typo3/sysext/backend/Resources/Private/Templates/ToolbarItems/ClearCacheToolbarItemSingle.html
new file mode 100644
index 000000000000..8d4ca8d0ed08
--- /dev/null
+++ b/typo3/sysext/backend/Resources/Private/Templates/ToolbarItems/ClearCacheToolbarItemSingle.html
@@ -0,0 +1,4 @@
+<f:link.typolink parameter="{link}" class="toolbar-cache-flush-action toolbar-item-link" title="{title}">
+    <f:render partial="ToolbarItem" arguments="{title: title, icon: icon}"/>
+</f:link.typolink>
+
diff --git a/typo3/sysext/backend/Resources/Public/JavaScript/Toolbar/ClearCacheMenu.js b/typo3/sysext/backend/Resources/Public/JavaScript/Toolbar/ClearCacheMenu.js
index b3ff39b1b7c4..22558fa61e5e 100644
--- a/typo3/sysext/backend/Resources/Public/JavaScript/Toolbar/ClearCacheMenu.js
+++ b/typo3/sysext/backend/Resources/Public/JavaScript/Toolbar/ClearCacheMenu.js
@@ -27,7 +27,7 @@ define(['jquery', 'TYPO3/CMS/Backend/Icons', 'TYPO3/CMS/Backend/Notification'],
 	var ClearCacheMenu = {
 		options: {
 			containerSelector: '#typo3-cms-backend-backend-toolbaritems-clearcachetoolbaritem',
-			menuItemSelector: '.dropdown-menu a',
+			menuItemSelector: 'a.toolbar-cache-flush-action',
 			toolbarIconSelector: '.toolbar-item-icon .t3js-icon',
 		}
 	};
-- 
GitLab