[BUGFIX] Rename calls for action-version-open to ...page-open
[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 {
37 $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
38 }
39
40 /**
41 * Main function, adding the item to input menuItems array
42 *
43 * @param ClickMenu $backRef References to parent clickmenu objects.
44 * @param array $menuItems Array of existing menu items accumulated. New element added to this.
45 * @param string $table Table name of the element
46 * @param int $uid Record UID of the element
47 * @return array Modified menuItems array
48 */
49 public function main(&$backRef, $menuItems, $table, $uid)
50 {
51 $localItems = array();
52 if (!$backRef->cmLevel && $uid > 0 && $GLOBALS['BE_USER']->check('modules', 'web_txversionM1')) {
53 // Returns directly, because the clicked item was not from the pages table
54 if (in_array('versioning', $backRef->disabledItems) || !$GLOBALS['TCA'][$table] || !$GLOBALS['TCA'][$table]['ctrl']['versioningWS']) {
55 return $menuItems;
56 }
57 // Adds the regular item
58 $LL = $this->includeLL();
59 // "Versioning" element added:
60 $url = \TYPO3\CMS\Backend\Utility\BackendUtility::getModuleUrl('web_txversionM1', array('table' => $table, 'uid' => $uid));
61 $localItems[] = $backRef->linkItem(
62 $GLOBALS['LANG']->getLLL('title', $LL),
63 $backRef->excludeIcon($this->iconFactory->getIcon('actions-version-page-open', Icon::SIZE_SMALL)->render()),
64 $backRef->urlRefForCM($url),
65 true
66 );
67 // Find position of "delete" element:
68 $c = 0;
69 foreach ($menuItems as $k => $value) {
70 $c++;
71 if ($k === 'delete') {
72 break;
73 }
74 }
75 // .. subtract two (delete item + divider line)
76 $c -= 2;
77 // ... and insert the items just before the delete element.
78 array_splice($menuItems, $c, 0, $localItems);
79 }
80 return $menuItems;
81 }
82
83 /**
84 * Includes the [extDir]/locallang.xlf and returns the translations found in that file.
85 *
86 * @return array Local lang array
87 */
88 public function includeLL()
89 {
90 return $GLOBALS['LANG']->includeLLFile('EXT:version/Resources/Private/Language/locallang.xlf', false);
91 }
92 }