‪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\Http\Message\ResponseInterface;
21 use Psr\Http\Message\ServerRequestInterface;
29 use TYPO3\CMS\Core\Imaging\IconSize;
36 
42 #[AsController]
44 {
45  public function ‪__construct(
46  private readonly ‪UriBuilder $uriBuilder,
47  private readonly ‪IconFactory $iconFactory,
48  private readonly ‪ModuleTemplateFactory $moduleTemplateFactory,
49  private readonly ‪ReactionRegistry $reactionRegistry,
50  private readonly ‪ReactionRepository $reactionRepository
51  ) {}
52 
53  public function ‪handleRequest(ServerRequestInterface $request): ResponseInterface
54  {
55  $view = $this->moduleTemplateFactory->create($request);
56  $demand = ‪ReactionDemand::fromRequest($request);
57 
58  $this->‪registerDocHeaderButtons($view, $request->getAttribute('normalizedParams')->getRequestUri(), $demand);
59 
60  $reactionRecords = $this->reactionRepository->getReactionRecords($demand);
61  $paginator = new ‪DemandedArrayPaginator($reactionRecords, $demand->getPage(), $demand->getLimit(), $this->reactionRepository->countAll());
62  $pagination = new ‪SimplePagination($paginator);
63 
64  $requestUri = $request->getAttribute('normalizedParams')->getRequestUri();
65  $languageService = $this->‪getLanguageService();
66 
67  return $view->assignMultiple([
68  'demand' => $demand,
69  'reactionTypes' => iterator_to_array($this->reactionRegistry->getAvailableReactionTypes()),
70  'paginator' => $paginator,
71  'pagination' => $pagination,
72  'reactionRecords' => $reactionRecords,
73  'actions' => [
74  new ‪Action(
75  'edit',
76  [
77  'idField' => 'uid',
78  'tableName' => 'sys_reaction',
79  'returnUrl' => $requestUri,
80  ],
81  'actions-open',
82  'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:cm.edit'
83  ),
84  new ‪Action(
85  'delete',
86  [
87  'idField' => 'uid',
88  'tableName' => 'sys_reaction',
89  'title' => $languageService->sL('LLL:EXT:reactions/Resources/Private/Language/locallang_module_reactions.xlf:labels.delete.title'),
90  'content' => $languageService->sL('LLL:EXT:reactions/Resources/Private/Language/locallang_module_reactions.xlf:labels.delete.message'),
91  'ok' => $languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:cm.delete'),
92  'cancel' => $languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.cancel'),
93  'returnUrl' => $requestUri,
94  ],
95  'actions-edit-delete',
96  'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:cm.delete'
97  ),
98  ],
99  ])->renderResponse('Management/Overview');
100  }
101 
102  protected function ‪registerDocHeaderButtons(‪ModuleTemplate $view, string $requestUri, ‪ReactionDemand $demand): void
103  {
104  $languageService = $this->‪getLanguageService();
105  $buttonBar = $view->‪getDocHeaderComponent()->getButtonBar();
106 
107  // Create new
108  $newRecordButton = $buttonBar->makeLinkButton()
109  ->setHref((string)$this->uriBuilder->buildUriFromRoute(
110  'record_edit',
111  [
112  'edit' => ['sys_reaction' => ['new']],
113  'returnUrl' => (string)$this->uriBuilder->buildUriFromRoute('system_reactions'),
114  ]
115  ))
116  ->setShowLabelText(true)
117  ->setTitle($languageService->sL('LLL:EXT:reactions/Resources/Private/Language/locallang_module_reactions.xlf:reaction_create'))
118  ->setIcon($this->iconFactory->getIcon('actions-plus', IconSize::SMALL));
119  $buttonBar->addButton($newRecordButton, ‪ButtonBar::BUTTON_POSITION_LEFT, 10);
120 
121  // Reload
122  $reloadButton = $buttonBar->makeLinkButton()
123  ->setHref($requestUri)
124  ->setTitle($languageService->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.reload'))
125  ->setIcon($this->iconFactory->getIcon('actions-refresh', IconSize::SMALL));
126  $buttonBar->addButton($reloadButton, ‪ButtonBar::BUTTON_POSITION_RIGHT);
127 
128  // Shortcut
129  $shortcutButton = $buttonBar->makeShortcutButton()
130  ->setRouteIdentifier('system_reactions')
131  ->setDisplayName($languageService->sL('LLL:EXT:reactions/Resources/Private/Language/locallang_module_reactions.xlf:mlang_labels_tablabel'))
132  ->setArguments(array_filter([
133  'demand' => $demand->‪getParameters(),
134  'orderField' => $demand->‪getOrderField(),
135  'orderDirection' => $demand->‪getOrderDirection(),
136  ]));
137  $buttonBar->addButton($shortcutButton, ‪ButtonBar::BUTTON_POSITION_RIGHT);
138  }
139 
141  {
142  return ‪$GLOBALS['LANG'];
143  }
144 }
‪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\Reactions\Pagination\DemandedArrayPaginator
Definition: DemandedArrayPaginator.php:27
‪TYPO3\CMS\Backend\Template\ModuleTemplateFactory
Definition: ModuleTemplateFactory.php:33
‪TYPO3\CMS\Reactions\Repository\ReactionDemand\getParameters
‪getParameters()
Definition: ReactionDemand.php:128
‪TYPO3\CMS\Reactions\Repository\ReactionRepository
Definition: ReactionRepository.php:36
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:34
‪TYPO3\CMS\Reactions\Repository\ReactionDemand\getOrderField
‪getOrderField()
Definition: ReactionDemand.php:67
‪TYPO3\CMS\Backend\Template\ModuleTemplate
Definition: ModuleTemplate.php:46
‪TYPO3\CMS\Core\Pagination\SimplePagination
Definition: SimplePagination.php:21
‪TYPO3\CMS\Reactions\Repository\ReactionDemand
Definition: ReactionDemand.php:28
‪TYPO3\CMS\Reactions\Repository\ReactionDemand\fromRequest
‪static fromRequest(ServerRequestInterface $request)
Definition: ReactionDemand.php:53
‪TYPO3\CMS\Reactions\Controller
Definition: ManagementController.php:18
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:44
‪TYPO3\CMS\Reactions\Controller\ManagementController\registerDocHeaderButtons
‪registerDocHeaderButtons(ModuleTemplate $view, string $requestUri, ReactionDemand $demand)
Definition: ManagementController.php:102
‪TYPO3\CMS\Reactions\Repository\ReactionDemand\getOrderDirection
‪getOrderDirection()
Definition: ReactionDemand.php:72
‪TYPO3\CMS\Reactions\Controller\ManagementController\__construct
‪__construct(private readonly UriBuilder $uriBuilder, private readonly IconFactory $iconFactory, private readonly ModuleTemplateFactory $moduleTemplateFactory, private readonly ReactionRegistry $reactionRegistry, private readonly ReactionRepository $reactionRepository)
Definition: ManagementController.php:45
‪TYPO3\CMS\Reactions\ReactionRegistry
Definition: ReactionRegistry.php:28
‪TYPO3\CMS\Backend\Template\ModuleTemplate\getDocHeaderComponent
‪getDocHeaderComponent()
Definition: ModuleTemplate.php:181
‪TYPO3\CMS\Reactions\Controller\ManagementController\getLanguageService
‪getLanguageService()
Definition: ManagementController.php:140
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Backend\Template\Components\MultiRecordSelection\Action
Definition: Action.php:29
‪TYPO3\CMS\Backend\Attribute\AsController
Definition: AsController.php:25
‪TYPO3\CMS\Reactions\Controller\ManagementController
Definition: ManagementController.php:44
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:46
‪TYPO3\CMS\Reactions\Controller\ManagementController\handleRequest
‪handleRequest(ServerRequestInterface $request)
Definition: ManagementController.php:53
‪TYPO3\CMS\Backend\Template\Components\ButtonBar\BUTTON_POSITION_RIGHT
‪const BUTTON_POSITION_RIGHT
Definition: ButtonBar.php:42