‪TYPO3CMS  9.5
ShortcutController.php
Go to the documentation of this file.
1 <?php
2 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 
18 use Psr\Http\Message\ResponseInterface;
19 use Psr\Http\Message\ServerRequestInterface;
29 
35 {
39  protected ‪$shortcutToolbarItem;
40 
44  protected ‪$shortcutRepository;
45 
49  protected ‪$moduleLoader;
50 
54  public function ‪__construct()
55  {
56  $this->shortcutToolbarItem = GeneralUtility::makeInstance(ShortcutToolbarItem::class);
57  $this->shortcutRepository = GeneralUtility::makeInstance(ShortcutRepository::class);
58  // Needed to get the correct icons when reloading the menu after saving it
59  $this->moduleLoader = GeneralUtility::makeInstance(ModuleLoader::class);
60  $this->moduleLoader->load(‪$GLOBALS['TBE_MODULES']);
61  }
62 
68  public function ‪menuAction(): ResponseInterface
69  {
70  return new ‪HtmlResponse($this->shortcutToolbarItem->getDropDown());
71  }
72 
79  public function ‪addAction(ServerRequestInterface $request): ResponseInterface
80  {
81  $result = 'success';
82  $parsedBody = $request->getParsedBody();
83  $queryParams = $request->getQueryParams();
84  $url = rawurldecode($parsedBody['url'] ?? $queryParams['url'] ?? '');
85 
86  if ($this->shortcutRepository->shortcutExists($url)) {
87  $result = 'alreadyExists';
88  } else {
89  $moduleName = $parsedBody['module'] ?? '';
90  $parentModuleName = $parsedBody['motherModName'] ?? '';
91  $shortcutName = $parsedBody['displayName'] ?? '';
92  $success = $this->shortcutRepository->addShortcut($url, $moduleName, $parentModuleName, $shortcutName);
93 
94  if (!$success) {
95  $result = 'failed';
96  }
97  }
98 
99  return new ‪HtmlResponse($result);
100  }
101 
108  public function ‪showEditFormAction(ServerRequestInterface $request): ResponseInterface
109  {
110  $parsedBody = $request->getParsedBody();
111  $queryParams = $request->getQueryParams();
112 
113  $selectedShortcutId = (int)($parsedBody['shortcutId'] ?? $queryParams['shortcutId']);
114  $selectedShortcutGroupId = (int)($parsedBody['shortcutGroup'] ?? $queryParams['shortcutGroup']);
115  $selectedShortcut = $this->shortcutRepository->getShortcutById($selectedShortcutId);
116  $shortcutGroups = $this->shortcutRepository->getShortcutGroups();
117 
118  $editFormView = $this->‪getFluidTemplateObject('EditForm.html');
119  $editFormView->assign('selectedShortcutId', $selectedShortcutId);
120  $editFormView->assign('selectedShortcutGroupId', $selectedShortcutGroupId);
121  $editFormView->assign('selectedShortcut', $selectedShortcut);
122  $editFormView->assign('shortcutGroups', $shortcutGroups);
123 
124  return new ‪HtmlResponse($editFormView->render());
125  }
126 
134  public function ‪updateAction(ServerRequestInterface $request): ResponseInterface
135  {
136  $parsedBody = $request->getParsedBody();
137  $queryParams = $request->getQueryParams();
138  $shortcutId = (int)($parsedBody['shortcutId'] ?? $queryParams['shortcutId'] ?? 0);
139  $shortcutTitle = strip_tags($parsedBody['shortcutTitle'] ?? $queryParams['shortcutTitle'] ?? '');
140  $shortcutGroupId = (int)($parsedBody['shortcutGroup'] ?? $queryParams['shortcutGroup'] ?? 0);
141 
142  $success = $this->shortcutRepository->updateShortcut($shortcutId, $shortcutTitle, $shortcutGroupId);
143 
144  return new ‪HtmlResponse($success ? $shortcutTitle : 'failed');
145  }
146 
153  public function ‪removeAction(ServerRequestInterface $request): ResponseInterface
154  {
155  $parsedBody = $request->getParsedBody();
156  $queryParams = $request->getQueryParams();
157  $shortcutId = (int)($parsedBody['shortcutId'] ?? $queryParams['shortcutId'] ?? 0);
158  $success = $this->shortcutRepository->removeShortcut($shortcutId);
159 
160  return new ‪JsonResponse(['success' => $success]);
161  }
162 
172  protected function ‪getFluidTemplateObject(string $templateFilename): ‪StandaloneView
173  {
174  $view = GeneralUtility::makeInstance(StandaloneView::class);
175  $view->setLayoutRootPaths(['EXT:backend/Resources/Private/Layouts']);
176  $view->setPartialRootPaths(['EXT:backend/Resources/Private/Partials']);
177  $view->setTemplateRootPaths(['EXT:backend/Resources/Private/Templates/ShortcutToolbarItem']);
178  $view->setTemplate($templateFilename);
179  $view->getRequest()->setControllerExtensionName('Backend');
180 
181  return $view;
182  }
183 
187  protected function ‪getBackendUser(): ‪BackendUserAuthentication
188  {
189  return ‪$GLOBALS['BE_USER'];
190  }
191 
195  protected function ‪getLanguageService(): ‪LanguageService
196  {
197  return ‪$GLOBALS['LANG'];
198  }
199 }
‪TYPO3\CMS\Backend\Backend\Shortcut\ShortcutRepository
Definition: ShortcutRepository.php:41
‪TYPO3\CMS\Backend\Controller\ShortcutController
Definition: ShortcutController.php:35
‪TYPO3\CMS\Backend\Controller\ShortcutController\getFluidTemplateObject
‪StandaloneView getFluidTemplateObject(string $templateFilename)
Definition: ShortcutController.php:169
‪TYPO3\CMS\Backend\Controller\ShortcutController\getBackendUser
‪BackendUserAuthentication getBackendUser()
Definition: ShortcutController.php:184
‪TYPO3\CMS\Backend\Controller\ShortcutController\$shortcutRepository
‪ShortcutRepository $shortcutRepository
Definition: ShortcutController.php:42
‪TYPO3\CMS\Backend\Controller\ShortcutController\menuAction
‪ResponseInterface menuAction()
Definition: ShortcutController.php:65
‪TYPO3\CMS\Backend\Controller\ShortcutController\showEditFormAction
‪ResponseInterface showEditFormAction(ServerRequestInterface $request)
Definition: ShortcutController.php:105
‪TYPO3\CMS\Backend\Controller\ShortcutController\$shortcutToolbarItem
‪ShortcutToolbarItem $shortcutToolbarItem
Definition: ShortcutController.php:38
‪TYPO3\CMS\Backend\Controller\ShortcutController\$moduleLoader
‪ModuleLoader $moduleLoader
Definition: ShortcutController.php:46
‪TYPO3\CMS\Backend\Module\ModuleLoader
Definition: ModuleLoader.php:32
‪TYPO3\CMS\Backend\Controller\ShortcutController\updateAction
‪ResponseInterface updateAction(ServerRequestInterface $request)
Definition: ShortcutController.php:131
‪TYPO3\CMS\Backend\Backend\ToolbarItems\ShortcutToolbarItem
Definition: ShortcutToolbarItem.php:29
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:45
‪TYPO3\CMS\Backend\Controller\ShortcutController\__construct
‪__construct()
Definition: ShortcutController.php:51
‪TYPO3\CMS\Backend\Controller\ShortcutController\getLanguageService
‪LanguageService getLanguageService()
Definition: ShortcutController.php:192
‪TYPO3\CMS\Fluid\View\StandaloneView
Definition: StandaloneView.php:32
‪TYPO3\CMS\Core\Http\JsonResponse
Definition: JsonResponse.php:25
‪$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:150
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:29
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Backend\Controller
Definition: AbstractFormEngineAjaxController.php:3
‪TYPO3\CMS\Backend\Controller\ShortcutController\addAction
‪ResponseInterface addAction(ServerRequestInterface $request)
Definition: ShortcutController.php:76
‪TYPO3\CMS\Core\Http\HtmlResponse
Definition: HtmlResponse.php:25