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