From 0f876cf223db3b229a7ef95e7a1676b8666b57d0 Mon Sep 17 00:00:00 2001 From: Florian Wessels Date: Mon, 10 Oct 2016 14:03:45 +0200 Subject: [PATCH] [TASK] Use IconFactory for TYPO3 > 6 (#26) --- Classes/View/AdministrationModuleFunction.php | 149 ++++++++++++++---- 1 file changed, 118 insertions(+), 31 deletions(-) diff --git a/Classes/View/AdministrationModuleFunction.php b/Classes/View/AdministrationModuleFunction.php index 8869570..666836e 100644 --- a/Classes/View/AdministrationModuleFunction.php +++ b/Classes/View/AdministrationModuleFunction.php @@ -27,6 +27,7 @@ * This copyright notice MUST APPEAR in all copies of the script! ***************************************************************/ use TYPO3\CMS\Backend\Utility\BackendUtility; +use TYPO3\CMS\Core\Utility\VersionNumberUtility; /** * Class AdministrationModuleFunction @@ -38,6 +39,29 @@ class AdministrationModuleFunction extends \TYPO3\CMS\Backend\Module\AbstractFun */ protected $searchResultCounter = 0; + /** + * @var int + */ + protected $typo3VersionMain = 0; + + /** + * @var null|\TYPO3\CMS\Core\Imaging\IconFactory + */ + protected $iconFactory = null; + + /** + * @var array + */ + protected $iconMapping = array( + 'gfx/zoom.gif' => 'actions-search', + 'gfx/edit2.gif' => 'actions-open', + 'gfx/garbage.gif' => 'actions-delete', + 'gfx/napshot.gif' => 'actions-document-save', + 'gfx/clip_copy.gif' => 'actions-edit-copy', + 'gfx/up.gif' => 'actions-move-up', + 'gfx/new_el.gif' => 'actions-document-new', + ); + /** * */ @@ -84,6 +108,13 @@ public function modMenu() */ public function main() { + $typo3VersionArray = VersionNumberUtility::convertVersionStringToArray(VersionNumberUtility::getCurrentTypo3Version()); + $this->typo3VersionMain = $typo3VersionArray['version_main']; + + if ($this->typo3VersionMain > 6) { + $this->iconFactory = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Imaging\\IconFactory'); + } + if ($this->pObj->id) { $result = $this->createModuleContentForPage(); } else { @@ -277,12 +308,12 @@ public function renderModule(\TYPO3\CMS\Backend\Tree\View\PageTreeView $tree) $baseRow = $row['row']; // page row as base. $onClick = \TYPO3\CMS\Backend\Utility\BackendUtility::editOnClick('&edit[pages][' . $row['row']['uid'] . ']=edit&columnsOnly=title,nav_title,alias,tx_realurl_pathsegment', $this->pObj->doc->backPath); $editIcon = '' . - 'pObj->doc->backPath, 'gfx/edit2.gif', 'width="11" height="12"') . ' title="" alt="" />' . + $this->getIcon('gfx/edit2.gif', 'width="11" height="12"', $this->pObj->doc->backPath) . ''; $onClick = \TYPO3\CMS\Backend\Utility\BackendUtility::viewOnClick($row['row']['uid'], $this->pObj->doc->backPath, '', '', '', ''); $editIcon.= '' . - 'pObj->doc->backPath, 'gfx/zoom.gif', 'width="12" height="12"') . ' title="" alt="" />' . - ''; + $this->getIcon('gfx/zoom.gif', 'width="12" height="12"', $this->pObj->doc->backPath) . + ''; if ($inf['language_id']>0) { // For alternative languages, show another list of fields, form page overlay record: $editIcon = ''; @@ -291,11 +322,11 @@ public function renderModule(\TYPO3\CMS\Backend\Tree\View\PageTreeView $tree) $baseRow = array_merge($baseRow, $olRec); $onClick = \TYPO3\CMS\Backend\Utility\BackendUtility::editOnClick('&edit[pages_language_overlay][' . $olRec['uid'] . ']=edit&columnsOnly=title,nav_title', $this->pObj->doc->backPath); $editIcon = '' . - 'pObj->doc->backPath, 'gfx/edit2.gif', 'width="11" height="12"') . ' title="" alt="" />' . + $this->getIcon('gfx/edit2.gif', 'width="11" height="12"', $this->pObj->doc->backPath) . ''; $onClick = \TYPO3\CMS\Backend\Utility\BackendUtility::viewOnClick($row['row']['uid'], $this->pObj->doc->backPath, '', '', '', '&L=' . $olRec['sys_language_uid']); $editIcon.= '' . - 'pObj->doc->backPath, 'gfx/zoom.gif', 'width="12" height="12"') . ' title="" alt="" />' . + $this->getIcon('gfx/zoom.gif', 'width="12" height="12"', $this->pObj->doc->backPath) . ''; } else { $baseRow = array(); @@ -352,16 +383,16 @@ public function renderModule(\TYPO3\CMS\Backend\Tree\View\PageTreeView $tree) } else { $tCells[]='' . '' . - 'pObj->doc->backPath, 'gfx/garbage.gif', 'width="11" height="12"') . ' title="Delete" alt="" />' . + $this->getIcon('gfx/garbage.gif', 'width="11" height="12"', $this->pObj->doc->backPath, 'Delete') . '' . '' . - 'pObj->doc->backPath, 'gfx/edit2.gif', 'width="11" height="12"') . ' title="Edit" alt="" />' . + $this->getIcon('gfx/edit2.gif', 'width="12" height="12"', $this->pObj->doc->backPath, 'Edit') . '' . '' . - 'pObj->doc->backPath, 'gfx/napshot.gif', 'width="12" height="12"') . ' title="Use for search" alt="" />' . + $this->getIcon('gfx/napshot.gif', 'width="12" height="12"', $this->pObj->doc->backPath, 'Use for search') . '' . '' . - 'pObj->doc->backPath, 'gfx/clip_copy.gif', 'width="12" height="12"') . ' title="Copy entry" alt="" />' . + $this->getIcon('gfx/clip_copy.gif', 'width="12" height="12"', $this->pObj->doc->backPath, 'Copy entry') . '' . ''; } @@ -369,7 +400,7 @@ public function renderModule(\TYPO3\CMS\Backend\Tree\View\PageTreeView $tree) ($inf['expire'] ? htmlspecialchars(\TYPO3\CMS\Backend\Utility\BackendUtility::dateTimeAge($inf['expire'], -1)) : '') . ($inf['expire'] ? '' . - 'pObj->doc->backPath, 'gfx/up.gif', 'width="14" height="14"') . ' title="Set expire time to 30 days" alt="" />' . + $this->getIcon('gfx/up.gif', 'width="14" height="14"', $this->pObj->doc->backPath, 'Set expire time to 30 days') . '' : '') . ''; @@ -415,15 +446,15 @@ public function renderModule(\TYPO3\CMS\Backend\Tree\View\PageTreeView $tree) $tCells[]='Pagepath:'; $tCells[]='' . '' . - 'pObj->doc->backPath, 'gfx/garbage.gif', 'width="11" height="12"') . ' alt="" />' . + $this->getIcon('gfx/garbage.gif', 'width="11" height="12"', $this->pObj->doc->backPath) . '' . '' . - 'pObj->doc->backPath, 'gfx/edit2.gif', 'width="11" height="12"') . ' title="" alt="" />' . + $this->getIcon('gfx/edit2.gif', 'width="11" height="12"', $this->pObj->doc->backPath) . '' . ''; $tCells[]='Expires:' . '' . - 'pObj->doc->backPath, 'gfx/garbage.gif', 'width="11" height="12"') . ' title="Flush all expired" alt="" />' . + $this->getIcon('gfx/garbage.gif', 'width="11" height="12"', $this->pObj->doc->backPath, 'Flush all expired') . '' . ''; $tCells[]='Errors:'; @@ -784,7 +815,7 @@ public function decodeView(\TYPO3\CMS\Backend\Tree\View\PageTreeView $tree) $tCells[]='' . $row['row']['uid'] . ''; $tCells[]='' . '' . - 'pObj->doc->backPath, 'gfx/garbage.gif', 'width="11" height="12"') . ' title="Delete entries for page" alt="" />' . + $this->getIcon('gfx/garbage.gif', 'width="11" height="12"', $this->pObj->doc->backPath, 'Delete entries for page') . '' . ''; } @@ -801,7 +832,7 @@ public function decodeView(\TYPO3\CMS\Backend\Tree\View\PageTreeView $tree) // Delete: $tCells[]='' . '' . - 'pObj->doc->backPath, 'gfx/garbage.gif', 'width="11" height="12"') . ' title="Delete entry" alt="" />' . + $this->getIcon('gfx/garbage.gif', 'width="11" height="12"', $this->pObj->doc->backPath, 'Delete entry') . '' . ''; @@ -842,12 +873,12 @@ public function decodeView(\TYPO3\CMS\Backend\Tree\View\PageTreeView $tree) $output = '

Displayed entries: ' . $countDisplayed . ' ' . '' . - 'pObj->doc->backPath, 'gfx/garbage.gif', 'width="11" height="12"') . ' title="Delete displayed entries" alt="" />' . + $this->getIcon('gfx/garbage.gif', 'width="11" height="12"', $this->pObj->doc->backPath, 'Delete displayed entries') . '' . '
Total entries in decode cache: ' . $count_allInTable['count'] . ' ' . '' . - 'pObj->doc->backPath, 'gfx/garbage.gif', 'width="11" height="12"') . ' title="Delete WHOLE decode cache!" alt="" />' . + $this->getIcon('gfx/garbage.gif', 'width="11" height="12"', $this->pObj->doc->backPath, 'Delete WHOLE decode cache!') . '' . '
' . $output . ' @@ -926,7 +957,7 @@ public function encodeView(\TYPO3\CMS\Backend\Tree\View\PageTreeView $tree) $tCells[]=''; $tCells[]=''; } @@ -943,7 +974,7 @@ public function encodeView(\TYPO3\CMS\Backend\Tree\View\PageTreeView $tree) // Delete: $tCells[]=''; @@ -1001,12 +1032,12 @@ public function encodeView(\TYPO3\CMS\Backend\Tree\View\PageTreeView $tree)
Displayed entries: ' . $countDisplayed . ' ' . '' . - 'pObj->doc->backPath, 'gfx/garbage.gif', 'width="11" height="12"') . ' title="Delete displayed entries" alt="" />' . + $this->getIcon('gfx/garbage.gif', 'width="11" height="12"', $this->pObj->doc->backPath, 'Delete displayed entries') . '' . '
Total entries in encode cache: ' . $count_allInTable['count'] . ' ' . '' . - 'pObj->doc->backPath, 'gfx/garbage.gif', 'width="11" height="12"') . ' title="Delete WHOLE encode cache!" alt="" />' . + $this->getIcon('gfx/garbage.gif', 'width="11" height="12"', $this->pObj->doc->backPath, 'Delete WHOLE encode cache!') . '' . '
' . $row['row']['uid'] . '' . '' . - 'pObj->doc->backPath, 'gfx/garbage.gif', 'width="11" height="12"') . ' title="Delete entries for page" alt="" />' . + $this->getIcon('gfx/garbage.gif', 'width="11" height="12"', $this->pObj->doc->backPath, 'Delete entries for page') . '' . '' . '' . - 'pObj->doc->backPath, 'gfx/garbage.gif', 'width="11" height="12"') . ' title="Delete entry" alt="" />' . + $this->getIcon('gfx/garbage.gif', 'width="11" height="12"', $this->pObj->doc->backPath, 'Delete entry!') . '' . '
' . $output . ' @@ -1107,11 +1138,11 @@ public function uniqueAlias() $tCells[]=''; @@ -1141,15 +1172,15 @@ public function uniqueAlias() $tCells[]=''; $tCells[]=''; $tCells[]=''; $tCells[]=''; @@ -1328,7 +1359,7 @@ public function logView() $tCells[]=''; $tCells[]=''; $tCells[]=''; @@ -1364,7 +1395,7 @@ public function logView() $output = '
' . - 'pObj->doc->backPath, 'gfx/garbage.gif', 'width="11" height="12"') . ' title="Delete All" alt="" />' . + $this->getIcon('gfx/garbage.gif', 'width="11" height="12"', $this->pObj->doc->backPath, 'Delete All') . ' Flush log
' . // Edit link: '' . - 'pObj->doc->backPath, 'gfx/edit2.gif', 'width="11" height="12"') . ' title="" alt="" />' . + $this->getIcon('gfx/edit2.gif', 'width="11" height="12"', $this->pObj->doc->backPath) . '' . // Delete link: '' . - 'pObj->doc->backPath, 'gfx/garbage.gif', 'width="11" height="12"') . ' title="" alt="" />' . + $this->getIcon('gfx/garbage.gif', 'width="11" height="12"', $this->pObj->doc->backPath) . '' . 'Lang:Expire:' . (!$search ? '' . - 'pObj->doc->backPath, 'gfx/garbage.gif', 'width="11" height="12"') . ' title="Flush expired" alt="" />' . + $this->getIcon('gfx/garbage.gif', 'width="11" height="12"', $this->pObj->doc->backPath, 'Flush expired') . '' : '') . '' . (!$search ? '' . - 'pObj->doc->backPath, 'gfx/edit2.gif', 'width="11" height="12"') . ' title="Edit all" alt="" />' . + $this->getIcon('gfx/edit2.gif', 'width="11" height="12"', $this->pObj->doc->backPath, 'Edit all') . '' . '' . - 'pObj->doc->backPath, 'gfx/garbage.gif', 'width="11" height="12"') . ' title="Delete all" alt="" />' . + $this->getIcon('gfx/garbage.gif', 'width="11" height="12"', $this->pObj->doc->backPath, 'Delete all') . '' : '') . 'Error:' . \TYPO3\CMS\Backend\Utility\BackendUtility::dateTimeAge($rec['tstamp']) . '' . ($host ? $host . '/' : '') . htmlspecialchars($rec['url']) . '' . ' ' . - 'pObj->doc->backPath, 'gfx/napshot.gif', 'width="12" height="12"') . ' title="Set as redirect" alt="" />' . + $this->getIcon('gfx/napshot.gif', 'width="12" height="12"', $this->pObj->doc->backPath, 'Set as redirect') . '' . '' . htmlspecialchars($rec['error']) . '
' . $output . ' @@ -1520,10 +1551,10 @@ protected function generateSingleRedirectContent(array $rec, $page) { $output = ''; $output .= sprintf('', htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . $rec['url']), htmlspecialchars($rec['url'])); @@ -1671,7 +1702,7 @@ protected function deleteRedirectEntry() protected function getNewButton() { $content = '
' . - 'pObj->doc->backPath, 'gfx/new_el.gif', 'width="11" height="12"') . ' title="New entry" alt="" />' . + $this->getIcon('gfx/new_el.gif', 'width="11" height="12"', $this->pObj->doc->backPath, 'New entry') . ' Add new redirects
'; return $content; } @@ -1904,4 +1935,60 @@ protected function getDestinationRedirectURL($url) } return $url; } + + /** + * @param string $icon + * @param string $iconSize + * @param string $backPath + * @param string $title + * @param string $alt + * + * @return string + */ + protected function getIcon($icon, $iconSize = '', $backPath = '', $title = '', $alt = '') + { + if ($this->typo3VersionMain === 6) { + return $this->getIconByIconUtility($icon, $iconSize, $backPath, $title, $alt); + } else { + $icon = $this->iconMapping[$icon]; + return $this->getIconByIconFactory($icon); + } + } + + /** + * @param string $icon + * @param string $iconSize + * @param string $backPath + * @param string $title + * @param string $alt + * + * @return string + */ + protected function getIconByIconUtility($icon, $iconSize, $backPath, $title, $alt) + { + $imgTag = 'iconFactory->getIcon($icon, $iconSize)->render(); + } }
' . '' . - 'pObj->doc->backPath, 'gfx/edit2.gif', 'width="11" height="12"') . ' title="Edit entry" alt="" />' . + $this->getIcon('gfx/edit2.gif', 'width="11" height="12"', $this->pObj->doc->backPath, 'Edit entry') . '' . '' . - 'pObj->doc->backPath, 'gfx/garbage.gif', 'width="11" height="12"') . ' title="Delete entry" alt="" />' . + $this->getIcon('gfx/garbage.gif', 'width="11" height="12"', $this->pObj->doc->backPath, 'Delete entry') . '' . '/%s