From b0d663a3c811d155aa7e8ee5379c57b88f914d5b Mon Sep 17 00:00:00 2001 From: Marc Willmann <mw@f7.de> Date: Tue, 25 Oct 2016 23:02:29 +0200 Subject: [PATCH] [TASK] Fluidification of ClearCacheToolbarItem 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> --- .../ToolbarItems/ClearCacheToolbarItem.php | 70 +++++++++++-------- .../Partials/ToolbarItems/ToolbarItem.html | 4 ++ .../ToolbarItems/ClearCacheToolbarItem.html | 1 + .../ClearCacheToolbarItemDropDown.html | 19 +++++ 4 files changed, 63 insertions(+), 31 deletions(-) create mode 100644 typo3/sysext/backend/Resources/Private/Partials/ToolbarItems/ToolbarItem.html create mode 100644 typo3/sysext/backend/Resources/Private/Templates/ToolbarItems/ClearCacheToolbarItem.html create mode 100644 typo3/sysext/backend/Resources/Private/Templates/ToolbarItems/ClearCacheToolbarItemDropDown.html diff --git a/typo3/sysext/backend/Classes/Backend/ToolbarItems/ClearCacheToolbarItem.php b/typo3/sysext/backend/Classes/Backend/ToolbarItems/ClearCacheToolbarItem.php index 47429506c11e..5a420155fba6 100644 --- a/typo3/sysext/backend/Classes/Backend/ToolbarItems/ClearCacheToolbarItem.php +++ b/typo3/sysext/backend/Classes/Backend/ToolbarItems/ClearCacheToolbarItem.php @@ -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 index 000000000000..efc8745787ce --- /dev/null +++ b/typo3/sysext/backend/Resources/Private/Partials/ToolbarItems/ToolbarItem.html @@ -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 index 000000000000..48941d882c7b --- /dev/null +++ b/typo3/sysext/backend/Resources/Private/Templates/ToolbarItems/ClearCacheToolbarItem.html @@ -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 index 000000000000..84ec8abeb54c --- /dev/null +++ b/typo3/sysext/backend/Resources/Private/Templates/ToolbarItems/ClearCacheToolbarItemDropDown.html @@ -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> -- GitLab