TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
ShortcutToolbarItem.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Backend\Backend\ToolbarItems;
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
17 use Psr\Http\Message\ResponseInterface;
18 use Psr\Http\Message\ServerRequestInterface;
33 
38 {
42  const SUPERGLOBAL_GROUP = -100;
43 
47  public $perms_clause;
48 
52  public $fieldArray;
53 
59  protected $shortcuts;
60 
64  protected $shortcutGroups;
65 
72  protected $groupLabels;
73 
77  protected $iconFactory;
78 
82  protected $moduleLoader;
83 
87  public function __construct()
88  {
89  $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
90  $this->getLanguageService()->includeLLFile('EXT:lang/Resources/Private/Language/locallang_misc.xlf');
91  // Needed to get the correct icons when reloading the menu after saving it
92  $this->moduleLoader = GeneralUtility::makeInstance(ModuleLoader::class);
93  $this->moduleLoader->load($GLOBALS['TBE_MODULES']);
94 
95  // By default, 5 groups are set
96  $this->shortcutGroups = [
97  1 => '1',
98  2 => '1',
99  3 => '1',
100  4 => '1',
101  5 => '1'
102  ];
103  $this->shortcutGroups = $this->initShortcutGroups();
104  $this->shortcuts = $this->initShortcuts();
105 
106  $this->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/Toolbar/ShortcutMenu');
107  $languageService = $this->getLanguageService();
108  $this->getPageRenderer()->addInlineLanguageLabelArray([
109  'bookmark.delete' => $languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:toolbarItems.bookmarksDelete'),
110  'bookmark.confirmDelete' => $languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:toolbarItems.confirmBookmarksDelete'),
111  'bookmark.create' => $languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:toolbarItems.createBookmark'),
112  'bookmark.savedTitle' => $languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:toolbarItems.bookmarkSavedTitle'),
113  'bookmark.savedMessage' => $languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:toolbarItems.bookmarkSavedMessage'),
114  ]);
115  }
116 
122  public function checkAccess()
123  {
124  return (bool)$this->getBackendUser()->getTSConfigVal('options.enableBookmarks');
125  }
126 
134  public function getItem()
135  {
136  return $this->getFluidTemplateObject('Item.html')->render();
137  }
138 
146  public function getDropDown()
147  {
148  $shortcutMenu = [];
149  $groups = $this->getGroupsFromShortcuts();
150  arsort($groups, SORT_NUMERIC);
151  foreach ($groups as $groupId => $groupLabel) {
152  $shortcutMenu[] = [
153  'id' => (int)$groupId,
154  'title' => $groupLabel,
155  'shortcuts' => $this->getShortcutsByGroup($groupId)
156  ];
157  }
158 
159  $dropDownView = $this->getFluidTemplateObject('DropDown.html');
160  $dropDownView->assign('shortcutMenu', $shortcutMenu);
161  return $dropDownView->render();
162  }
163 
171  public function menuAction(ServerRequestInterface $request, ResponseInterface $response)
172  {
173  $menuContent = $this->getDropDown();
174 
175  $response->getBody()->write($menuContent);
176  $response = $response->withHeader('Content-Type', 'text/html; charset=utf-8');
177  return $response;
178  }
179 
185  public function getAdditionalAttributes()
186  {
187  return [];
188  }
189 
195  public function hasDropDown()
196  {
197  return true;
198  }
199 
205  protected function initShortcuts()
206  {
207  $backendUser = $this->getBackendUser();
208  // Traverse shortcuts
209  $lastGroup = 0;
210  $shortcuts = [];
211  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
212  ->getQueryBuilderForTable('sys_be_shortcuts');
213  $result = $queryBuilder->select('*')
214  ->from('sys_be_shortcuts')
215  ->where(
216  $queryBuilder->expr()->andX(
217  $queryBuilder->expr()->eq(
218  'userid',
219  $queryBuilder->createNamedParameter($backendUser->user['uid'], \PDO::PARAM_INT)
220  ),
221  $queryBuilder->expr()->gte(
222  'sc_group',
223  $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
224  )
225  )
226  )
227  ->orWhere(
228  $queryBuilder->expr()->in(
229  'sc_group',
230  $queryBuilder->createNamedParameter(
231  array_keys($this->getGlobalShortcutGroups()),
232  Connection::PARAM_INT_ARRAY
233  )
234  )
235  )
236  ->orderBy('sc_group')
237  ->addOrderBy('sorting')
238  ->execute();
239 
240  while ($row = $result->fetch()) {
241  $shortcut = ['raw' => $row];
242 
243  list($row['module_name'], $row['M_module_name']) = explode('|', $row['module_name']);
244 
245  $queryParts = parse_url($row['url']);
246  $queryParameters = GeneralUtility::explodeUrl2Array($queryParts['query'], 1);
247  if ($row['module_name'] === 'xMOD_alt_doc.php' && is_array($queryParameters['edit'])) {
248  $shortcut['table'] = key($queryParameters['edit']);
249  $shortcut['recordid'] = key($queryParameters['edit'][$shortcut['table']]);
250  if ($queryParameters['edit'][$shortcut['table']][$shortcut['recordid']] === 'edit') {
251  $shortcut['type'] = 'edit';
252  } elseif ($queryParameters['edit'][$shortcut['table']][$shortcut['recordid']] === 'new') {
253  $shortcut['type'] = 'new';
254  }
255  if (substr($shortcut['recordid'], -1) === ',') {
256  $shortcut['recordid'] = substr($shortcut['recordid'], 0, -1);
257  }
258  } else {
259  $shortcut['type'] = 'other';
260  }
261  // Check for module access
262  $moduleName = $row['M_module_name'] ?: $row['module_name'];
263 
264  // Check if the user has access to this module
265  if (!is_array($this->moduleLoader->checkMod($moduleName))) {
266  continue;
267  }
268  $pageId = $this->getLinkedPageId($row['url']);
269 
270  if (!$backendUser->isAdmin()) {
272  // Check for webmount access
273  if ($backendUser->isInWebMount($pageId) === null) {
274  continue;
275  }
276  // Check for record access
277  $pageRow = BackendUtility::getRecord('pages', $pageId);
278  if ($pageRow === null) {
279  continue;
280  }
281  if (!$backendUser->doesUserHaveAccess($pageRow, ($perms = 1))) {
282  continue;
283  }
284  }
285  }
286  $moduleParts = explode('_', $moduleName);
287  $shortcutGroup = (int)$row['sc_group'];
288  if ($shortcutGroup && $lastGroup !== $shortcutGroup && $shortcutGroup !== self::SUPERGLOBAL_GROUP) {
289  $shortcut['groupLabel'] = $this->getShortcutGroupLabel($shortcutGroup);
290  }
291  $lastGroup = $shortcutGroup;
292 
293  if ($row['description']) {
294  $shortcut['label'] = $row['description'];
295  } else {
296  $shortcut['label'] = GeneralUtility::fixed_lgd_cs(rawurldecode($queryParts['query']), 150);
297  }
298  $shortcut['group'] = $shortcutGroup;
299  $shortcut['icon'] = $this->getShortcutIcon($row, $shortcut);
300  $shortcut['iconTitle'] = $this->getShortcutIconTitle($shortcut['label'], $row['module_name'], $row['M_module_name']);
301  $shortcut['action'] = 'jump(' . GeneralUtility::quoteJSvalue($this->getTokenUrl($row['url'])) . ',' . GeneralUtility::quoteJSvalue($moduleName) . ',' . GeneralUtility::quoteJSvalue($moduleParts[0]) . ', ' . (int)$pageId . ');';
302 
303  $shortcuts[] = $shortcut;
304  }
305  return $shortcuts;
306  }
307 
314  protected function getTokenUrl($url)
315  {
316  $parsedUrl = parse_url($url);
317  parse_str($parsedUrl['query'], $parameters);
318 
319  // parse the returnUrl and replace the module token of it
320  if (isset($parameters['returnUrl'])) {
321  $parsedReturnUrl = parse_url($parameters['returnUrl']);
322  parse_str($parsedReturnUrl['query'], $returnUrlParameters);
323  if (strpos($parsedReturnUrl['path'], 'index.php') !== false && isset($returnUrlParameters['M'])) {
324  $module = $returnUrlParameters['M'];
325  $returnUrl = BackendUtility::getModuleUrl($module, $returnUrlParameters);
326  $parameters['returnUrl'] = $returnUrl;
327  $url = $parsedUrl['path'] . '?' . http_build_query($parameters);
328  }
329  }
330 
331  if (strpos($parsedUrl['path'], 'index.php') !== false && isset($parameters['M'])) {
332  $module = $parameters['M'];
333  $url = BackendUtility::getModuleUrl($module, $parameters);
334  } elseif (strpos($parsedUrl['path'], 'index.php') !== false && isset($parameters['route'])) {
335  $routePath = $parameters['route'];
337  $router = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\Router::class);
338  try {
339  $route = $router->match($routePath);
340  if ($route) {
341  $routeIdentifier = $route->getOption('_identifier');
343  $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
344  unset($parameters['route']);
345  $url = (string)$uriBuilder->buildUriFromRoute($routeIdentifier, $parameters);
346  }
347  } catch (\TYPO3\CMS\Backend\Routing\Exception\ResourceNotFoundException $e) {
348  $url = '';
349  }
350  }
351  return $url;
352  }
353 
360  protected function getShortcutsByGroup($groupId)
361  {
362  $shortcuts = [];
363  foreach ($this->shortcuts as $shortcut) {
364  if ($shortcut['group'] == $groupId) {
365  $shortcuts[] = $shortcut;
366  }
367  }
368  return $shortcuts;
369  }
370 
377  protected function getShortcutById($shortcutId)
378  {
379  $returnShortcut = false;
380  foreach ($this->shortcuts as $shortcut) {
381  if ($shortcut['raw']['uid'] == (int)$shortcutId) {
382  $returnShortcut = $shortcut;
383  continue;
384  }
385  }
386  return $returnShortcut;
387  }
388 
394  protected function initShortcutGroups()
395  {
396  $languageService = $this->getLanguageService();
397  $backendUser = $this->getBackendUser();
398  // Groups from TSConfig
399  $bookmarkGroups = $backendUser->getTSConfigProp('options.bookmarkGroups');
400  if (is_array($bookmarkGroups) && !empty($bookmarkGroups)) {
401  foreach ($bookmarkGroups as $groupId => $label) {
402  if (!empty($label)) {
403  $this->shortcutGroups[$groupId] = (string)$label;
404  } elseif ($backendUser->isAdmin()) {
405  unset($this->shortcutGroups[$groupId]);
406  }
407  }
408  }
409  // Generate global groups, all global groups have negative IDs.
410  if (!empty($this->shortcutGroups)) {
411  $groups = $this->shortcutGroups;
412  foreach ($groups as $groupId => $groupLabel) {
413  $this->shortcutGroups[$groupId * -1] = $groupLabel;
414  }
415  }
416  // Group -100 is kind of superglobal and can't be changed.
417  $this->shortcutGroups[self::SUPERGLOBAL_GROUP] = 1;
418  // Add labels
419  foreach ($this->shortcutGroups as $groupId => $groupLabel) {
420  $groupId = (int)$groupId;
421  $label = $groupLabel;
422  if ($groupLabel == '1') {
423  $label = htmlspecialchars($languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_misc.xlf:bookmark_group_' . abs($groupId)));
424  if (empty($label)) {
425  // Fallback label
426  $label = htmlspecialchars($languageService->getLL('bookmark_group')) . ' ' . abs($groupId);
427  }
428  }
429  if ($groupId < 0) {
430  // Global group
431  $label = htmlspecialchars($languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_misc.xlf:bookmark_global')) . ': ' . (!empty($label) ? $label : abs($groupId));
432  if ($groupId === self::SUPERGLOBAL_GROUP) {
433  $label = htmlspecialchars($languageService->getLL('bookmark_global')) . ': ' . htmlspecialchars($languageService->getLL('bookmark_all'));
434  }
435  }
436  $this->shortcutGroups[$groupId] = $label;
437  }
438 
439  return $this->shortcutGroups;
440  }
441 
452  public function editFormAction(ServerRequestInterface $request, ResponseInterface $response)
453  {
454  $parsedBody = $request->getParsedBody();
455  $queryParams = $request->getQueryParams();
456 
457  $selectedShortcutId = (int)($parsedBody['shortcutId'] ?? $queryParams['shortcutId']);
458  $selectedShortcutGroupId = (int)($parsedBody['shortcutGroup'] ?? $queryParams['shortcutGroup']);
459  $selectedShortcut = $this->getShortcutById($selectedShortcutId);
461  if (!$this->getBackendUser()->isAdmin()) {
462  foreach ($shortcutGroups as $groupId => $groupName) {
463  if ((int)$groupId < 0) {
464  unset($shortcutGroups[$groupId]);
465  }
466  }
467  }
468 
469  $editFormView = $this->getFluidTemplateObject('EditForm.html');
470  $editFormView->assign('selectedShortcutId', $selectedShortcutId);
471  $editFormView->assign('selectedShortcutGroupId', $selectedShortcutGroupId);
472  $editFormView->assign('selectedShortcut', $selectedShortcut);
473  $editFormView->assign('shortcutGroups', $shortcutGroups);
474 
475  $response->getBody()->write($editFormView->render());
476  return $response->withHeader('Content-Type', 'text/html; charset=utf-8');
477  }
478 
486  public function removeShortcutAction(ServerRequestInterface $request, ResponseInterface $response)
487  {
488  $parsedBody = $request->getParsedBody();
489  $queryParams = $request->getQueryParams();
490 
491  $shortcutId = (int)(isset($parsedBody['shortcutId']) ? $parsedBody['shortcutId'] : $queryParams['shortcutId']);
492  $fullShortcut = $this->getShortcutById($shortcutId);
493  $success = false;
494  if ($fullShortcut['raw']['userid'] == $this->getBackendUser()->user['uid']) {
495  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
496  ->getQueryBuilderForTable('sys_be_shortcuts');
497  $affectedRows = $queryBuilder->delete('sys_be_shortcuts')
498  ->where(
499  $queryBuilder->expr()->eq(
500  'uid',
501  $queryBuilder->createNamedParameter($shortcutId, \PDO::PARAM_INT)
502  )
503  )
504  ->execute();
505  if ($affectedRows === 1) {
506  $success = true;
507  }
508  }
509  $response->getBody()->write(json_encode(['success' => $success]));
510  return $response;
511  }
512 
520  public function createShortcutAction(ServerRequestInterface $request, ResponseInterface $response)
521  {
522  $languageService = $this->getLanguageService();
523  $parsedBody = $request->getParsedBody();
524  $queryParams = $request->getQueryParams();
525 
526  // Default name
527  $shortcutName = 'Shortcut';
528  $shortcutNamePrepend = '';
529  $url = isset($parsedBody['url']) ? $parsedBody['url'] : $queryParams['url'];
530 
531  // Use given display name
532  if (!empty($parsedBody['displayName'])) {
533  $shortcutName = $parsedBody['displayName'];
534  }
535 
536  // Determine shortcut type
537  $url = rawurldecode($url);
538  $queryParts = parse_url($url);
539  $queryParameters = GeneralUtility::explodeUrl2Array($queryParts['query'], true);
540 
541  // Proceed only if no scheme is defined, as URL is expected to be relative
542  if (empty($queryParts['scheme'])) {
543  if (is_array($queryParameters['edit'])) {
544  $shortcut['table'] = key($queryParameters['edit']);
545  $shortcut['recordid'] = key($queryParameters['edit'][$shortcut['table']]);
546  $shortcut['pid'] = BackendUtility::getRecord($shortcut['table'], $shortcut['recordid'])['pid'];
547  if ($queryParameters['edit'][$shortcut['table']][$shortcut['recordid']] == 'edit') {
548  $shortcut['type'] = 'edit';
549  $shortcutNamePrepend = htmlspecialchars($languageService->getLL('shortcut_edit'));
550  } elseif ($queryParameters['edit'][$shortcut['table']][$shortcut['recordid']] == 'new') {
551  $shortcut['type'] = 'new';
552  $shortcutNamePrepend = htmlspecialchars($languageService->getLL('shortcut_create'));
553  }
554  } else {
555  $shortcut['type'] = 'other';
556  $shortcut['table'] = '';
557  $shortcut['recordid'] = 0;
558  }
559 
560  // Check if given id is a combined identifier
561  if (!empty($queryParameters['id']) && preg_match('/^[0-9]+:/', $queryParameters['id'])) {
562  try {
563  $resourceFactory = ResourceFactory::getInstance();
564  $resource = $resourceFactory->getObjectFromCombinedIdentifier($queryParameters['id']);
565  $shortcutName = trim($shortcutNamePrepend . ' ' . $resource->getName());
566  } catch (ResourceDoesNotExistException $e) {
567  }
568  } else {
569  // Lookup the title of this page and use it as default description
570  $pageId = (int)($shortcut['pid'] ?: ($shortcut['recordid'] ?: $this->getLinkedPageId($url)));
571  $page = false;
572  if ($pageId) {
573  $page = BackendUtility::getRecord('pages', $pageId);
574  }
575  if (!empty($page)) {
576  // Set the name to the title of the page
577  if ($shortcut['type'] === 'other') {
578  if (empty($shortcutName)) {
579  $shortcutName = $page['title'];
580  } else {
581  $shortcutName .= ' (' . $page['title'] . ')';
582  }
583  } else {
584  $shortcutName = $shortcutNamePrepend . ' ' .
585  $languageService->sL($GLOBALS['TCA'][$shortcut['table']]['ctrl']['title']) .
586  ' (' . $page['title'] . ')';
587  }
588  } elseif ($shortcut['table'] !== '' && $shortcut['type'] !== 'other') {
589  $shortcutName = $shortcutNamePrepend . ' ' .
590  $languageService->sL($GLOBALS['TCA'][$shortcut['table']]['ctrl']['title']);
591  }
592  }
593 
594  return $this->tryAddingTheShortcut($response, $url, $shortcutName);
595  }
596  }
597 
607  protected function tryAddingTheShortcut(ResponseInterface $response, $url, $shortcutName)
608  {
609  $module = GeneralUtility::_POST('module');
610  $shortcutCreated = 'failed';
611 
612  if (!empty($module) && !empty($url)) {
613  $shortcutCreated = 'alreadyExists';
614 
615  if (!BackendUtility::shortcutExists($url) && !is_array($module)) {
616  $shortcutCreated = $this->addShortcut($url, $shortcutName, $module);
617  }
618  }
619 
620  $response->getBody()->write($shortcutCreated);
621  return $response->withHeader('Content-Type', 'text/html; charset=utf-8');
622  }
623 
633  protected function addShortcut($url, $shortcutName, $module)
634  {
635  $moduleLabels = $this->moduleLoader->getLabelsForModule($module);
636  if ($shortcutName === 'Shortcut' && !empty($moduleLabels['shortdescription'])) {
637  $shortcutName = $this->getLanguageService()->sL($moduleLabels['shortdescription']);
638  }
639 
640  $motherModule = GeneralUtility::_POST('motherModName');
641  $fieldValues = [
642  'userid' => $this->getBackendUser()->user['uid'],
643  'module_name' => $module . '|' . $motherModule,
644  'url' => $url,
645  'description' => $shortcutName,
646  'sorting' => $GLOBALS['EXEC_TIME']
647  ];
648 
649  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
650  ->getQueryBuilderForTable('sys_be_shortcuts');
651  $affectedRows = $queryBuilder
652  ->insert('sys_be_shortcuts')
653  ->values($fieldValues)
654  ->execute();
655 
656  if ($affectedRows === 1) {
657  return 'success';
658  } else {
659  return 'failed';
660  }
661  }
662 
670  protected function shortcutExists($url)
671  {
672  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
673  ->getQueryBuilderForTable('sys_be_shortcuts');
674  $uid = $queryBuilder->select('uid')
675  ->from('sys_be_shortcuts')
676  ->where(
677  $queryBuilder->expr()->eq(
678  'userid',
679  $queryBuilder->createNamedParameter($this->getBackendUser()->user['uid'], \PDO::PARAM_INT)
680  ),
681  $queryBuilder->expr()->eq('url', $queryBuilder->createNamedParameter($url, \PDO::PARAM_STR))
682  )
683  ->execute()
684  ->fetchColumn();
685 
686  return (bool)$uid;
687  }
688 
697  public function saveFormAction(ServerRequestInterface $request, ResponseInterface $response)
698  {
699  $parsedBody = $request->getParsedBody();
700  $queryParams = $request->getQueryParams();
701 
702  $backendUser = $this->getBackendUser();
703  $shortcutId = (int)(isset($parsedBody['shortcutId']) ? $parsedBody['shortcutId'] : $queryParams['shortcutId']);
704  $shortcutName = strip_tags(isset($parsedBody['shortcutTitle']) ? $parsedBody['shortcutTitle'] : $queryParams['shortcutTitle']);
705  $shortcutGroupId = (int)(isset($parsedBody['shortcutGroup']) ? $parsedBody['shortcutGroup'] : $queryParams['shortcutGroup']);
706 
707  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
708  ->getQueryBuilderForTable('sys_be_shortcuts');
709  $queryBuilder->update('sys_be_shortcuts')
710  ->where(
711  $queryBuilder->expr()->eq(
712  'uid',
713  $queryBuilder->createNamedParameter($shortcutId, \PDO::PARAM_INT)
714  )
715  )
716  ->set('description', $shortcutName)
717  ->set('sc_group', $shortcutGroupId);
718 
719  if (!$backendUser->isAdmin()) {
720  // Users can only modify their own shortcuts
721  $queryBuilder->andWhere(
722  $queryBuilder->expr()->eq(
723  'userid',
724  $queryBuilder->createNamedParameter($backendUser->user['uid'], \PDO::PARAM_INT)
725  )
726  );
727 
728  if ($shortcutGroupId < 0) {
729  $queryBuilder->set('sc_group', 0);
730  }
731  }
732 
733  if ($queryBuilder->execute() === 1) {
734  $response->getBody()->write($shortcutName);
735  } else {
736  $response->getBody()->write('failed');
737  }
738  return $response->withHeader('Content-Type', 'text/html; charset=utf-8');
739  }
740 
747  protected function getShortcutGroupLabel($groupId)
748  {
749  return isset($this->shortcutGroups[$groupId]) ? $this->shortcutGroups[$groupId] : '';
750  }
751 
757  protected function getGlobalShortcutGroups()
758  {
759  $globalGroups = [];
760  foreach ($this->shortcutGroups as $groupId => $groupLabel) {
761  if ($groupId < 0) {
762  $globalGroups[$groupId] = $groupLabel;
763  }
764  }
765  return $globalGroups;
766  }
767 
773  protected function getGroupsFromShortcuts()
774  {
775  $groups = [];
776  foreach ($this->shortcuts as $shortcut) {
777  $groups[$shortcut['group']] = $this->shortcutGroups[$shortcut['group']];
778  }
779  return array_unique($groups);
780  }
781 
790  protected function getShortcutIcon($row, $shortcut)
791  {
792  switch ($row['module_name']) {
793  case 'xMOD_alt_doc.php':
794  $table = $shortcut['table'];
795  $recordid = $shortcut['recordid'];
796  $icon = '';
797  if ($shortcut['type'] === 'edit') {
798  // Creating the list of fields to include in the SQL query:
799  $selectFields = $this->fieldArray;
800  $selectFields[] = 'uid';
801  $selectFields[] = 'pid';
802  if ($table === 'pages') {
803  $selectFields[] = 'module';
804  $selectFields[] = 'extendToSubpages';
805  $selectFields[] = 'doktype';
806  }
807  if (is_array($GLOBALS['TCA'][$table]['ctrl']['enablecolumns'])) {
808  $selectFields = array_merge($selectFields, $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']);
809  }
810  if ($GLOBALS['TCA'][$table]['ctrl']['type']) {
811  $selectFields[] = $GLOBALS['TCA'][$table]['ctrl']['type'];
812  }
813  if ($GLOBALS['TCA'][$table]['ctrl']['typeicon_column']) {
814  $selectFields[] = $GLOBALS['TCA'][$table]['ctrl']['typeicon_column'];
815  }
816  if ($GLOBALS['TCA'][$table]['ctrl']['versioningWS']) {
817  $selectFields[] = 't3ver_state';
818  }
819 
820  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
821  ->getQueryBuilderForTable($table);
822  $queryBuilder->select(...array_unique(array_values($selectFields)))
823  ->from($table)
824  ->where(
825  $queryBuilder->expr()->in(
826  'uid',
827  $queryBuilder->createNamedParameter($recordid, \PDO::PARAM_INT)
828  )
829  );
830 
831  if ($table === 'pages' && $this->perms_clause) {
832  $queryBuilder->andWhere(QueryHelper::stripLogicalOperatorPrefix($this->perms_clause));
833  }
834 
835  $row = $queryBuilder->execute()->fetch();
836 
837  $icon = $this->iconFactory->getIconForRecord($table, (array)$row, Icon::SIZE_SMALL)->render();
838  } elseif ($shortcut['type'] === 'new') {
839  $icon = $this->iconFactory->getIconForRecord($table, [], Icon::SIZE_SMALL)->render();
840  }
841  break;
842  case 'file_edit':
843  $icon = $this->iconFactory->getIcon('mimetypes-text-html', Icon::SIZE_SMALL)->render();
844  break;
845  case 'wizard_rte':
846  $icon = $this->iconFactory->getIcon('mimetypes-word', Icon::SIZE_SMALL)->render();
847  break;
848  default:
849  $iconIdentifier = '';
850  $moduleName = $row['module_name'];
851  if (strpos($moduleName, '_') !== false) {
852  list($mainModule, $subModule) = explode('_', $moduleName, 2);
853  $iconIdentifier = $this->moduleLoader->modules[$mainModule]['sub'][$subModule]['iconIdentifier'];
854  } elseif (!empty($moduleName)) {
855  $iconIdentifier = $this->moduleLoader->modules[$moduleName]['iconIdentifier'];
856  }
857  if (!$iconIdentifier) {
858  $iconIdentifier = 'empty-empty';
859  }
860  $icon = $this->iconFactory->getIcon($iconIdentifier, Icon::SIZE_SMALL)->render();
861  }
862 
863  return $icon;
864  }
865 
874  protected function getShortcutIconTitle($shortcutLabel, $moduleName, $parentModuleName = '')
875  {
876  $languageService = $this->getLanguageService();
877  if (substr($moduleName, 0, 5) == 'xMOD_') {
878  $title = substr($moduleName, 5);
879  } else {
880  list($mainModule, $subModule) = explode('_', $moduleName);
881  $mainModuleLabels = $this->moduleLoader->getLabelsForModule($mainModule);
882  $title = $languageService->sL($mainModuleLabels['title']);
883  if (!empty($subModule)) {
884  $subModuleLabels = $this->moduleLoader->getLabelsForModule($moduleName);
885  $title .= '>' . $languageService->sL($subModuleLabels['title']);
886  }
887  }
888  if ($parentModuleName) {
889  $title .= ' (' . $parentModuleName . ')';
890  }
891  $title .= ': ' . $shortcutLabel;
892  return $title;
893  }
894 
901  protected function getLinkedPageId($url)
902  {
903  return preg_replace('/.*[\\?&]id=([^&]+).*/', '$1', $url);
904  }
905 
911  public function getIndex()
912  {
913  return 20;
914  }
915 
921  protected function getBackendUser()
922  {
923  return $GLOBALS['BE_USER'];
924  }
925 
931  protected function getPageRenderer()
932  {
933  return GeneralUtility::makeInstance(PageRenderer::class);
934  }
935 
941  protected function getLanguageService()
942  {
943  return $GLOBALS['LANG'];
944  }
945 
955  protected function getFluidTemplateObject(string $templateFilename)
956  {
958  $view = GeneralUtility::makeInstance(StandaloneView::class);
959  $view->setLayoutRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Layouts')]);
960  $view->setPartialRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Partials')]);
961  $view->setTemplateRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates')]);
962 
963  $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates/ShortcutToolbarItem/' . $templateFilename));
964 
965  $view->getRequest()->setControllerExtensionName('Backend');
966  return $view;
967  }
968 }
saveFormAction(ServerRequestInterface $request, ResponseInterface $response)
removeShortcutAction(ServerRequestInterface $request, ResponseInterface $response)
static explodeUrl2Array($string, $multidim=false)
editFormAction(ServerRequestInterface $request, ResponseInterface $response)
static getRecord($table, $uid, $fields= '*', $where= '', $useDeleteClause=true)
createShortcutAction(ServerRequestInterface $request, ResponseInterface $response)
menuAction(ServerRequestInterface $request, ResponseInterface $response)
if(TYPO3_MODE=== 'BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
static makeInstance($className,...$constructorArguments)
static stripLogicalOperatorPrefix(string $constraint)
static getFileAbsFileName($filename, $_=null, $_2=null)
tryAddingTheShortcut(ResponseInterface $response, $url, $shortcutName)
getShortcutIconTitle($shortcutLabel, $moduleName, $parentModuleName= '')