‪TYPO3CMS  10.4
RecyclerModuleController.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
18 use Psr\Http\Message\ResponseInterface;
19 use Psr\Http\Message\ServerRequestInterface;
32 
38 {
39 
43  protected ‪$pageRecord = [];
44 
48  protected ‪$isAccessibleForCurrentUser = false;
49 
53  protected ‪$allowDelete = false;
54 
58  protected ‪$recordsPageLimit = 50;
59 
63  protected ‪$id;
64 
68  protected ‪$view;
69 
73  protected ‪$moduleTemplate;
74 
81  public function ‪handleRequest(ServerRequestInterface $request): ResponseInterface
82  {
83  $this->id = (int)($request->getQueryParams()['id'] ?? $request->getParsedBody()['id'] ?? 0);
84  $backendUser = $this->‪getBackendUser();
85  $this->pageRecord = ‪BackendUtility::readPageAccess($this->id, $backendUser->getPagePermsClause(‪Permission::PAGE_SHOW));
86  $this->isAccessibleForCurrentUser = $this->id && is_array($this->pageRecord) || !$this->id && $this->‪getBackendUser()->‪isAdmin();
87  $this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
88 
89  // don't access in workspace
90  if ($backendUser->workspace !== 0) {
91  $this->isAccessibleForCurrentUser = false;
92  }
93 
94  // read configuration
95  if ($backendUser->isAdmin()) {
96  $this->allowDelete = true;
97  } else {
98  $this->allowDelete = (bool)($backendUser->getTSConfig()['mod.']['recycler.']['allowDelete'] ?? false);
99  }
100 
101  $this->recordsPageLimit = ‪MathUtility::forceIntegerInRange(
102  (int)($backendUser->getTSConfig()['mod.']['recycler.']['recordsPageLimit'] ?? 25),
103  1
104  );
105 
106  $action = 'index';
107  $this->‪initializeView($action);
108 
109  $result = call_user_func_array([$this, $action . 'Action'], [$request]);
110  if ($result instanceof ResponseInterface) {
111  return $result;
112  }
113 
115 
116  $this->moduleTemplate->setContent($this->view->render());
117  return new ‪HtmlResponse($this->moduleTemplate->renderContent());
118  }
119 
123  protected function ‪initializeView(string $templateName)
124  {
125  $this->view = GeneralUtility::makeInstance(StandaloneView::class);
126  $this->view->setTemplate($templateName);
127  $this->view->setTemplateRootPaths(['EXT:recycler/Resources/Private/Templates/RecyclerModule']);
128  $this->view->setPartialRootPaths(['EXT:recycler/Resources/Private/Partials']);
129  $this->view->setLayoutRootPaths(['EXT:recycler/Resources/Private/Layouts']);
130  $this->view->getRequest()->setControllerExtensionName('Recycler');
131  }
132 
138  public function ‪indexAction(ServerRequestInterface $request)
139  {
140  $this->moduleTemplate->getPageRenderer()->addInlineSettingArray('Recycler', $this->‪getJavaScriptConfiguration($request->getAttribute('normalizedParams')));
141  $this->moduleTemplate->getPageRenderer()->addInlineLanguageLabelFile('EXT:recycler/Resources/Private/Language/locallang.xlf');
142  if ($this->isAccessibleForCurrentUser) {
143  $this->moduleTemplate->getDocHeaderComponent()->setMetaInformation($this->pageRecord);
144  }
145 
146  $this->view->assign('allowDelete', $this->allowDelete);
147  }
148 
154  protected function ‪registerDocheaderButtons()
155  {
156  $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
157 
158  $shortcutButton = $buttonBar->makeShortcutButton()
159  ->setModuleName('web_recycler')
160  ->setGetVariables(['id', 'route']);
161  $buttonBar->addButton($shortcutButton);
162 
163  $reloadButton = $buttonBar->makeLinkButton()
164  ->setHref('#')
165  ->setDataAttributes(['action' => 'reload'])
166  ->setTitle($this->‪getLanguageService()->sL('LLL:EXT:recycler/Resources/Private/Language/locallang.xlf:button.reload'))
167  ->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-refresh', ‪Icon::SIZE_SMALL));
168  $buttonBar->addButton($reloadButton, ‪ButtonBar::BUTTON_POSITION_RIGHT);
169  }
170 
177  protected function ‪getJavaScriptConfiguration(‪NormalizedParams $normalizedParams): array
178  {
179  return [
180  'pagingSize' => ‪$this->recordsPageLimit,
181  'showDepthMenu' => true,
182  'startUid' => ‪$this->id,
183  'isSSL' => $normalizedParams->‪isHttps(),
184  'deleteDisable' => !‪$this->allowDelete,
185  'depthSelection' => $this->‪getDataFromSession('depthSelection', '0'),
186  'tableSelection' => $this->‪getDataFromSession('tableSelection', ''),
187  'States' => $this->‪getBackendUser()->uc['moduleData']['web_recycler']['States']
188  ];
189  }
190 
198  protected function ‪getDataFromSession($identifier, $default = null)
199  {
200  $sessionData = &$this->‪getBackendUser()->uc['tx_recycler'];
201  if (isset($sessionData[$identifier]) && $sessionData[$identifier]) {
202  $data = $sessionData[$identifier];
203  } else {
204  $data = $default;
205  }
206  return $data;
207  }
208 
214  protected function ‪getBackendUser(): ‪BackendUserAuthentication
215  {
216  return ‪$GLOBALS['BE_USER'];
217  }
218 
224  protected function ‪getLanguageService(): ‪LanguageService
225  {
226  return ‪$GLOBALS['LANG'];
227  }
228 }
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_SMALL
‪const SIZE_SMALL
Definition: Icon.php:30
‪TYPO3\CMS\Backend\Template\Components\ButtonBar
Definition: ButtonBar.php:32
‪TYPO3\CMS\Recycler\Controller\RecyclerModuleController\registerDocheaderButtons
‪registerDocheaderButtons()
Definition: RecyclerModuleController.php:147
‪TYPO3\CMS\Recycler\Controller\RecyclerModuleController\$view
‪StandaloneView $view
Definition: RecyclerModuleController.php:62
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:26
‪TYPO3\CMS\Recycler\Controller\RecyclerModuleController\getBackendUser
‪BackendUserAuthentication getBackendUser()
Definition: RecyclerModuleController.php:207
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\isAdmin
‪bool isAdmin()
Definition: BackendUserAuthentication.php:292
‪TYPO3\CMS\Core\Utility\MathUtility\forceIntegerInRange
‪static int forceIntegerInRange($theInt, $min, $max=2000000000, $defaultValue=0)
Definition: MathUtility.php:32
‪TYPO3\CMS\Recycler\Controller\RecyclerModuleController\getLanguageService
‪LanguageService getLanguageService()
Definition: RecyclerModuleController.php:217
‪TYPO3\CMS\Recycler\Controller\RecyclerModuleController\getJavaScriptConfiguration
‪array getJavaScriptConfiguration(NormalizedParams $normalizedParams)
Definition: RecyclerModuleController.php:170
‪TYPO3\CMS\Recycler\Controller\RecyclerModuleController\initializeView
‪initializeView(string $templateName)
Definition: RecyclerModuleController.php:116
‪TYPO3\CMS\Backend\Template\ModuleTemplate
Definition: ModuleTemplate.php:43
‪TYPO3\CMS\Core\Type\Bitmask\Permission
Definition: Permission.php:24
‪TYPO3\CMS\Recycler\Controller
Definition: DeletedRecordsController.php:16
‪TYPO3\CMS\Recycler\Controller\RecyclerModuleController\handleRequest
‪ResponseInterface handleRequest(ServerRequestInterface $request)
Definition: RecyclerModuleController.php:74
‪TYPO3\CMS\Recycler\Controller\RecyclerModuleController\$allowDelete
‪bool $allowDelete
Definition: RecyclerModuleController.php:50
‪TYPO3\CMS\Recycler\Controller\RecyclerModuleController\$id
‪int $id
Definition: RecyclerModuleController.php:58
‪TYPO3\CMS\Recycler\Controller\RecyclerModuleController\indexAction
‪indexAction(ServerRequestInterface $request)
Definition: RecyclerModuleController.php:131
‪TYPO3\CMS\Recycler\Controller\RecyclerModuleController\$recordsPageLimit
‪int $recordsPageLimit
Definition: RecyclerModuleController.php:54
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Core\Type\Bitmask\Permission\PAGE_SHOW
‪const PAGE_SHOW
Definition: Permission.php:33
‪TYPO3\CMS\Recycler\Controller\RecyclerModuleController\$moduleTemplate
‪ModuleTemplate $moduleTemplate
Definition: RecyclerModuleController.php:66
‪TYPO3\CMS\Core\Http\NormalizedParams\isHttps
‪bool isHttps()
Definition: NormalizedParams.php:333
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:75
‪TYPO3\CMS\Recycler\Controller\RecyclerModuleController\getDataFromSession
‪string getDataFromSession($identifier, $default=null)
Definition: RecyclerModuleController.php:191
‪TYPO3\CMS\Backend\Utility\BackendUtility\readPageAccess
‪static array false readPageAccess($id, $perms_clause)
Definition: BackendUtility.php:597
‪TYPO3\CMS\Fluid\View\StandaloneView
Definition: StandaloneView.php:34
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Recycler\Controller\RecyclerModuleController
Definition: RecyclerModuleController.php:38
‪TYPO3\CMS\Core\Utility\MathUtility
Definition: MathUtility.php:22
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Backend\Template\Components\ButtonBar\BUTTON_POSITION_RIGHT
‪const BUTTON_POSITION_RIGHT
Definition: ButtonBar.php:41
‪TYPO3\CMS\Recycler\Controller\RecyclerModuleController\$isAccessibleForCurrentUser
‪bool $isAccessibleForCurrentUser
Definition: RecyclerModuleController.php:46
‪TYPO3\CMS\Recycler\Controller\RecyclerModuleController\$pageRecord
‪array $pageRecord
Definition: RecyclerModuleController.php:42
‪TYPO3\CMS\Core\Http\NormalizedParams
Definition: NormalizedParams.php:35
‪TYPO3\CMS\Core\Http\HtmlResponse
Definition: HtmlResponse.php:26