ShortcutRepository.php 25.5 KB
Newer Older
1
<?php
2

3
declare(strict_types=1);
4
5
6
7
8
9
10
11
12
13
14
15
16
17

/*
 * This file is part of the TYPO3 CMS project.
 *
 * It is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License, either version 2
 * of the License, or any later version.
 *
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
 *
 * The TYPO3 project - inspiring people to share!
 */

18
19
namespace TYPO3\CMS\Backend\Backend\Shortcut;

20
use Symfony\Component\Routing\Route;
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use TYPO3\CMS\Backend\Module\ModuleLoader;
use TYPO3\CMS\Backend\Routing\Router;
use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException;
use TYPO3\CMS\Core\Resource\ResourceFactory;
use TYPO3\CMS\Core\Type\Bitmask\Permission;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
 * Repository for backend shortcuts
38
39
 *
 * @internal This class is a specific Backend implementation and is not considered part of the Public TYPO3 API.
40
41
42
43
44
45
46
47
 */
class ShortcutRepository
{
    /**
     * @var int Number of super global (All) group
     */
    protected const SUPERGLOBAL_GROUP = -100;

48
    protected const TABLE_NAME = 'sys_be_shortcuts';
49

50
    protected array $shortcuts;
51

52
    protected array $shortcutGroups;
53

54
    protected ConnectionPool $connectionPool;
55

56
57
58
59
60
    protected IconFactory $iconFactory;

    protected ModuleLoader $moduleLoader;

    public function __construct(ConnectionPool $connectionPool, IconFactory $iconFactory, ModuleLoader $moduleLoader)
61
    {
62
63
64
        $this->connectionPool = $connectionPool;
        $this->iconFactory = $iconFactory;
        $this->moduleLoader = $moduleLoader;
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
        $this->moduleLoader->load($GLOBALS['TBE_MODULES']);

        $this->shortcutGroups = $this->initShortcutGroups();
        $this->shortcuts = $this->initShortcuts();
    }

    /**
     * Gets a shortcut by its uid
     *
     * @param int $shortcutId Shortcut id to get the complete shortcut for
     * @return mixed An array containing the shortcut's data on success or FALSE on failure
     */
    public function getShortcutById(int $shortcutId)
    {
        foreach ($this->shortcuts as $shortcut) {
            if ($shortcut['raw']['uid'] === $shortcutId) {
                return $shortcut;
            }
        }

        return false;
    }

    /**
     * Gets shortcuts for a specific group
     *
     * @param int $groupId Group Id
     * @return array Array of shortcuts that matched the group
     */
    public function getShortcutsByGroup(int $groupId): array
    {
        $shortcuts = [];

        foreach ($this->shortcuts as $shortcut) {
            if ($shortcut['group'] === $groupId) {
                $shortcuts[] = $shortcut;
            }
        }

        return $shortcuts;
    }

    /**
     * Get shortcut groups the current user has access to
     *
     * @return array
     */
    public function getShortcutGroups(): array
    {
        $shortcutGroups = $this->shortcutGroups;

        if (!$this->getBackendUser()->isAdmin()) {
            foreach ($shortcutGroups as $groupId => $groupName) {
                if ((int)$groupId < 0) {
                    unset($shortcutGroups[$groupId]);
                }
            }
        }

        return $shortcutGroups;
    }

    /**
128
     * runs through the available shortcuts and collects their groups
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
     *
     * @return array Array of groups which have shortcuts
     */
    public function getGroupsFromShortcuts(): array
    {
        $groups = [];

        foreach ($this->shortcuts as $shortcut) {
            $groups[$shortcut['group']] = $this->shortcutGroups[$shortcut['group']];
        }

        return array_unique($groups);
    }

    /**
     * Returns if there already is a shortcut entry for a given TYPO3 URL
     *
146
147
     * @param string $routeIdentifier
     * @param string $arguments
148
149
     * @return bool
     */
150
    public function shortcutExists(string $routeIdentifier, string $arguments): bool
151
    {
152
        $queryBuilder = $this->connectionPool->getQueryBuilderForTable(self::TABLE_NAME);
153
154
155
        $queryBuilder->getRestrictions()->removeAll();

        $uid = $queryBuilder->select('uid')
156
            ->from(self::TABLE_NAME)
157
158
159
160
161
            ->where(
                $queryBuilder->expr()->eq(
                    'userid',
                    $queryBuilder->createNamedParameter($this->getBackendUser()->user['uid'], \PDO::PARAM_INT)
                ),
162
163
                $queryBuilder->expr()->eq('route', $queryBuilder->createNamedParameter($routeIdentifier)),
                $queryBuilder->expr()->eq('arguments', $queryBuilder->createNamedParameter($arguments))
164
165
166
167
168
169
170
171
172
173
            )
            ->execute()
            ->fetchColumn();

        return (bool)$uid;
    }

    /**
     * Add a shortcut
     *
174
175
     * @param string $routeIdentifier route identifier of the new shortcut
     * @param string $arguments arguments of the new shortcut
176
177
178
179
     * @param string $title title of the new shortcut
     * @return bool
     * @throws \RuntimeException if the given URL is invalid
     */
180
    public function addShortcut(string $routeIdentifier, string $arguments = '', string $title = ''): bool
181
    {
182
183
        // Do not add shortcuts for routes which do not exist
        if (!$this->routeExists($routeIdentifier)) {
184
185
186
187
188
            return false;
        }

        $languageService = $this->getLanguageService();

189
190
191
        // Only apply "magic" if title is not set
        // @todo This is deprecated and can be removed in v12
        if ($title === '') {
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
            $queryParameters = json_decode($arguments, true);
            $titlePrefix = '';
            $type = 'other';
            $table = '';
            $recordId = 0;
            $pageId = 0;

            if ($queryParameters && is_array($queryParameters['edit'])) {
                $table = (string)key($queryParameters['edit']);
                $recordId = (int)key($queryParameters['edit'][$table]);
                $pageId = (int)BackendUtility::getRecord($table, $recordId)['pid'];
                $languageFile = 'LLL:EXT:core/Resources/Private/Language/locallang_misc.xlf';
                $action = $queryParameters['edit'][$table][$recordId];

                switch ($action) {
                    case 'edit':
                        $type = 'edit';
                        $titlePrefix = $languageService->sL($languageFile . ':shortcut_edit');
                        break;
                    case 'new':
                        $type = 'new';
                        $titlePrefix = $languageService->sL($languageFile . ':shortcut_create');
                        break;
                }
            }
217
218
219
220
221
222
            // Check if given id is a combined identifier
            if (!empty($queryParameters['id']) && preg_match('/^[\d]+:/', $queryParameters['id'])) {
                try {
                    $resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
                    $resource = $resourceFactory->getObjectFromCombinedIdentifier($queryParameters['id']);
                    $title = trim(sprintf(
223
224
                        '%s (%s)',
                        $titlePrefix,
225
226
227
228
229
230
                        $resource->getName()
                    ));
                } catch (ResourceDoesNotExistException $e) {
                }
            } else {
                // Lookup the title of this page and use it as default description
231
                $pageId = $pageId ?: $recordId ?: (int)($queryParameters['id'] ?? 0);
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
                $page = $pageId ? BackendUtility::getRecord('pages', $pageId) : null;

                if (!empty($page)) {
                    // Set the name to the title of the page
                    if ($type === 'other') {
                        $title = sprintf(
                            '%s (%s)',
                            $title,
                            $page['title']
                        );
                    } else {
                        $title = sprintf(
                            '%s %s (%s)',
                            $titlePrefix,
                            $languageService->sL($GLOBALS['TCA'][$table]['ctrl']['title']),
                            $page['title']
                        );
                    }
                } elseif (!empty($table)) {
                    $title = trim(sprintf(
                        '%s %s',
                        $titlePrefix,
                        $languageService->sL($GLOBALS['TCA'][$table]['ctrl']['title'])
                    ));
256
257
258
259
                }
            }
        }

260
261
262
        // In case title is still empty try to set the modules short description label
        // @todo This is deprecated and can be removed in v12
        if ($title === '') {
263
            $moduleLabels = $this->moduleLoader->getLabelsForModule($this->getModuleNameFromRouteIdentifier($routeIdentifier));
264
265
266
267
268
            if (!empty($moduleLabels['shortdescription'])) {
                $title = $this->getLanguageService()->sL($moduleLabels['shortdescription']);
            }
        }

269
        $queryBuilder = $this->connectionPool->getQueryBuilderForTable(self::TABLE_NAME);
270
        $affectedRows = $queryBuilder
271
            ->insert(self::TABLE_NAME)
272
273
            ->values([
                'userid' => $this->getBackendUser()->user['uid'],
274
275
                'route' => $routeIdentifier,
                'arguments' => $arguments,
276
                'description' => $title ?: 'Shortcut',
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
                'sorting' => $GLOBALS['EXEC_TIME'],
            ])
            ->execute();

        return $affectedRows === 1;
    }

    /**
     * Update a shortcut
     *
     * @param int $id identifier of a shortcut
     * @param string $title new title of the shortcut
     * @param int $groupId new group identifier of the shortcut
     * @return bool
     */
    public function updateShortcut(int $id, string $title, int $groupId): bool
    {
        $backendUser = $this->getBackendUser();
295
296
        $queryBuilder = $this->connectionPool->getQueryBuilderForTable(self::TABLE_NAME);
        $queryBuilder->update(self::TABLE_NAME)
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
            ->where(
                $queryBuilder->expr()->eq(
                    'uid',
                    $queryBuilder->createNamedParameter($id, \PDO::PARAM_INT)
                )
            )
            ->set('description', $title)
            ->set('sc_group', $groupId);

        if (!$backendUser->isAdmin()) {
            // Users can only modify their own shortcuts
            $queryBuilder->andWhere(
                $queryBuilder->expr()->eq(
                    'userid',
                    $queryBuilder->createNamedParameter($backendUser->user['uid'], \PDO::PARAM_INT)
                )
            );

            if ($groupId < 0) {
                $queryBuilder->set('sc_group', 0);
            }
        }

        $affectedRows = $queryBuilder->execute();

        return $affectedRows === 1;
    }

    /**
     * Remove a shortcut
     *
     * @param int $id identifier of a shortcut
     * @return bool
     */
    public function removeShortcut(int $id): bool
    {
        $shortcut = $this->getShortcutById($id);
        $success = false;

336
337
338
        if ((int)$shortcut['raw']['userid'] === (int)$this->getBackendUser()->user['uid']) {
            $queryBuilder = $this->connectionPool->getQueryBuilderForTable(self::TABLE_NAME);
            $affectedRows = $queryBuilder->delete(self::TABLE_NAME)
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
                ->where(
                    $queryBuilder->expr()->eq(
                        'uid',
                        $queryBuilder->createNamedParameter($id, \PDO::PARAM_INT)
                    )
                )
                ->execute();

            if ($affectedRows === 1) {
                $success = true;
            }
        }

        return $success;
    }

    /**
     * Gets the available shortcut groups from default groups, user TSConfig, and global groups
     *
     * @return array
     */
    protected function initShortcutGroups(): array
    {
        $languageService = $this->getLanguageService();
        $backendUser = $this->getBackendUser();
        // By default, 5 groups are set
        $shortcutGroups = [
            1 => '1',
            2 => '1',
            3 => '1',
            4 => '1',
            5 => '1',
        ];

        // Groups from TSConfig
        $bookmarkGroups = $backendUser->getTSConfig()['options.']['bookmarkGroups.'] ?? [];

        if (is_array($bookmarkGroups)) {
            foreach ($bookmarkGroups as $groupId => $label) {
                if (!empty($label)) {
379
380
                    $label = (string)$label;
                    $shortcutGroups[$groupId] = strpos($label, 'LLL:') === 0 ? $languageService->sL($label) : $label;
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
                } elseif ($backendUser->isAdmin()) {
                    unset($shortcutGroups[$groupId]);
                }
            }
        }

        // Generate global groups, all global groups have negative IDs.
        if (!empty($shortcutGroups)) {
            foreach ($shortcutGroups as $groupId => $groupLabel) {
                $shortcutGroups[$groupId * -1] = $groupLabel;
            }
        }

        // Group -100 is kind of superglobal and can't be changed.
        $shortcutGroups[self::SUPERGLOBAL_GROUP] = '1';

        // Add labels
        $languageFile = 'LLL:EXT:core/Resources/Private/Language/locallang_misc.xlf';

        foreach ($shortcutGroups as $groupId => $groupLabel) {
            $groupId = (int)$groupId;
            $label = $groupLabel;

            if ($groupLabel === '1') {
                $label = $languageService->sL($languageFile . ':bookmark_group_' . abs($groupId));

                if (empty($label)) {
                    // Fallback label
                    $label = $languageService->sL($languageFile . ':bookmark_group') . ' ' . abs($groupId);
                }
            }

            if ($groupId < 0) {
                // Global group
                $label = $languageService->sL($languageFile . ':bookmark_global') . ': ' . (!empty($label) ? $label : abs($groupId));

                if ($groupId === self::SUPERGLOBAL_GROUP) {
                    $label = $languageService->sL($languageFile . ':bookmark_global') . ': ' . $languageService->sL($languageFile . ':bookmark_all');
                }
            }

            $shortcutGroups[$groupId] = htmlspecialchars($label);
        }

        return $shortcutGroups;
    }

    /**
     * Retrieves the shortcuts for the current user
     *
     * @return array Array of shortcuts
     */
    protected function initShortcuts(): array
    {
        $backendUser = $this->getBackendUser();
        $lastGroup = 0;
        $shortcuts = [];
438
439

        $queryBuilder = $this->connectionPool->getQueryBuilderForTable(self::TABLE_NAME);
440
        $result = $queryBuilder->select('*')
441
            ->from(self::TABLE_NAME)
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
            ->where(
                $queryBuilder->expr()->andX(
                    $queryBuilder->expr()->eq(
                        'userid',
                        $queryBuilder->createNamedParameter($backendUser->user['uid'], \PDO::PARAM_INT)
                    ),
                    $queryBuilder->expr()->gte(
                        'sc_group',
                        $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
                    )
                )
            )
            ->orWhere(
                $queryBuilder->expr()->in(
                    'sc_group',
                    $queryBuilder->createNamedParameter(
                        array_keys($this->getGlobalShortcutGroups()),
                        Connection::PARAM_INT_ARRAY
                    )
                )
            )
            ->orderBy('sc_group')
            ->addOrderBy('sorting')
            ->execute();

        while ($row = $result->fetch()) {
            $shortcut = ['raw' => $row];
469
470
            $routeIdentifier = $row['route'] ?? '';
            $arguments = json_decode($row['arguments'] ?? '', true) ?? [];
471

472
473
474
            if ($routeIdentifier === 'record_edit' && is_array($arguments['edit'])) {
                $shortcut['table'] = key($arguments['edit']);
                $shortcut['recordid'] = key($arguments['edit'][$shortcut['table']]);
475

476
                if ($arguments['edit'][$shortcut['table']][$shortcut['recordid']] === 'edit') {
477
                    $shortcut['type'] = 'edit';
478
                } elseif ($arguments['edit'][$shortcut['table']][$shortcut['recordid']] === 'new') {
479
480
481
482
483
484
485
486
487
488
                    $shortcut['type'] = 'new';
                }

                if (substr((string)$shortcut['recordid'], -1) === ',') {
                    $shortcut['recordid'] = substr((string)$shortcut['recordid'], 0, -1);
                }
            } else {
                $shortcut['type'] = 'other';
            }

489
490
491
492
493
494
            $moduleName = $this->getModuleNameFromRouteIdentifier($routeIdentifier);

            // Skip shortcut if module name can not be resolved
            if ($moduleName === '') {
                continue;
            }
495
496

            // Check if the user has access to this module
497
            // @todo Hack for EditDocumentController / FormEngine, see issues #91368 and #91210
498
            if ($routeIdentifier !== 'record_edit' && !is_array($this->moduleLoader->checkMod($moduleName))) {
499
500
                continue;
            }
501
502
503
504
505
506
507
508
509
            if (($pageId = ((int)($arguments['id'] ?? 0))) > 0 && !$backendUser->isAdmin()) {
                // Check for webmount access
                if ($backendUser->isInWebMount($pageId) === null) {
                    continue;
                }
                // Check for record access
                $pageRow = BackendUtility::getRecord('pages', $pageId);
                if ($pageRow === null || !$backendUser->doesUserHaveAccess($pageRow, Permission::PAGE_SHOW)) {
                    continue;
510
511
512
513
514
515
516
517
518
                }
            }

            $shortcutGroup = (int)$row['sc_group'];
            if ($shortcutGroup && $lastGroup !== $shortcutGroup && $shortcutGroup !== self::SUPERGLOBAL_GROUP) {
                $shortcut['groupLabel'] = $this->getShortcutGroupLabel($shortcutGroup);
            }
            $lastGroup = $shortcutGroup;

519
520
521
522
523
524
525
526
527
            $description = $row['description'] ?? '';
            // Empty description should usually never happen since not defining such, is deprecated and a
            // fallback is in place, at least for v11. Only manual inserts could lead to an empty description.
            // @todo Can be removed in v12 since setting a display name is mandatory then
            if ($description === '') {
                $moduleLabel = (string)($this->moduleLoader->getLabelsForModule($moduleName)['shortdescription'] ?? '');
                if ($moduleLabel !== '') {
                    $description = $this->getLanguageService()->sL($moduleLabel);
                }
528
529
            }

530
            $shortcutUrl = (string)GeneralUtility::makeInstance(UriBuilder::class)->buildUriFromRoute($routeIdentifier, $arguments);
531

532
533
534
535
536
537
538
539
            $shortcut['group'] = $shortcutGroup;
            $shortcut['icon'] = $this->getShortcutIcon($routeIdentifier, $moduleName, $shortcut);
            $shortcut['label'] = $description;
            $shortcut['action'] = 'jump('
                . GeneralUtility::quoteJSvalue($shortcutUrl)
                . ',' . GeneralUtility::quoteJSvalue($moduleName)
                . ',' . GeneralUtility::quoteJSvalue($moduleName)
                . ', ' . $pageId . ');';
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
            $shortcuts[] = $shortcut;
        }

        return $shortcuts;
    }

    /**
     * Gets a list of global groups, shortcuts in these groups are available to all users
     *
     * @return array Array of global groups
     */
    protected function getGlobalShortcutGroups(): array
    {
        $globalGroups = [];

        foreach ($this->shortcutGroups as $groupId => $groupLabel) {
            if ($groupId < 0) {
                $globalGroups[$groupId] = $groupLabel;
            }
        }

        return $globalGroups;
    }

    /**
     * Gets the label for a shortcut group
     *
     * @param int $groupId A shortcut group id
     * @return string The shortcut group label, can be an empty string if no group was found for the id
     */
    protected function getShortcutGroupLabel(int $groupId): string
    {
        return $this->shortcutGroups[$groupId] ?? '';
    }

    /**
     * Gets the icon for the shortcut
     *
578
579
     * @param string $routeIdentifier
     * @param string $moduleName
580
581
582
     * @param array $shortcut
     * @return string Shortcut icon as img tag
     */
583
    protected function getShortcutIcon(string $routeIdentifier, string $moduleName, array $shortcut): string
584
    {
585
        $selectFields = [];
586
587
        switch ($routeIdentifier) {
            case 'record_edit':
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
                $table = $shortcut['table'];
                $recordid = $shortcut['recordid'];
                $icon = '';

                if ($shortcut['type'] === 'edit') {
                    // Creating the list of fields to include in the SQL query:
                    $selectFields[] = 'uid';
                    $selectFields[] = 'pid';

                    if ($table === 'pages') {
                        $selectFields[] = 'module';
                        $selectFields[] = 'extendToSubpages';
                        $selectFields[] = 'doktype';
                    }

                    if (is_array($GLOBALS['TCA'][$table]['ctrl']['enablecolumns'])) {
                        $selectFields = array_merge($selectFields, $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']);
                    }

                    if ($GLOBALS['TCA'][$table]['ctrl']['typeicon_column']) {
                        $selectFields[] = $GLOBALS['TCA'][$table]['ctrl']['typeicon_column'];
                    }

611
                    if (BackendUtility::isTableWorkspaceEnabled($table)) {
612
                        $selectFields[] = 't3ver_state';
613
614
                        $selectFields[] = 't3ver_wsid';
                        $selectFields[] = 't3ver_oid';
615
616
                    }

617
                    $queryBuilder = $this->connectionPool->getQueryBuilderForTable($table);
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
                    $queryBuilder->select(...array_unique(array_values($selectFields)))
                        ->from($table)
                        ->where(
                            $queryBuilder->expr()->in(
                                'uid',
                                $queryBuilder->createNamedParameter($recordid, \PDO::PARAM_INT)
                            )
                        );

                    $row = $queryBuilder->execute()->fetch();

                    $icon = $this->iconFactory->getIconForRecord($table, (array)$row, Icon::SIZE_SMALL)->render();
                } elseif ($shortcut['type'] === 'new') {
                    $icon = $this->iconFactory->getIconForRecord($table, [], Icon::SIZE_SMALL)->render();
                }
                break;
            case 'file_edit':
                $icon = $this->iconFactory->getIcon('mimetypes-text-html', Icon::SIZE_SMALL)->render();
                break;
            case 'wizard_rte':
                $icon = $this->iconFactory->getIcon('mimetypes-word', Icon::SIZE_SMALL)->render();
                break;
            default:
                $iconIdentifier = '';

                if (strpos($moduleName, '_') !== false) {
644
                    [$mainModule, $subModule] = explode('_', $moduleName, 2);
645
                    $iconIdentifier = $this->moduleLoader->modules[$mainModule]['sub'][$subModule]['iconIdentifier'];
646
                } elseif ($moduleName !== '') {
647
648
649
650
651
652
653
654
655
656
657
658
659
660
                    $iconIdentifier = $this->moduleLoader->modules[$moduleName]['iconIdentifier'];
                }

                if (!$iconIdentifier) {
                    $iconIdentifier = 'empty-empty';
                }

                $icon = $this->iconFactory->getIcon($iconIdentifier, Icon::SIZE_SMALL)->render();
        }

        return $icon;
    }

    /**
661
     * Get the module name from the resolved route or by static mapping for some special cases.
662
     *
663
664
     * @param string $routeIdentifier
     * @return string
665
     */
666
    protected function getModuleNameFromRouteIdentifier(string $routeIdentifier): string
667
    {
668
669
        if ($this->isSpecialRoute($routeIdentifier)) {
            return $routeIdentifier;
670
671
        }

672
673
        $route = $this->getRoute($routeIdentifier);
        return $route !== null ? (string)($route->getOption('moduleName') ?? '') : '';
674
675
676
    }

    /**
677
     * Get the route for a given route identifier
678
     *
679
680
     * @param string $routeIdentifier
     * @return Route|null
681
     */
682
    protected function getRoute(string $routeIdentifier): ?Route
683
    {
684
        return GeneralUtility::makeInstance(Router::class)->getRoutes()[$routeIdentifier] ?? null;
685
686
687
    }

    /**
688
     * Check if a route for the given identifier exists
689
     *
690
691
     * @param string $routeIdentifier
     * @return bool
692
     */
693
    protected function routeExists(string $routeIdentifier): bool
694
    {
695
696
        return $this->getRoute($routeIdentifier) !== null;
    }
697

698
699
700
701
702
703
704
705
706
    /**
     * Check if given route identifier is a special "no module" route
     *
     * @param string $routeIdentifier
     * @return bool
     */
    protected function isSpecialRoute(string $routeIdentifier): bool
    {
        return in_array($routeIdentifier, ['record_edit', 'file_edit', 'wizard_rte'], true);
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
    }

    /**
     * Returns the current BE user.
     *
     * @return BackendUserAuthentication
     */
    protected function getBackendUser(): BackendUserAuthentication
    {
        return $GLOBALS['BE_USER'];
    }

    /**
     * @return LanguageService
     */
    protected function getLanguageService(): LanguageService
    {
        return $GLOBALS['LANG'];
    }
}