[TASK] Move reload button in recycler to right
[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 = array();
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 * @return void
80 */
81 public function initializeAction()
82 {
83 $this->id = (int)GeneralUtility::_GP('id');
84 $backendUser = $this->getBackendUser();
85 $this->perms_clause = $backendUser->getPagePermsClause(1);
86 $this->pageRecord = \TYPO3\CMS\Backend\Utility\BackendUtility::readPageAccess($this->id, $this->perms_clause);
87 $this->isAccessibleForCurrentUser = $this->id && is_array($this->pageRecord) || !$this->id && $this->isCurrentUserAdmin();
88
89 // don't access in workspace
90 if ($backendUser->workspace !== 0) {
91 $this->isAccessibleForCurrentUser = false;
92 }
93
94 // read configuration
95 $modTS = $backendUser->getTSConfig('mod.recycler');
96 if ($this->isCurrentUserAdmin()) {
97 $this->allowDelete = true;
98 } else {
99 $this->allowDelete = (bool)$modTS['properties']['allowDelete'];
100 }
101
102 if (isset($modTS['properties']['recordsPageLimit']) && intval($modTS['properties']['recordsPageLimit']) > 0) {
103 $this->recordsPageLimit = intval($modTS['properties']['recordsPageLimit']);
104 }
105 }
106
107 /**
108 * Initialize the view
109 *
110 * @param ViewInterface $view The view
111 * @return void
112 */
113 public function initializeView(ViewInterface $view)
114 {
115 /** @var BackendTemplateView $view */
116 parent::initializeView($view);
117 $this->registerDocheaderButtons();
118 $this->view->getModuleTemplate()->setFlashMessageQueue($this->controllerContext->getFlashMessageQueue());
119 }
120
121 /**
122 * Renders the content of the module.
123 *
124 * @return void
125 */
126 public function indexAction()
127 {
128 // Integrate dynamic JavaScript such as configuration or lables:
129 $jsConfiguration = $this->getJavaScriptConfiguration();
130 $this->view->getModuleTemplate()->getPageRenderer()->addInlineSettingArray('Recycler', $jsConfiguration);
131 $this->view->getModuleTemplate()->getPageRenderer()->addInlineLanguageLabelFile('EXT:recycler/Resources/Private/Language/locallang.xlf');
132 if ($this->isAccessibleForCurrentUser) {
133 $this->view->getModuleTemplate()->getDocHeaderComponent()->setMetaInformation($this->pageRecord);
134 }
135
136 $this->view->assign('title', $this->getLanguageService()->getLL('title'));
137 $this->view->assign('allowDelete', $this->allowDelete);
138 }
139
140 /**
141 * Registers the Icons into the docheader
142 *
143 * @return void
144 * @throws \InvalidArgumentException
145 */
146 protected function registerDocheaderButtons()
147 {
148 /** @var ButtonBar $buttonBar */
149 $buttonBar = $this->view->getModuleTemplate()->getDocHeaderComponent()->getButtonBar();
150 $currentRequest = $this->request;
151 $moduleName = $currentRequest->getPluginName();
152 $getVars = $this->request->getArguments();
153
154 $extensionName = $currentRequest->getControllerExtensionName();
155 if (count($getVars) === 0) {
156 $modulePrefix = strtolower('tx_' . $extensionName . '_' . $moduleName);
157 $getVars = array('id', 'M', $modulePrefix);
158 }
159 $shortcutButton = $buttonBar->makeShortcutButton()
160 ->setModuleName($moduleName)
161 ->setGetVariables($getVars);
162 $buttonBar->addButton($shortcutButton);
163
164 $reloadButton = $buttonBar->makeLinkButton()
165 ->setHref('#')
166 ->setDataAttributes(['action' => 'reload'])
167 ->setTitle($this->getLanguageService()->sL('LLL:EXT:recycler/Resources/Private/Language/locallang.xlf:button.reload'))
168 ->setIcon($this->view->getModuleTemplate()->getIconFactory()->getIcon('actions-refresh', Icon::SIZE_SMALL));
169 $buttonBar->addButton($reloadButton, ButtonBar::BUTTON_POSITION_RIGHT);
170 }
171
172 /**
173 * Determines whether the current user is admin.
174 *
175 * @return bool Whether the current user is admin
176 */
177 protected function isCurrentUserAdmin()
178 {
179 return (bool)$this->getBackendUser()->user['admin'];
180 }
181
182 /**
183 * Gets the JavaScript configuration for the Ext JS interface.
184 *
185 * @return array The JavaScript configuration
186 */
187 protected function getJavaScriptConfiguration()
188 {
189 $configuration = array(
190 'pagingSize' => $this->recordsPageLimit,
191 'showDepthMenu' => 1,
192 'startUid' => (int)GeneralUtility::_GP('id'),
193 'isSSL' => GeneralUtility::getIndpEnv('TYPO3_SSL'),
194 'deleteDisable' => !$this->allowDelete,
195 'depthSelection' => $this->getDataFromSession('depthSelection', 0),
196 'tableSelection' => $this->getDataFromSession('tableSelection', ''),
197 'States' => $this->getBackendUser()->uc['moduleData']['web_recycler']['States']
198 );
199 return $configuration;
200 }
201
202 /**
203 * Gets data from the session of the current backend user.
204 *
205 * @param string $identifier The identifier to be used to get the data
206 * @param string $default The default date to be used if nothing was found in the session
207 * @return string The accordant data in the session of the current backend user
208 */
209 protected function getDataFromSession($identifier, $default = null)
210 {
211 $sessionData = &$this->getBackendUser()->uc['tx_recycler'];
212 if (isset($sessionData[$identifier]) && $sessionData[$identifier]) {
213 $data = $sessionData[$identifier];
214 } else {
215 $data = $default;
216 }
217 return $data;
218 }
219
220 /**
221 * Returns the current BE user.
222 *
223 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
224 */
225 protected function getBackendUser()
226 {
227 return $GLOBALS['BE_USER'];
228 }
229
230 /**
231 * Returns an instance of DocumentTemplate
232 *
233 * @return \TYPO3\CMS\Backend\Template\DocumentTemplate
234 */
235 protected function getDocumentTemplate()
236 {
237 return $GLOBALS['TBE_TEMPLATE'];
238 }
239
240 /**
241 * Returns an instance of LanguageService
242 *
243 * @return \TYPO3\CMS\Lang\LanguageService
244 */
245 protected function getLanguageService()
246 {
247 return $GLOBALS['LANG'];
248 }
249 }