TYPO3 CMS  TYPO3_8-7
ShortcutToolbarItem.php
Go to the documentation of this file.
1 <?php
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 
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, '', '&', PHP_QUERY_RFC3986);
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  }
659  return 'failed';
660  }
661 
669  protected function shortcutExists($url)
670  {
671  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
672  ->getQueryBuilderForTable('sys_be_shortcuts');
673  $uid = $queryBuilder->select('uid')
674  ->from('sys_be_shortcuts')
675  ->where(
676  $queryBuilder->expr()->eq(
677  'userid',
678  $queryBuilder->createNamedParameter($this->getBackendUser()->user['uid'], \PDO::PARAM_INT)
679  ),
680  $queryBuilder->expr()->eq('url', $queryBuilder->createNamedParameter($url, \PDO::PARAM_STR))
681  )
682  ->execute()
683  ->fetchColumn();
684 
685  return (bool)$uid;
686  }
687 
696  public function saveFormAction(ServerRequestInterface $request, ResponseInterface $response)
697  {
698  $parsedBody = $request->getParsedBody();
699  $queryParams = $request->getQueryParams();
700 
701  $backendUser = $this->getBackendUser();
702  $shortcutId = (int)(isset($parsedBody['shortcutId']) ? $parsedBody['shortcutId'] : $queryParams['shortcutId']);
703  $shortcutName = strip_tags(isset($parsedBody['shortcutTitle']) ? $parsedBody['shortcutTitle'] : $queryParams['shortcutTitle']);
704  $shortcutGroupId = (int)(isset($parsedBody['shortcutGroup']) ? $parsedBody['shortcutGroup'] : $queryParams['shortcutGroup']);
705 
706  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
707  ->getQueryBuilderForTable('sys_be_shortcuts');
708  $queryBuilder->update('sys_be_shortcuts')
709  ->where(
710  $queryBuilder->expr()->eq(
711  'uid',
712  $queryBuilder->createNamedParameter($shortcutId, \PDO::PARAM_INT)
713  )
714  )
715  ->set('description', $shortcutName)
716  ->set('sc_group', $shortcutGroupId);
717 
718  if (!$backendUser->isAdmin()) {
719  // Users can only modify their own shortcuts
720  $queryBuilder->andWhere(
721  $queryBuilder->expr()->eq(
722  'userid',
723  $queryBuilder->createNamedParameter($backendUser->user['uid'], \PDO::PARAM_INT)
724  )
725  );
726 
727  if ($shortcutGroupId < 0) {
728  $queryBuilder->set('sc_group', 0);
729  }
730  }
731 
732  if ($queryBuilder->execute() === 1) {
733  $response->getBody()->write($shortcutName);
734  } else {
735  $response->getBody()->write('failed');
736  }
737  return $response->withHeader('Content-Type', 'text/html; charset=utf-8');
738  }
739 
746  protected function getShortcutGroupLabel($groupId)
747  {
748  return isset($this->shortcutGroups[$groupId]) ? $this->shortcutGroups[$groupId] : '';
749  }
750 
756  protected function getGlobalShortcutGroups()
757  {
758  $globalGroups = [];
759  foreach ($this->shortcutGroups as $groupId => $groupLabel) {
760  if ($groupId < 0) {
761  $globalGroups[$groupId] = $groupLabel;
762  }
763  }
764  return $globalGroups;
765  }
766 
772  protected function getGroupsFromShortcuts()
773  {
774  $groups = [];
775  foreach ($this->shortcuts as $shortcut) {
776  $groups[$shortcut['group']] = $this->shortcutGroups[$shortcut['group']];
777  }
778  return array_unique($groups);
779  }
780 
789  protected function getShortcutIcon($row, $shortcut)
790  {
791  switch ($row['module_name']) {
792  case 'xMOD_alt_doc.php':
793  $table = $shortcut['table'];
794  $recordid = $shortcut['recordid'];
795  $icon = '';
796  if ($shortcut['type'] === 'edit') {
797  // Creating the list of fields to include in the SQL query:
798  $selectFields = $this->fieldArray;
799  $selectFields[] = 'uid';
800  $selectFields[] = 'pid';
801  if ($table === 'pages') {
802  $selectFields[] = 'module';
803  $selectFields[] = 'extendToSubpages';
804  $selectFields[] = 'doktype';
805  }
806  if (is_array($GLOBALS['TCA'][$table]['ctrl']['enablecolumns'])) {
807  $selectFields = array_merge($selectFields, $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']);
808  }
809  if ($GLOBALS['TCA'][$table]['ctrl']['typeicon_column']) {
810  $selectFields[] = $GLOBALS['TCA'][$table]['ctrl']['typeicon_column'];
811  }
812  if ($GLOBALS['TCA'][$table]['ctrl']['versioningWS']) {
813  $selectFields[] = 't3ver_state';
814  }
815 
816  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
817  ->getQueryBuilderForTable($table);
818  $queryBuilder->select(...array_unique(array_values($selectFields)))
819  ->from($table)
820  ->where(
821  $queryBuilder->expr()->in(
822  'uid',
823  $queryBuilder->createNamedParameter($recordid, \PDO::PARAM_INT)
824  )
825  );
826 
827  if ($table === 'pages' && $this->perms_clause) {
828  $queryBuilder->andWhere(QueryHelper::stripLogicalOperatorPrefix($this->perms_clause));
829  }
830 
831  $row = $queryBuilder->execute()->fetch();
832 
833  $icon = $this->iconFactory->getIconForRecord($table, (array)$row, Icon::SIZE_SMALL)->render();
834  } elseif ($shortcut['type'] === 'new') {
835  $icon = $this->iconFactory->getIconForRecord($table, [], Icon::SIZE_SMALL)->render();
836  }
837  break;
838  case 'file_edit':
839  $icon = $this->iconFactory->getIcon('mimetypes-text-html', Icon::SIZE_SMALL)->render();
840  break;
841  case 'wizard_rte':
842  $icon = $this->iconFactory->getIcon('mimetypes-word', Icon::SIZE_SMALL)->render();
843  break;
844  default:
845  $iconIdentifier = '';
846  $moduleName = $row['module_name'];
847  if (strpos($moduleName, '_') !== false) {
848  list($mainModule, $subModule) = explode('_', $moduleName, 2);
849  $iconIdentifier = $this->moduleLoader->modules[$mainModule]['sub'][$subModule]['iconIdentifier'];
850  } elseif (!empty($moduleName)) {
851  $iconIdentifier = $this->moduleLoader->modules[$moduleName]['iconIdentifier'];
852  }
853  if (!$iconIdentifier) {
854  $iconIdentifier = 'empty-empty';
855  }
856  $icon = $this->iconFactory->getIcon($iconIdentifier, Icon::SIZE_SMALL)->render();
857  }
858 
859  return $icon;
860  }
861 
870  protected function getShortcutIconTitle($shortcutLabel, $moduleName, $parentModuleName = '')
871  {
872  $languageService = $this->getLanguageService();
873  if (substr($moduleName, 0, 5) === 'xMOD_') {
874  $title = substr($moduleName, 5);
875  } else {
876  list($mainModule, $subModule) = explode('_', $moduleName);
877  $mainModuleLabels = $this->moduleLoader->getLabelsForModule($mainModule);
878  $title = $languageService->sL($mainModuleLabels['title']);
879  if (!empty($subModule)) {
880  $subModuleLabels = $this->moduleLoader->getLabelsForModule($moduleName);
881  $title .= '>' . $languageService->sL($subModuleLabels['title']);
882  }
883  }
884  if ($parentModuleName) {
885  $title .= ' (' . $parentModuleName . ')';
886  }
887  $title .= ': ' . $shortcutLabel;
888  return $title;
889  }
890 
897  protected function getLinkedPageId($url)
898  {
899  return preg_replace('/.*[\\?&]id=([^&]+).*/', '$1', $url);
900  }
901 
907  public function getIndex()
908  {
909  return 20;
910  }
911 
917  protected function getBackendUser()
918  {
919  return $GLOBALS['BE_USER'];
920  }
921 
927  protected function getPageRenderer()
928  {
929  return GeneralUtility::makeInstance(PageRenderer::class);
930  }
931 
937  protected function getLanguageService()
938  {
939  return $GLOBALS['LANG'];
940  }
941 
951  protected function getFluidTemplateObject(string $templateFilename): StandaloneView
952  {
953  $view = GeneralUtility::makeInstance(StandaloneView::class);
954  $view->setLayoutRootPaths(['EXT:backend/Resources/Private/Layouts']);
955  $view->setPartialRootPaths(['EXT:backend/Resources/Private/Partials']);
956  $view->setTemplateRootPaths(['EXT:backend/Resources/Private/Templates/ShortcutToolbarItem']);
957 
958  $view->setTemplate($templateFilename);
959 
960  $view->getRequest()->setControllerExtensionName('Backend');
961  return $view;
962  }
963 }
tryAddingTheShortcut(ResponseInterface $response, $url, $shortcutName)
saveFormAction(ServerRequestInterface $request, ResponseInterface $response)
editFormAction(ServerRequestInterface $request, ResponseInterface $response)
static makeInstance($className,... $constructorArguments)
menuAction(ServerRequestInterface $request, ResponseInterface $response)
getShortcutIconTitle($shortcutLabel, $moduleName, $parentModuleName='')
static explodeUrl2Array($string, $multidim=false)
createShortcutAction(ServerRequestInterface $request, ResponseInterface $response)
static stripLogicalOperatorPrefix(string $constraint)
static fixed_lgd_cs($string, $chars, $appendString='...')
removeShortcutAction(ServerRequestInterface $request, ResponseInterface $response)
static getRecord($table, $uid, $fields=' *', $where='', $useDeleteClause=true)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']