[TASK] Call explicit render() on icon objects
[Packages/TYPO3.CMS.git] / typo3 / sysext / version / Classes / ClickMenu / VersionClickMenu.php
1 <?php
2 namespace TYPO3\CMS\Version\ClickMenu;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Backend\ClickMenu\ClickMenu;
18 use TYPO3\CMS\Core\Imaging\Icon;
19 use TYPO3\CMS\Core\Imaging\IconFactory;
20 use TYPO3\CMS\Core\Utility\GeneralUtility;
21
22 /**
23 * "Versioning" item added to click menu of elements.
24 */
25 class VersionClickMenu {
26
27 /**
28 * @var IconFactory
29 */
30 protected $iconFactory;
31
32 /**
33 * Initialize
34 */
35 public function __construct() {
36 $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
37 }
38
39 /**
40 * Main function, adding the item to input menuItems array
41 *
42 * @param ClickMenu $backRef References to parent clickmenu objects.
43 * @param array $menuItems Array of existing menu items accumulated. New element added to this.
44 * @param string $table Table name of the element
45 * @param int $uid Record UID of the element
46 * @return array Modified menuItems array
47 */
48 public function main(&$backRef, $menuItems, $table, $uid) {
49 $localItems = array();
50 if (!$backRef->cmLevel && $uid > 0 && $GLOBALS['BE_USER']->check('modules', 'web_txversionM1')) {
51 // Returns directly, because the clicked item was not from the pages table
52 if (in_array('versioning', $backRef->disabledItems) || !$GLOBALS['TCA'][$table] || !$GLOBALS['TCA'][$table]['ctrl']['versioningWS']) {
53 return $menuItems;
54 }
55 // Adds the regular item
56 $LL = $this->includeLL();
57 // "Versioning" element added:
58 $url = \TYPO3\CMS\Backend\Utility\BackendUtility::getModuleUrl('web_txversionM1', array('table' => $table, 'uid' => $uid));
59 $localItems[] = $backRef->linkItem(
60 $GLOBALS['LANG']->getLLL('title', $LL),
61 $backRef->excludeIcon($this->iconFactory->getIcon('actions-version-open', Icon::SIZE_SMALL)->render()),
62 $backRef->urlRefForCM($url),
63 TRUE
64 );
65 // Find position of "delete" element:
66 $c = 0;
67 foreach ($menuItems as $k => $value) {
68 $c++;
69 if ($k === 'delete') {
70 break;
71 }
72 }
73 // .. subtract two (delete item + divider line)
74 $c -= 2;
75 // ... and insert the items just before the delete element.
76 array_splice($menuItems, $c, 0, $localItems);
77 }
78 return $menuItems;
79 }
80
81 /**
82 * Includes the [extDir]/locallang.xlf and returns the translations found in that file.
83 *
84 * @return array Local lang array
85 */
86 public function includeLL() {
87 return $GLOBALS['LANG']->includeLLFile('EXT:version/Resources/Private/Language/locallang.xlf', FALSE);
88 }
89
90 }