‪TYPO3CMS  ‪main
ManagementController.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\EventDispatcher\EventDispatcherInterface;
21 use Psr\Http\Message\ResponseInterface;
22 use Psr\Http\Message\ServerRequestInterface;
31 use TYPO3\CMS\Core\Imaging\IconSize;
38 
44 #[AsController]
46 {
47  public function ‪__construct(
48  protected ‪UriBuilder $uriBuilder,
49  protected ‪IconFactory $iconFactory,
50  protected ‪RedirectRepository $redirectRepository,
51  protected ‪ModuleTemplateFactory $moduleTemplateFactory,
52  private EventDispatcherInterface $eventDispatcher,
53  ) {}
54 
58  public function ‪handleRequest(ServerRequestInterface $request): ResponseInterface
59  {
60  $view = $this->moduleTemplateFactory->create($request);
61  $demand = ‪Demand::fromRequest($request);
62 
63  $view->setTitle(
64  $this->‪getLanguageService()->sL('LLL:EXT:redirects/Resources/Private/Language/locallang_module_redirect.xlf:mlang_tabs_tab')
65  );
66  $this->‪registerDocHeaderButtons($view, $request->getAttribute('normalizedParams')->getRequestUri());
67 
68  $event = $this->eventDispatcher->dispatch(
70  $demand,
71  $this->redirectRepository->findRedirectsByDemand($demand),
72  $this->redirectRepository->findHostsOfRedirects(),
73  $this->redirectRepository->findStatusCodesOfRedirects(),
74  $this->redirectRepository->findCreationTypes(),
75  GeneralUtility::makeInstance(Features::class)->isFeatureEnabled('redirects.hitCount'),
76  $view,
77  $request,
78  $this->redirectRepository->findIntegrityStatusCodes(),
79  )
80  );
81  $requestUri = $request->getAttribute('normalizedParams')->getRequestUri();
82  $languageService = $this->‪getLanguageService();
83  $view = $event->getView();
84  $view->assignMultiple([
85  'redirects' => $event->getRedirects(),
86  'hosts' => $event->getHosts(),
87  'statusCodes' => $event->getStatusCodes(),
88  'creationTypes' => $event->getCreationTypes(),
89  'integrityStatusCodes' => $event->getIntegrityStatusCodes(),
90  'defaultIntegrityStatus' => ‪RedirectConflict::NO_CONFLICT,
91  'demand' => $event->getDemand(),
92  'showHitCounter' => $event->getShowHitCounter(),
93  'pagination' => $this->preparePagination($event->getDemand()),
94  'actions' => [
95  new ‪Action(
96  'edit',
97  [
98  'idField' => 'uid',
99  'tableName' => 'sys_redirect',
100  'returnUrl' => $requestUri,
101  ],
102  'actions-open',
103  'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:cm.edit'
104  ),
105  new ‪Action(
106  'delete',
107  [
108  'idField' => 'uid',
109  'tableName' => 'sys_redirect',
110  'title' => $languageService->sL('LLL:EXT:redirects/Resources/Private/Language/locallang_module_reactions.xlf:labels.delete.title'),
111  'content' => $languageService->sL('LLL:EXT:redirects/Resources/Private/Language/locallang_module_reactions.xlf:labels.delete.message'),
112  'ok' => $languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:cm.delete'),
113  'cancel' => $languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.cancel'),
114  'returnUrl' => $requestUri,
115  ],
116  'actions-edit-delete',
117  'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:cm.delete'
118  ),
119  ],
120  ]);
121  return $view->renderResponse('Management/Overview');
122  }
123 
127  protected function ‪preparePagination(‪Demand $demand): array
128  {
129  $count = $this->redirectRepository->countRedirectsByByDemand($demand);
130  $numberOfPages = ceil($count / $demand->‪getLimit());
131  $endRecord = $demand->‪getOffset() + $demand->‪getLimit();
132  if ($endRecord > $count) {
133  $endRecord = $count;
134  }
135 
136  $pagination = [
137  'current' => $demand->‪getPage(),
138  'numberOfPages' => $numberOfPages,
139  'hasLessPages' => $demand->‪getPage() > 1,
140  'hasMorePages' => $demand->‪getPage() < $numberOfPages,
141  'startRecord' => $demand->‪getOffset() + 1,
142  'endRecord' => $endRecord,
143  ];
144  if ($pagination['current'] < $pagination['numberOfPages']) {
145  $pagination['nextPage'] = $pagination['current'] + 1;
146  }
147  if ($pagination['current'] > 1) {
148  $pagination['previousPage'] = $pagination['current'] - 1;
149  }
150  return $pagination;
151  }
152 
156  protected function ‪registerDocHeaderButtons(‪ModuleTemplate $view, string $requestUri): void
157  {
158  $languageService = $this->‪getLanguageService();
159  $buttonBar = $view->‪getDocHeaderComponent()->getButtonBar();
160 
161  // Create new
162  $newRecordButton = $buttonBar->makeLinkButton()
163  ->setHref((string)$this->uriBuilder->buildUriFromRoute(
164  'record_edit',
165  [
166  'edit' => ['sys_redirect' => ['new'],
167  ],
168  'returnUrl' => (string)$this->uriBuilder->buildUriFromRoute('site_redirects'),
169  ]
170  ))
171  ->setTitle($languageService->sL('LLL:EXT:redirects/Resources/Private/Language/locallang_module_redirect.xlf:redirect_add_text'))
172  ->setShowLabelText(true)
173  ->setIcon($this->iconFactory->getIcon('actions-plus', IconSize::SMALL));
174  $buttonBar->addButton($newRecordButton, ‪ButtonBar::BUTTON_POSITION_LEFT, 10);
175 
176  // Reload
177  $reloadButton = $buttonBar->makeLinkButton()
178  ->setHref($requestUri)
179  ->setTitle($languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.reload'))
180  ->setIcon($this->iconFactory->getIcon('actions-refresh', IconSize::SMALL));
181  $buttonBar->addButton($reloadButton, ‪ButtonBar::BUTTON_POSITION_RIGHT);
182 
183  // Shortcut
184  $shortcutButton = $buttonBar->makeShortcutButton()
185  ->setRouteIdentifier('site_redirects')
186  ->setDisplayName($languageService->sL('LLL:EXT:redirects/Resources/Private/Language/locallang_module_redirect.xlf:mlang_labels_tablabel'));
187  $buttonBar->addButton($shortcutButton, ‪ButtonBar::BUTTON_POSITION_RIGHT);
188  }
189 
191  {
192  return ‪$GLOBALS['LANG'];
193  }
194 }
‪TYPO3\CMS\Redirects\Repository\Demand
Definition: Demand.php:29
‪TYPO3\CMS\Redirects\Repository\Demand\getOffset
‪getOffset()
Definition: Demand.php:296
‪TYPO3\CMS\Redirects\Controller\ManagementController\preparePagination
‪preparePagination(Demand $demand)
Definition: ManagementController.php:127
‪TYPO3\CMS\Backend\Template\Components\ButtonBar\BUTTON_POSITION_LEFT
‪const BUTTON_POSITION_LEFT
Definition: ButtonBar.php:37
‪TYPO3\CMS\Backend\Template\Components\ButtonBar
Definition: ButtonBar.php:33
‪TYPO3\CMS\Redirects\Utility\RedirectConflict
Definition: RedirectConflict.php:24
‪TYPO3\CMS\Redirects\Repository\Demand\fromRequest
‪static fromRequest(ServerRequestInterface $request)
Definition: Demand.php:94
‪TYPO3\CMS\Backend\Template\ModuleTemplateFactory
Definition: ModuleTemplateFactory.php:33
‪TYPO3\CMS\Redirects\Controller\ManagementController\__construct
‪__construct(protected UriBuilder $uriBuilder, protected IconFactory $iconFactory, protected RedirectRepository $redirectRepository, protected ModuleTemplateFactory $moduleTemplateFactory, private EventDispatcherInterface $eventDispatcher,)
Definition: ManagementController.php:47
‪TYPO3\CMS\Redirects\Controller\ManagementController\getLanguageService
‪getLanguageService()
Definition: ManagementController.php:190
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:34
‪TYPO3\CMS\Redirects\Controller\ManagementController\handleRequest
‪handleRequest(ServerRequestInterface $request)
Definition: ManagementController.php:58
‪TYPO3\CMS\Backend\Template\ModuleTemplate
Definition: ModuleTemplate.php:46
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:44
‪TYPO3\CMS\Core\Configuration\Features
Definition: Features.php:56
‪TYPO3\CMS\Redirects\Repository\Demand\getLimit
‪getLimit()
Definition: Demand.php:208
‪TYPO3\CMS\Redirects\Repository\RedirectRepository
Definition: RedirectRepository.php:31
‪TYPO3\CMS\Redirects\Utility\RedirectConflict\NO_CONFLICT
‪const NO_CONFLICT
Definition: RedirectConflict.php:25
‪TYPO3\CMS\Backend\Template\ModuleTemplate\getDocHeaderComponent
‪getDocHeaderComponent()
Definition: ModuleTemplate.php:181
‪TYPO3\CMS\Redirects\Repository\Demand\getPage
‪getPage()
Definition: Demand.php:288
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Redirects\Event\ModifyRedirectManagementControllerViewDataEvent
Definition: ModifyRedirectManagementControllerViewDataEvent.php:31
‪TYPO3\CMS\Backend\Template\Components\MultiRecordSelection\Action
Definition: Action.php:29
‪TYPO3\CMS\Backend\Attribute\AsController
Definition: AsController.php:25
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:46
‪TYPO3\CMS\Redirects\Controller\ManagementController
Definition: ManagementController.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Redirects\Controller\ManagementController\registerDocHeaderButtons
‪registerDocHeaderButtons(ModuleTemplate $view, string $requestUri)
Definition: ManagementController.php:156
‪TYPO3\CMS\Redirects\Controller
Definition: ManagementController.php:18
‪TYPO3\CMS\Backend\Template\Components\ButtonBar\BUTTON_POSITION_RIGHT
‪const BUTTON_POSITION_RIGHT
Definition: ButtonBar.php:42