‪TYPO3CMS  9.5
RecyclerModuleController.php
Go to the documentation of this file.
1 <?php
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 Psr\Http\Message\ResponseInterface;
18 use Psr\Http\Message\ServerRequestInterface;
31 
37 {
38 
42  protected ‪$pageRecord = [];
43 
47  protected ‪$isAccessibleForCurrentUser = false;
48 
52  protected ‪$allowDelete = false;
53 
57  protected ‪$recordsPageLimit = 50;
58 
62  protected ‪$id;
63 
67  protected ‪$view;
68 
72  protected ‪$moduleTemplate;
73 
80  public function ‪handleRequest(ServerRequestInterface $request): ResponseInterface
81  {
82  $this->id = (int)($request->getQueryParams()['id'] ?? $request->getParsedBody()['id'] ?? 0);
83  $backendUser = $this->‪getBackendUser();
84  $this->pageRecord = ‪BackendUtility::readPageAccess($this->id, $backendUser->getPagePermsClause(‪Permission::PAGE_SHOW));
85  $this->isAccessibleForCurrentUser = $this->id && is_array($this->pageRecord) || !$this->id && $this->‪getBackendUser()->‪isAdmin();
86  $this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
87 
88  // don't access in workspace
89  if ($backendUser->workspace !== 0) {
90  $this->isAccessibleForCurrentUser = false;
91  }
92 
93  // read configuration
94  if ($backendUser->isAdmin()) {
95  $this->allowDelete = true;
96  } else {
97  $this->allowDelete = (bool)($backendUser->getTSConfig()['mod.']['recycler.']['allowDelete'] ?? false);
98  }
99 
100  $this->recordsPageLimit = ‪MathUtility::forceIntegerInRange(
101  (int)($backendUser->getTSConfig()['mod.']['recycler.']['recordsPageLimit'] ?? 25),
102  1
103  );
104 
105  $action = 'index';
106  $this->‪initializeView($action);
107 
108  $result = call_user_func_array([$this, $action . 'Action'], [$request]);
109  if ($result instanceof ResponseInterface) {
110  return $result;
111  }
112 
114 
115  $this->moduleTemplate->setContent($this->view->render());
116  return new ‪HtmlResponse($this->moduleTemplate->renderContent());
117  }
118 
122  protected function ‪initializeView(string $templateName)
123  {
124  $this->view = GeneralUtility::makeInstance(StandaloneView::class);
125  $this->view->setTemplate($templateName);
126  $this->view->setTemplateRootPaths(['EXT:recycler/Resources/Private/Templates/RecyclerModule']);
127  $this->view->setPartialRootPaths(['EXT:recycler/Resources/Private/Partials']);
128  $this->view->setLayoutRootPaths(['EXT:recycler/Resources/Private/Layouts']);
129  $this->view->getRequest()->setControllerExtensionName('Recycler');
130  }
131 
137  public function ‪indexAction(ServerRequestInterface $request)
138  {
139  $this->moduleTemplate->getPageRenderer()->addInlineSettingArray('Recycler', $this->‪getJavaScriptConfiguration($request->getAttribute('normalizedParams')));
140  $this->moduleTemplate->getPageRenderer()->addInlineLanguageLabelFile('EXT:recycler/Resources/Private/Language/locallang.xlf');
141  if ($this->isAccessibleForCurrentUser) {
142  $this->moduleTemplate->getDocHeaderComponent()->setMetaInformation($this->pageRecord);
143  }
144 
145  $this->view->assign('allowDelete', $this->allowDelete);
146  }
147 
153  protected function ‪registerDocheaderButtons()
154  {
155  $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
156 
157  $shortcutButton = $buttonBar->makeShortcutButton()
158  ->setModuleName('web_recycler')
159  ->setGetVariables(['id', 'route']);
160  $buttonBar->addButton($shortcutButton);
161 
162  $reloadButton = $buttonBar->makeLinkButton()
163  ->setHref('#')
164  ->setDataAttributes(['action' => 'reload'])
165  ->setTitle($this->‪getLanguageService()->sL('LLL:EXT:recycler/Resources/Private/Language/locallang.xlf:button.reload'))
166  ->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-refresh', ‪Icon::SIZE_SMALL));
167  $buttonBar->addButton($reloadButton, ‪ButtonBar::BUTTON_POSITION_RIGHT);
168  }
169 
176  protected function ‪getJavaScriptConfiguration(‪NormalizedParams $normalizedParams): array
177  {
178  return [
179  'pagingSize' => ‪$this->recordsPageLimit,
180  'showDepthMenu' => true,
181  'startUid' => ‪$this->id,
182  'isSSL' => $normalizedParams->‪isHttps(),
183  'deleteDisable' => !‪$this->allowDelete,
184  'depthSelection' => $this->‪getDataFromSession('depthSelection', 0),
185  'tableSelection' => $this->‪getDataFromSession('tableSelection', ''),
186  'States' => $this->‪getBackendUser()->uc['moduleData']['web_recycler']['States']
187  ];
188  }
189 
197  protected function ‪getDataFromSession($identifier, $default = null)
198  {
199  $sessionData = &$this->‪getBackendUser()->uc['tx_recycler'];
200  if (isset($sessionData[$identifier]) && $sessionData[$identifier]) {
201  $data = $sessionData[$identifier];
202  } else {
203  $data = $default;
204  }
205  return $data;
206  }
207 
213  protected function ‪getBackendUser(): ‪BackendUserAuthentication
214  {
215  return ‪$GLOBALS['BE_USER'];
216  }
217 
223  protected function ‪getLanguageService(): ‪LanguageService
224  {
225  return ‪$GLOBALS['LANG'];
226  }
227 }
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_SMALL
‪const SIZE_SMALL
Definition: Icon.php:29
‪TYPO3\CMS\Backend\Template\Components\ButtonBar
Definition: ButtonBar.php:31
‪TYPO3\CMS\Recycler\Controller\RecyclerModuleController\registerDocheaderButtons
‪registerDocheaderButtons()
Definition: RecyclerModuleController.php:146
‪TYPO3\CMS\Recycler\Controller\RecyclerModuleController\$view
‪StandaloneView $view
Definition: RecyclerModuleController.php:61
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:25
‪TYPO3\CMS\Recycler\Controller\RecyclerModuleController\getBackendUser
‪BackendUserAuthentication getBackendUser()
Definition: RecyclerModuleController.php:206
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\isAdmin
‪bool isAdmin()
Definition: BackendUserAuthentication.php:294
‪TYPO3\CMS\Core\Utility\MathUtility\forceIntegerInRange
‪static int forceIntegerInRange($theInt, $min, $max=2000000000, $defaultValue=0)
Definition: MathUtility.php:31
‪TYPO3\CMS\Recycler\Controller\RecyclerModuleController\getLanguageService
‪LanguageService getLanguageService()
Definition: RecyclerModuleController.php:216
‪TYPO3\CMS\Recycler\Controller\RecyclerModuleController\getJavaScriptConfiguration
‪array getJavaScriptConfiguration(NormalizedParams $normalizedParams)
Definition: RecyclerModuleController.php:169
‪TYPO3\CMS\Recycler\Controller\RecyclerModuleController\initializeView
‪initializeView(string $templateName)
Definition: RecyclerModuleController.php:115
‪TYPO3\CMS\Backend\Template\ModuleTemplate
Definition: ModuleTemplate.php:40
‪TYPO3\CMS\Core\Type\Bitmask\Permission
Definition: Permission.php:23
‪TYPO3\CMS\Recycler\Controller
Definition: DeletedRecordsController.php:3
‪TYPO3\CMS\Recycler\Controller\RecyclerModuleController\handleRequest
‪ResponseInterface handleRequest(ServerRequestInterface $request)
Definition: RecyclerModuleController.php:73
‪TYPO3\CMS\Recycler\Controller\RecyclerModuleController\$allowDelete
‪bool $allowDelete
Definition: RecyclerModuleController.php:49
‪TYPO3\CMS\Recycler\Controller\RecyclerModuleController\$id
‪int $id
Definition: RecyclerModuleController.php:57
‪TYPO3\CMS\Recycler\Controller\RecyclerModuleController\indexAction
‪indexAction(ServerRequestInterface $request)
Definition: RecyclerModuleController.php:130
‪TYPO3\CMS\Recycler\Controller\RecyclerModuleController\$recordsPageLimit
‪int $recordsPageLimit
Definition: RecyclerModuleController.php:53
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:45
‪TYPO3\CMS\Core\Type\Bitmask\Permission\PAGE_SHOW
‪const PAGE_SHOW
Definition: Permission.php:32
‪TYPO3\CMS\Recycler\Controller\RecyclerModuleController\$moduleTemplate
‪ModuleTemplate $moduleTemplate
Definition: RecyclerModuleController.php:65
‪TYPO3\CMS\Core\Http\NormalizedParams\isHttps
‪bool isHttps()
Definition: NormalizedParams.php:310
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:72
‪TYPO3\CMS\Recycler\Controller\RecyclerModuleController\getDataFromSession
‪string getDataFromSession($identifier, $default=null)
Definition: RecyclerModuleController.php:190
‪TYPO3\CMS\Fluid\View\StandaloneView
Definition: StandaloneView.php:32
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Recycler\Controller\RecyclerModuleController
Definition: RecyclerModuleController.php:37
‪TYPO3\CMS\Core\Utility\MathUtility
Definition: MathUtility.php:21
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:29
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Backend\Template\Components\ButtonBar\BUTTON_POSITION_RIGHT
‪const BUTTON_POSITION_RIGHT
Definition: ButtonBar.php:40
‪TYPO3\CMS\Recycler\Controller\RecyclerModuleController\$isAccessibleForCurrentUser
‪bool $isAccessibleForCurrentUser
Definition: RecyclerModuleController.php:45
‪TYPO3\CMS\Recycler\Controller\RecyclerModuleController\$pageRecord
‪array $pageRecord
Definition: RecyclerModuleController.php:41
‪TYPO3\CMS\Core\Http\NormalizedParams
Definition: NormalizedParams.php:32
‪TYPO3\CMS\Core\Http\HtmlResponse
Definition: HtmlResponse.php:25
‪TYPO3\CMS\Backend\Utility\BackendUtility\readPageAccess
‪static array bool readPageAccess($id, $perms_clause)
Definition: BackendUtility.php:635