a60914e29ece2a855112d4dee6bbd2de63ffe24e
[Packages/TYPO3.CMS.git] / typo3 / sysext / recycler / Classes / Controller / RecyclerModuleController.php
1 <?php
2 namespace TYPO3\CMS\Recycler\Controller;
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\Template\Components\ButtonBar;
18 use TYPO3\CMS\Backend\View\BackendTemplateView;
19 use TYPO3\CMS\Core\Imaging\Icon;
20 use TYPO3\CMS\Core\Utility\GeneralUtility;
21 use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
22 use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
23
24 /**
25 * Module 'Recycler' for the 'recycler' extension.
26 */
27 class RecyclerModuleController extends ActionController
28 {
29 /**
30 * @var string
31 */
32 protected $relativePath;
33
34 /**
35 * @var string
36 */
37 public $perms_clause;
38
39 /**
40 * @var array
41 */
42 protected $pageRecord = [];
43
44 /**
45 * @var bool
46 */
47 protected $isAccessibleForCurrentUser = false;
48
49 /**
50 * @var bool
51 */
52 protected $allowDelete = false;
53
54 /**
55 * @var int
56 */
57 protected $recordsPageLimit = 50;
58
59 /**
60 * @var int
61 */
62 protected $id;
63
64 /**
65 * @var BackendTemplateView
66 */
67 protected $view;
68
69 /**
70 * BackendTemplateView Container
71 *
72 * @var BackendTemplateView
73 */
74 protected $defaultViewObjectName = BackendTemplateView::class;
75
76 /**
77 * Initializes the Module
78 */
79 public function initializeAction()
80 {
81 $this->id = (int)GeneralUtility::_GP('id');
82 $backendUser = $this->getBackendUser();
83 $this->perms_clause = $backendUser->getPagePermsClause(1);
84 $this->pageRecord = \TYPO3\CMS\Backend\Utility\BackendUtility::readPageAccess($this->id, $this->perms_clause);
85 $this->isAccessibleForCurrentUser = $this->id && is_array($this->pageRecord) || !$this->id && $this->getBackendUser()->isAdmin();
86
87 // don't access in workspace
88 if ($backendUser->workspace !== 0) {
89 $this->isAccessibleForCurrentUser = false;
90 }
91
92 // read configuration
93 $modTS = $backendUser->getTSConfig('mod.recycler');
94 if ($this->getBackendUser()->isAdmin()) {
95 $this->allowDelete = true;
96 } else {
97 $this->allowDelete = (bool)$modTS['properties']['allowDelete'];
98 }
99
100 if (isset($modTS['properties']['recordsPageLimit']) && (int)$modTS['properties']['recordsPageLimit'] > 0) {
101 $this->recordsPageLimit = (int)$modTS['properties']['recordsPageLimit'];
102 }
103 }
104
105 /**
106 * Initialize the view
107 *
108 * @param ViewInterface $view The view
109 */
110 public function initializeView(ViewInterface $view)
111 {
112 /** @var BackendTemplateView $view */
113 parent::initializeView($view);
114 $this->registerDocheaderButtons();
115 $this->view->getModuleTemplate()->setFlashMessageQueue($this->controllerContext->getFlashMessageQueue());
116 }
117
118 /**
119 * Renders the content of the module.
120 */
121 public function indexAction()
122 {
123 // Integrate dynamic JavaScript such as configuration or lables:
124 $jsConfiguration = $this->getJavaScriptConfiguration();
125 $this->view->getModuleTemplate()->getPageRenderer()->addInlineSettingArray('Recycler', $jsConfiguration);
126 $this->view->getModuleTemplate()->getPageRenderer()->addInlineLanguageLabelFile('EXT:recycler/Resources/Private/Language/locallang.xlf');
127 if ($this->isAccessibleForCurrentUser) {
128 $this->view->getModuleTemplate()->getDocHeaderComponent()->setMetaInformation($this->pageRecord);
129 }
130
131 $this->view->assign('title', $this->getLanguageService()->getLL('title'));
132 $this->view->assign('allowDelete', $this->allowDelete);
133 }
134
135 /**
136 * Registers the Icons into the docheader
137 *
138 * @throws \InvalidArgumentException
139 */
140 protected function registerDocheaderButtons()
141 {
142 /** @var ButtonBar $buttonBar */
143 $buttonBar = $this->view->getModuleTemplate()->getDocHeaderComponent()->getButtonBar();
144 $currentRequest = $this->request;
145 $moduleName = $currentRequest->getPluginName();
146 $getVars = $this->request->getArguments();
147
148 $extensionName = $currentRequest->getControllerExtensionName();
149 if (count($getVars) === 0) {
150 $modulePrefix = strtolower('tx_' . $extensionName . '_' . $moduleName);
151 $getVars = ['id', 'route', $modulePrefix];
152 }
153 $shortcutButton = $buttonBar->makeShortcutButton()
154 ->setModuleName($moduleName)
155 ->setGetVariables($getVars);
156 $buttonBar->addButton($shortcutButton);
157
158 $reloadButton = $buttonBar->makeLinkButton()
159 ->setHref('#')
160 ->setDataAttributes(['action' => 'reload'])
161 ->setTitle($this->getLanguageService()->sL('LLL:EXT:recycler/Resources/Private/Language/locallang.xlf:button.reload'))
162 ->setIcon($this->view->getModuleTemplate()->getIconFactory()->getIcon('actions-refresh', Icon::SIZE_SMALL));
163 $buttonBar->addButton($reloadButton, ButtonBar::BUTTON_POSITION_RIGHT);
164 }
165
166 /**
167 * Gets the JavaScript configuration.
168 *
169 * @return array The JavaScript configuration
170 */
171 protected function getJavaScriptConfiguration()
172 {
173 $configuration = [
174 'pagingSize' => $this->recordsPageLimit,
175 'showDepthMenu' => 1,
176 'startUid' => (int)GeneralUtility::_GP('id'),
177 'isSSL' => GeneralUtility::getIndpEnv('TYPO3_SSL'),
178 'deleteDisable' => !$this->allowDelete,
179 'depthSelection' => $this->getDataFromSession('depthSelection', 0),
180 'tableSelection' => $this->getDataFromSession('tableSelection', ''),
181 'States' => $this->getBackendUser()->uc['moduleData']['web_recycler']['States']
182 ];
183 return $configuration;
184 }
185
186 /**
187 * Gets data from the session of the current backend user.
188 *
189 * @param string $identifier The identifier to be used to get the data
190 * @param string $default The default date to be used if nothing was found in the session
191 * @return string The accordant data in the session of the current backend user
192 */
193 protected function getDataFromSession($identifier, $default = null)
194 {
195 $sessionData = &$this->getBackendUser()->uc['tx_recycler'];
196 if (isset($sessionData[$identifier]) && $sessionData[$identifier]) {
197 $data = $sessionData[$identifier];
198 } else {
199 $data = $default;
200 }
201 return $data;
202 }
203
204 /**
205 * Returns the current BE user.
206 *
207 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
208 */
209 protected function getBackendUser()
210 {
211 return $GLOBALS['BE_USER'];
212 }
213
214 /**
215 * Returns an instance of DocumentTemplate
216 *
217 * @return \TYPO3\CMS\Backend\Template\DocumentTemplate
218 */
219 protected function getDocumentTemplate()
220 {
221 return $GLOBALS['TBE_TEMPLATE'];
222 }
223
224 /**
225 * Returns an instance of LanguageService
226 *
227 * @return \TYPO3\CMS\Core\Localization\LanguageService
228 */
229 protected function getLanguageService()
230 {
231 return $GLOBALS['LANG'];
232 }
233 }