[BUGFIX] Compact clear cache button when one item exists 94/50594/5
authorClaus Due <claus@namelesscoder.net>
Fri, 11 Nov 2016 13:50:38 +0000 (14:50 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Sun, 20 Nov 2016 00:23:48 +0000 (01:23 +0100)
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>
typo3/sysext/backend/Classes/Backend/ToolbarItems/ClearCacheToolbarItem.php
typo3/sysext/backend/Resources/Private/Partials/ToolbarItems/ToolbarItem.html
typo3/sysext/backend/Resources/Private/Templates/ToolbarItems/ClearCacheToolbarItemDropDown.html
typo3/sysext/backend/Resources/Private/Templates/ToolbarItems/ClearCacheToolbarItemSingle.html [new file with mode: 0644]
typo3/sysext/backend/Resources/Public/JavaScript/Toolbar/ClearCacheMenu.js

index 5a42015..df33469 100644 (file)
@@ -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;
     }
 
     /**
index efc8745..99e1d94 100644 (file)
@@ -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
index 9875fa8..69d1296 100644 (file)
@@ -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 (file)
index 0000000..8d4ca8d
--- /dev/null
@@ -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>
+
index b3ff39b..22558fa 100644 (file)
@@ -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',
                }
        };