[CLEANUP] ImportExport classes
[Packages/TYPO3.CMS.git] / typo3 / sysext / impexp / Classes / Clickmenu.php
1 <?php
2 namespace TYPO3\CMS\Impexp;
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\Utility\BackendUtility;
18 use TYPO3\CMS\Core\Imaging\Icon;
19 use TYPO3\CMS\Core\Imaging\IconFactory;
20 use TYPO3\CMS\Core\Utility\GeneralUtility;
21 use TYPO3\CMS\Lang\LanguageService;
22
23 /**
24 * Adding Import/Export clickmenu item
25 */
26 class Clickmenu
27 {
28 /**
29 * @var IconFactory
30 */
31 protected $iconFactory;
32
33 /**
34 * Construct
35 */
36 public function __construct()
37 {
38 $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
39 }
40
41 /**
42 * Processing of clickmenu items
43 *
44 * @param \TYPO3\CMS\Backend\ClickMenu\ClickMenu $backRef parent
45 * @param array $menuItems Menu items array to modify
46 * @param string $table Table name
47 * @param int $uid Uid of the record
48 * @return array Menu item array, returned after modification
49 * @todo Skinning for icons...
50 */
51 public function main(&$backRef, $menuItems, $table, $uid)
52 {
53 $localItems = array();
54 // Show import/export on second level menu OR root level.
55 if ($backRef->cmLevel && GeneralUtility::_GP('subname') == 'moreoptions' || $table === 'pages' && $uid == 0) {
56 $LL = $this->includeLL();
57 $urlParameters = array(
58 'tx_impexp' => array(
59 'action' => 'export'
60 ),
61 'id' => ($table == 'pages' ? $uid : $backRef->rec['pid'])
62 );
63 if ($table == 'pages') {
64 $urlParameters['tx_impexp']['pagetree']['id'] = $uid;
65 $urlParameters['tx_impexp']['pagetree']['levels'] = 0;
66 $urlParameters['tx_impexp']['pagetree']['tables'][] = '_ALL';
67 } else {
68 $urlParameters['tx_impexp']['record'][] = $table . ':' . $uid;
69 $urlParameters['tx_impexp']['external_ref']['tables'][] = '_ALL';
70 }
71 $url = BackendUtility::getModuleUrl('xMOD_tximpexp', $urlParameters);
72 $localItems[] = $backRef->linkItem(
73 $this->getLanguageService()->makeEntities($this->getLanguageService()->getLLL('export', $LL)),
74 $backRef->excludeIcon($this->iconFactory->getIcon('actions-document-export-t3d', Icon::SIZE_SMALL)),
75 $backRef->urlRefForCM($url),
76 1
77 );
78 if ($table === 'pages') {
79 $urlParameters = array(
80 'id' => $uid,
81 'table' => $table,
82 'tx_impexp' => array(
83 'action' => 'import'
84 ),
85 );
86 $url = BackendUtility::getModuleUrl('xMOD_tximpexp', $urlParameters);
87 $localItems[] = $backRef->linkItem(
88 $this->getLanguageService()->makeEntities($this->getLanguageService()->getLLL('import', $LL)),
89 $backRef->excludeIcon($this->iconFactory->getIcon('actions-document-import-t3d', Icon::SIZE_SMALL)),
90 $backRef->urlRefForCM($url),
91 1
92 );
93 }
94 }
95 return array_merge($menuItems, $localItems);
96 }
97
98 /**
99 * Include local lang file and return $LOCAL_LANG array loaded.
100 *
101 * @return array Local lang array
102 */
103 public function includeLL()
104 {
105 return $this->getLanguageService()->includeLLFile('EXT:impexp/Resources/Private/Language/locallang.xlf', false);
106 }
107
108 /**
109 * @return LanguageService
110 */
111 protected function getLanguageService()
112 {
113 return $GLOBALS['LANG'];
114 }
115 }