4da8e6c257b5e4ed79f2a83df35e1fcfd0639f88
[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 /**
18 * "Versioning" item added to click menu of elements.
19 *
20 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
21 */
22 class VersionClickMenu {
23
24 /**
25 * Main function, adding the item to input menuItems array
26 *
27 * @param object $backRef References to parent clickmenu objects.
28 * @param array $menuItems Array of existing menu items accumulated. New element added to this.
29 * @param string $table Table name of the element
30 * @param int $uid Record UID of the element
31 * @return array Modified menuItems array
32 */
33 public function main(&$backRef, $menuItems, $table, $uid) {
34 $localItems = array();
35 if (!$backRef->cmLevel && $uid > 0 && $GLOBALS['BE_USER']->check('modules', 'web_txversionM1')) {
36 // Returns directly, because the clicked item was not from the pages table
37 if (in_array('versioning', $backRef->disabledItems) || !$GLOBALS['TCA'][$table] || !$GLOBALS['TCA'][$table]['ctrl']['versioningWS']) {
38 return $menuItems;
39 }
40 // Adds the regular item
41 $LL = $this->includeLL();
42 // "Versioning" element added:
43 $url = \TYPO3\CMS\Backend\Utility\BackendUtility::getModuleUrl('web_txversionM1', array('table' => $table, 'uid' => $uid));
44 $localItems[] = $backRef->linkItem(
45 $GLOBALS['LANG']->getLLL('title', $LL),
46 $backRef->excludeIcon('<img src="' . $backRef->backPath . \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('version') . 'Resources/Public/Icons/module-version.png" width="15" height="12" border="0" align="top" alt="" />'),
47 $backRef->urlRefForCM($url),
48 TRUE
49 );
50 // Find position of "delete" element:
51 $c = 0;
52 foreach ($menuItems as $k => $value) {
53 $c++;
54 if ($k === 'delete') {
55 break;
56 }
57 }
58 // .. subtract two (delete item + divider line)
59 $c -= 2;
60 // ... and insert the items just before the delete element.
61 array_splice($menuItems, $c, 0, $localItems);
62 }
63 return $menuItems;
64 }
65
66 /**
67 * Includes the [extDir]/locallang.xlf and returns the translations found in that file.
68 *
69 * @return array Local lang array
70 */
71 public function includeLL() {
72 return $GLOBALS['LANG']->includeLLFile('EXT:version/locallang.xlf', FALSE);
73 }
74
75 }