‪TYPO3CMS  10.4
ShortcutController.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;
31 
37 {
41  protected ‪$shortcutToolbarItem;
42 
46  protected ‪$shortcutRepository;
47 
51  protected ‪$moduleLoader;
52 
56  public function ‪__construct()
57  {
58  $this->shortcutToolbarItem = GeneralUtility::makeInstance(ShortcutToolbarItem::class);
59  $this->shortcutRepository = GeneralUtility::makeInstance(ShortcutRepository::class);
60  // Needed to get the correct icons when reloading the menu after saving it
61  $this->moduleLoader = GeneralUtility::makeInstance(ModuleLoader::class);
62  $this->moduleLoader->load(‪$GLOBALS['TBE_MODULES']);
63  }
64 
70  public function ‪menuAction(): ResponseInterface
71  {
72  return new ‪HtmlResponse($this->shortcutToolbarItem->getDropDown());
73  }
74 
81  public function ‪addAction(ServerRequestInterface $request): ResponseInterface
82  {
83  $result = 'success';
84  $parsedBody = $request->getParsedBody();
85  $queryParams = $request->getQueryParams();
86  $url = rawurldecode($parsedBody['url'] ?? $queryParams['url'] ?? '');
87 
88  if ($this->shortcutRepository->shortcutExists($url)) {
89  $result = 'alreadyExists';
90  } else {
91  $moduleName = $parsedBody['module'] ?? '';
92  $parentModuleName = $parsedBody['motherModName'] ?? '';
93  $shortcutName = $parsedBody['displayName'] ?? '';
94  $success = $this->shortcutRepository->addShortcut($url, $moduleName, $parentModuleName, $shortcutName);
95 
96  if (!$success) {
97  $result = 'failed';
98  }
99  }
100 
101  return new ‪HtmlResponse($result);
102  }
103 
110  public function ‪showEditFormAction(ServerRequestInterface $request): ResponseInterface
111  {
112  $parsedBody = $request->getParsedBody();
113  $queryParams = $request->getQueryParams();
114 
115  $selectedShortcutId = (int)($parsedBody['shortcutId'] ?? $queryParams['shortcutId']);
116  $selectedShortcutGroupId = (int)($parsedBody['shortcutGroup'] ?? $queryParams['shortcutGroup']);
117  $selectedShortcut = $this->shortcutRepository->getShortcutById($selectedShortcutId);
118  $shortcutGroups = $this->shortcutRepository->getShortcutGroups();
119 
120  $editFormView = $this->‪getFluidTemplateObject('EditForm.html');
121  $editFormView->assign('selectedShortcutId', $selectedShortcutId);
122  $editFormView->assign('selectedShortcutGroupId', $selectedShortcutGroupId);
123  $editFormView->assign('selectedShortcut', $selectedShortcut);
124  $editFormView->assign('shortcutGroups', $shortcutGroups);
125 
126  return new ‪HtmlResponse($editFormView->render());
127  }
128 
136  public function ‪updateAction(ServerRequestInterface $request): ResponseInterface
137  {
138  $parsedBody = $request->getParsedBody();
139  $queryParams = $request->getQueryParams();
140  $shortcutId = (int)($parsedBody['shortcutId'] ?? $queryParams['shortcutId'] ?? 0);
141  $shortcutTitle = strip_tags($parsedBody['shortcutTitle'] ?? $queryParams['shortcutTitle'] ?? '');
142  $shortcutGroupId = (int)($parsedBody['shortcutGroup'] ?? $queryParams['shortcutGroup'] ?? 0);
143 
144  $success = $this->shortcutRepository->updateShortcut($shortcutId, $shortcutTitle, $shortcutGroupId);
145 
146  return new ‪HtmlResponse($success ? $shortcutTitle : 'failed');
147  }
148 
155  public function ‪removeAction(ServerRequestInterface $request): ResponseInterface
156  {
157  $parsedBody = $request->getParsedBody();
158  $queryParams = $request->getQueryParams();
159  $shortcutId = (int)($parsedBody['shortcutId'] ?? $queryParams['shortcutId'] ?? 0);
160  $success = $this->shortcutRepository->removeShortcut($shortcutId);
161 
162  return new ‪JsonResponse(['success' => $success]);
163  }
164 
174  protected function ‪getFluidTemplateObject(string $templateFilename): ‪StandaloneView
175  {
176  $view = GeneralUtility::makeInstance(StandaloneView::class);
177  $view->setLayoutRootPaths(['EXT:backend/Resources/Private/Layouts']);
178  $view->setPartialRootPaths(['EXT:backend/Resources/Private/Partials']);
179  $view->setTemplateRootPaths(['EXT:backend/Resources/Private/Templates/ShortcutToolbarItem']);
180  $view->setTemplate($templateFilename);
181  $view->getRequest()->setControllerExtensionName('Backend');
182 
183  return $view;
184  }
185 
189  protected function ‪getBackendUser(): ‪BackendUserAuthentication
190  {
191  return ‪$GLOBALS['BE_USER'];
192  }
193 
197  protected function ‪getLanguageService(): ‪LanguageService
198  {
199  return ‪$GLOBALS['LANG'];
200  }
201 }
‪TYPO3\CMS\Backend\Backend\Shortcut\ShortcutRepository
Definition: ShortcutRepository.php:44
‪TYPO3\CMS\Backend\Controller\ShortcutController
Definition: ShortcutController.php:37
‪TYPO3\CMS\Backend\Controller\ShortcutController\getFluidTemplateObject
‪StandaloneView getFluidTemplateObject(string $templateFilename)
Definition: ShortcutController.php:171
‪TYPO3\CMS\Backend\Controller\ShortcutController\getBackendUser
‪BackendUserAuthentication getBackendUser()
Definition: ShortcutController.php:186
‪TYPO3\CMS\Backend\Controller\ShortcutController\$shortcutRepository
‪ShortcutRepository $shortcutRepository
Definition: ShortcutController.php:44
‪TYPO3\CMS\Backend\Controller\ShortcutController\menuAction
‪ResponseInterface menuAction()
Definition: ShortcutController.php:67
‪TYPO3\CMS\Backend\Controller\ShortcutController\showEditFormAction
‪ResponseInterface showEditFormAction(ServerRequestInterface $request)
Definition: ShortcutController.php:107
‪TYPO3\CMS\Backend\Controller\ShortcutController\$shortcutToolbarItem
‪ShortcutToolbarItem $shortcutToolbarItem
Definition: ShortcutController.php:40
‪TYPO3\CMS\Backend\Controller\ShortcutController\$moduleLoader
‪ModuleLoader $moduleLoader
Definition: ShortcutController.php:48
‪TYPO3\CMS\Backend\Module\ModuleLoader
Definition: ModuleLoader.php:34
‪TYPO3\CMS\Backend\Controller\ShortcutController\updateAction
‪ResponseInterface updateAction(ServerRequestInterface $request)
Definition: ShortcutController.php:133
‪TYPO3\CMS\Backend\Backend\ToolbarItems\ShortcutToolbarItem
Definition: ShortcutToolbarItem.php:30
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Backend\Controller\ShortcutController\__construct
‪__construct()
Definition: ShortcutController.php:53
‪TYPO3\CMS\Backend\Controller\ShortcutController\getLanguageService
‪LanguageService getLanguageService()
Definition: ShortcutController.php:194
‪TYPO3\CMS\Fluid\View\StandaloneView
Definition: StandaloneView.php:34
‪TYPO3\CMS\Core\Http\JsonResponse
Definition: JsonResponse.php:26
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Backend\Controller\ShortcutController\removeAction
‪ResponseInterface removeAction(ServerRequestInterface $request)
Definition: ShortcutController.php:152
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Backend\Controller
Definition: AbstractFormEngineAjaxController.php:18
‪TYPO3\CMS\Backend\Controller\ShortcutController\addAction
‪ResponseInterface addAction(ServerRequestInterface $request)
Definition: ShortcutController.php:78
‪TYPO3\CMS\Core\Http\HtmlResponse
Definition: HtmlResponse.php:26