‪TYPO3CMS  ‪main
RecyclerModuleController.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Psr\Http\Message\ResponseInterface;
21 use Psr\Http\Message\ServerRequestInterface;
26 use TYPO3\CMS\Backend\Utility\BackendUtility;
29 use TYPO3\CMS\Core\Imaging\IconSize;
34 
40 #[AsController]
42 {
46 
47  public function ‪__construct(
51  ) {
52  $this->iconFactory = ‪$iconFactory;
53  $this->pageRenderer = ‪$pageRenderer;
54  $this->moduleTemplateFactory = ‪$moduleTemplateFactory;
55  }
56 
57  public function ‪handleRequest(ServerRequestInterface $request): ResponseInterface
58  {
59  $backendUser = $this->‪getBackendUser();
60  $id = (int)($request->getQueryParams()['id'] ?? $request->getParsedBody()['id'] ?? 0);
61  $pageRecord = BackendUtility::readPageAccess($id, $backendUser->getPagePermsClause(‪Permission::PAGE_SHOW)) ?: [];
62  $view = $this->moduleTemplateFactory->create($request);
63 
64  // read configuration
65  $recordsPageLimit = ‪MathUtility::forceIntegerInRange((int)($backendUser->getTSConfig()['mod.']['recycler.']['recordsPageLimit'] ?? 25), 1);
66  $allowDelete = $backendUser->isAdmin() || ($backendUser->getTSConfig()['mod.']['recycler.']['allowDelete'] ?? false);
67  $sessionData = $backendUser->uc['tx_recycler'] ?? [];
68 
69  $this->pageRenderer->addInlineSettingArray('Recycler', [
70  'pagingSize' => $recordsPageLimit,
71  'startUid' => $id,
72  'deleteDisable' => !$allowDelete,
73  'depthSelection' => ($sessionData['depthSelection'] ?? false) ?: '0',
74  'tableSelection' => ($sessionData['tableSelection'] ?? false) ?: '',
75  ]);
76  $this->pageRenderer->addInlineLanguageLabelFile('EXT:recycler/Resources/Private/Language/locallang.xlf');
77  $this->pageRenderer->loadJavaScriptModule('@typo3/recycler/recycler.js');
78  $this->pageRenderer->loadJavaScriptModule('@typo3/backend/multi-record-selection.js');
79 
80  if ($backendUser->workspace !== 0
81  && (($id && $pageRecord !== []) || (!$id && $backendUser->isAdmin()))
82  ) {
83  $view->getDocHeaderComponent()->setMetaInformation($pageRecord);
84  }
85 
86  $view->setTitle(
87  $this->‪getLanguageService()->sL('LLL:EXT:recycler/Resources/Private/Language/locallang_mod.xlf:mlang_tabs_tab'),
88  $pageRecord['title'] ?? ''
89  );
90 
91  $this->‪registerDocHeaderButtons($view, $id, $pageRecord);
92 
93  $view->assign('allowDelete', $allowDelete);
94 
95  return $view->renderResponse('RecyclerModule');
96  }
97 
101  protected function ‪registerDocHeaderButtons(‪ModuleTemplate $view, int $id, array $pageRecord): void
102  {
103  $languageService = $this->‪getLanguageService();
104  $buttonBar = $view->‪getDocHeaderComponent()->getButtonBar();
105 
106  $shortcutTitle = sprintf(
107  '%s: %s [%d]',
108  $languageService->sL('LLL:EXT:recycler/Resources/Private/Language/locallang_mod.xlf:mlang_tabs_tab'),
109  BackendUtility::getRecordTitle('pages', $pageRecord),
110  $id
111  );
112  $shortcutButton = $buttonBar->makeShortcutButton()
113  ->setRouteIdentifier('recycler')
114  ->setDisplayName($shortcutTitle)
115  ->setArguments(['id' => $id]);
116  $buttonBar->addButton($shortcutButton);
117 
118  $reloadButton = $buttonBar->makeLinkButton()
119  ->setHref('#')
120  ->setDataAttributes(['action' => 'reload'])
121  ->setTitle($languageService->sL('LLL:EXT:recycler/Resources/Private/Language/locallang.xlf:button.reload'))
122  ->setIcon($this->iconFactory->getIcon('actions-refresh', IconSize::SMALL));
123  $buttonBar->addButton($reloadButton, ‪ButtonBar::BUTTON_POSITION_RIGHT);
124  }
125 
127  {
128  return ‪$GLOBALS['BE_USER'];
129  }
130 
132  {
133  return ‪$GLOBALS['LANG'];
134  }
135 }
‪TYPO3\CMS\Backend\Template\Components\ButtonBar
Definition: ButtonBar.php:33
‪TYPO3\CMS\Backend\Template\ModuleTemplateFactory
Definition: ModuleTemplateFactory.php:33
‪TYPO3\CMS\Recycler\Controller\RecyclerModuleController\getBackendUser
‪getBackendUser()
Definition: RecyclerModuleController.php:126
‪TYPO3\CMS\Recycler\Controller\RecyclerModuleController\getLanguageService
‪getLanguageService()
Definition: RecyclerModuleController.php:131
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:34
‪TYPO3\CMS\Backend\Template\ModuleTemplate
Definition: ModuleTemplate.php:46
‪TYPO3\CMS\Core\Type\Bitmask\Permission
Definition: Permission.php:26
‪TYPO3\CMS\Recycler\Controller
Definition: RecyclerAjaxController.php:18
‪TYPO3\CMS\Recycler\Controller\RecyclerModuleController\registerDocHeaderButtons
‪registerDocHeaderButtons(ModuleTemplate $view, int $id, array $pageRecord)
Definition: RecyclerModuleController.php:101
‪TYPO3\CMS\Recycler\Controller\RecyclerModuleController\$moduleTemplateFactory
‪ModuleTemplateFactory $moduleTemplateFactory
Definition: RecyclerModuleController.php:45
‪TYPO3\CMS\Core\Page\PageRenderer
Definition: PageRenderer.php:44
‪TYPO3\CMS\Recycler\Controller\RecyclerModuleController\handleRequest
‪handleRequest(ServerRequestInterface $request)
Definition: RecyclerModuleController.php:57
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:61
‪TYPO3\CMS\Core\Type\Bitmask\Permission\PAGE_SHOW
‪const PAGE_SHOW
Definition: Permission.php:35
‪TYPO3\CMS\Recycler\Controller\RecyclerModuleController\$iconFactory
‪IconFactory $iconFactory
Definition: RecyclerModuleController.php:43
‪TYPO3\CMS\Recycler\Controller\RecyclerModuleController\__construct
‪__construct(IconFactory $iconFactory, PageRenderer $pageRenderer, ModuleTemplateFactory $moduleTemplateFactory)
Definition: RecyclerModuleController.php:47
‪TYPO3\CMS\Recycler\Controller\RecyclerModuleController\$pageRenderer
‪PageRenderer $pageRenderer
Definition: RecyclerModuleController.php:44
‪TYPO3\CMS\Backend\Template\ModuleTemplate\getDocHeaderComponent
‪getDocHeaderComponent()
Definition: ModuleTemplate.php:181
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Recycler\Controller\RecyclerModuleController
Definition: RecyclerModuleController.php:42
‪TYPO3\CMS\Core\Utility\MathUtility
Definition: MathUtility.php:24
‪TYPO3\CMS\Backend\Attribute\AsController
Definition: AsController.php:25
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:46
‪TYPO3\CMS\Core\Utility\MathUtility\forceIntegerInRange
‪static int forceIntegerInRange(mixed $theInt, int $min, int $max=2000000000, int $defaultValue=0)
Definition: MathUtility.php:34
‪TYPO3\CMS\Backend\Template\Components\ButtonBar\BUTTON_POSITION_RIGHT
‪const BUTTON_POSITION_RIGHT
Definition: ButtonBar.php:42