ModuleTemplate.php 25.2 KB
Newer Older
1
<?php
2

3
4
5
6
7
8
9
10
11
12
13
14
15
/*
 * 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!
 */

16
17
namespace TYPO3\CMS\Backend\Template;

18
use TYPO3\CMS\Backend\Backend\Shortcut\ShortcutRepository;
19
use TYPO3\CMS\Backend\Routing\Router;
20
21
22
use TYPO3\CMS\Backend\Template\Components\DocHeaderComponent;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
23
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
24
25
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
26
use TYPO3\CMS\Core\Localization\LanguageService;
27
use TYPO3\CMS\Core\Messaging\AbstractMessage;
28
use TYPO3\CMS\Core\Messaging\FlashMessage;
Benni Mack's avatar
Benni Mack committed
29
use TYPO3\CMS\Core\Messaging\FlashMessageQueue;
30
use TYPO3\CMS\Core\Messaging\FlashMessageService;
31
32
33
use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
34
use TYPO3\CMS\Core\Utility\HttpUtility;
35
use TYPO3\CMS\Core\Utility\PathUtility;
36
use TYPO3\CMS\Fluid\View\StandaloneView;
37
use TYPO3Fluid\Fluid\View\Exception\InvalidTemplateResourceException;
38
39
40
41
42

/**
 * A class taking care of the "outer" HTML of a module, especially
 * the doc header and other related parts.
 */
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
class ModuleTemplate
{
    /**
     * DocHeaderComponent
     *
     * @var DocHeaderComponent
     */
    protected $docHeaderComponent;

    /**
     * Javascript Code Array
     * Used for inline JS
     *
     * @var array
     */
    protected $javascriptCodeArray = [];

    /**
     * Expose the pageRenderer
     *
     * @var PageRenderer
     */
    protected $pageRenderer;

67
68
69
70
71
    /**
     * @var bool
     */
    protected $uiBlock = false;

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
    /**
     * TemplateRootPath
     *
     * @var string[]
     */
    protected $templateRootPaths = ['EXT:backend/Resources/Private/Templates'];

    /**
     * PartialRootPath
     *
     * @var string[]
     */
    protected $partialRootPaths = ['EXT:backend/Resources/Private/Partials'];

    /**
     * LayoutRootPath
     *
     * @var string[]
     */
    protected $layoutRootPaths = ['EXT:backend/Resources/Private/Layouts'];

    /**
     * Template name
     *
     * @var string
     */
    protected $templateFile = 'Module.html';

    /**
     * Fluid Standalone View
     *
     * @var StandaloneView
     */
    protected $view;

    /**
     * Content String
     *
     * @var string
     */
    protected $content = '';

    /**
     * IconFactory Member
     *
     * @var IconFactory
     */
    protected $iconFactory;

121
122
123
124
125
    /**
     * @var FlashMessageService
     */
    protected $flashMessageService;

126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
    /**
     * Module ID
     *
     * @var string
     */
    protected $moduleId = '';

    /**
     * Module Name
     *
     * @var string
     */
    protected $moduleName = '';

    /**
     * Title Tag
     *
     * @var string
     */
    protected $title = '';

147
148
149
150
151
152
153
    /**
     * Body Tag
     *
     * @var string
     */
    protected $bodyTag = '<body>';

154
155
156
    /**
     * Flash message queue
     *
Benni Mack's avatar
Benni Mack committed
157
     * @var FlashMessageQueue
158
159
160
     */
    protected $flashMessageQueue;

161
162
163
164
165
166
167
168
169
170
171
172
173
174
    /**
     * Returns the current body tag
     *
     * @return string
     */
    public function getBodyTag()
    {
        return $this->bodyTag;
    }

    /**
     * Sets the body tag
     *
     * @param string $bodyTag
175
     * @return self
176
     */
177
    public function setBodyTag($bodyTag): self
178
179
    {
        $this->bodyTag = $bodyTag;
180
        return $this;
181
182
    }

183
184
185
186
187
188
189
190
191
192
193
194
195
196
    /**
     * Gets the standalone view.
     *
     * @return StandaloneView
     */
    public function getView()
    {
        return $this->view;
    }

    /**
     * Set content
     *
     * @param string $content Content of the module
197
     * @return self
198
     */
199
    public function setContent($content): self
200
201
    {
        $this->view->assign('content', $content);
202
        return $this;
203
204
205
206
207
208
    }

    /**
     * Set title tag
     *
     * @param string $title
209
     * @return self
210
     */
211
    public function setTitle($title): self
212
213
    {
        $this->title = $title;
214
        return $this;
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
    }

    /**
     * Returns the IconFactory
     *
     * @return IconFactory
     */
    public function getIconFactory()
    {
        return $this->iconFactory;
    }

    /**
     * Class constructor
     * Sets up view and property objects
     *
231
232
233
     * @param PageRenderer $pageRenderer
     * @param IconFactory $iconFactory
     * @param FlashMessageService $flashMessageService
234
235
     * @throws InvalidTemplateResourceException In case a template is invalid
     */
236
237
238
239
240
    public function __construct(
        PageRenderer $pageRenderer,
        IconFactory $iconFactory,
        FlashMessageService $flashMessageService
    ) {
241
242
243
244
245
        $this->view = GeneralUtility::makeInstance(StandaloneView::class);
        $this->view->setPartialRootPaths($this->partialRootPaths);
        $this->view->setTemplateRootPaths($this->templateRootPaths);
        $this->view->setLayoutRootPaths($this->layoutRootPaths);
        $this->view->setTemplate($this->templateFile);
246
247
248
        $this->pageRenderer = $pageRenderer;
        $this->iconFactory = $iconFactory;
        $this->flashMessageService = $flashMessageService;
249
        $this->docHeaderComponent = GeneralUtility::makeInstance(DocHeaderComponent::class);
250
251
252
        $this->setupPage();
        $this->loadJavaScripts();
        $this->loadStylesheets();
253
254
255
256
257
258
259
260
    }

    /**
     * Loads all necessary Javascript Files
     */
    protected function loadJavaScripts()
    {
        $this->pageRenderer->loadRequireJsModule('bootstrap');
261

Benni Mack's avatar
Benni Mack committed
262
        if ($this->getBackendUserAuthentication() && !empty($this->getBackendUserAuthentication()->user)) {
263
264
265
            $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/ContextHelp');
            $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/DocumentHeader');
        }
266
267
        $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/GlobalEventHandler');
        $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/ActionDispatcher');
268
        $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Element/ImmediateActionElement');
269
270
271
272
273
274
275
    }

    /**
     * Loads all necessary stylesheets
     */
    protected function loadStylesheets()
    {
276
        if (!empty($GLOBALS['TBE_STYLES']['stylesheet'])) {
277
278
            $this->pageRenderer->addCssFile($GLOBALS['TBE_STYLES']['stylesheet']);
        }
279
        if (!empty($GLOBALS['TBE_STYLES']['stylesheet2'])) {
280
281
            $this->pageRenderer->addCssFile($GLOBALS['TBE_STYLES']['stylesheet2']);
        }
282
283
284
        // Add all *.css files of the directory $path to the stylesheets
        foreach ($this->getRegisteredStylesheetFolders() as $folder) {
            // Read all files in directory and sort them alphabetically
285
            foreach (GeneralUtility::getFilesInDir($folder, 'css', true) as $cssFile) {
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
                $this->pageRenderer->addCssFile($cssFile);
            }
        }
    }

    /**
     * Returns an array of all stylesheet directories registered via $TBE_STYLES['skins']
     */
    protected function getRegisteredStylesheetFolders(): array
    {
        $stylesheetDirectories = [];
        foreach ($GLOBALS['TBE_STYLES']['skins'] ?? [] as $skin) {
            foreach ($skin['stylesheetDirectories'] ?? [] as $stylesheetDir) {
                $directory = GeneralUtility::getFileAbsFileName($stylesheetDir);
                if (!empty($directory)) {
                    $stylesheetDirectories[] = $directory;
                }
            }
        }
        return $stylesheetDirectories;
306
307
308
309
310
311
312
313
314
315
    }

    /**
     * Sets mandatory parameters for the view (pageRenderer)
     */
    protected function setupPage()
    {
        // Yes, hardcoded on purpose
        $this->pageRenderer->setXmlPrologAndDocType('<!DOCTYPE html>');
        $this->pageRenderer->setCharSet('utf-8');
316
        $this->pageRenderer->setLanguage($this->getLanguageService()->lang);
Mathias Schreiber's avatar
Mathias Schreiber committed
317
        $this->pageRenderer->setMetaTag('name', 'viewport', 'width=device-width, initial-scale=1');
318
        $this->pageRenderer->setFavIcon($this->getBackendFavicon());
319
320
321
322
        $this->pageRenderer->enableConcatenateCss();
        $this->pageRenderer->enableConcatenateJavascript();
        $this->pageRenderer->enableCompressCss();
        $this->pageRenderer->enableCompressJavascript();
323
324
        $languageCode = $this->pageRenderer->getLanguage() === 'default' ? 'en' : $this->pageRenderer->getLanguage();
        $this->pageRenderer->setHtmlTag('<html lang="' . htmlspecialchars($languageCode) . '">');
325
326
327
        if ($GLOBALS['TYPO3_CONF_VARS']['BE']['debug']) {
            $this->pageRenderer->enableDebugMode();
        }
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
    }

    /**
     * Wrapper function for adding JS inline blocks
     */
    protected function setJavaScriptCodeArray()
    {
        foreach ($this->javascriptCodeArray as $name => $code) {
            $this->pageRenderer->addJsInlineCode($name, $code, false);
        }
    }

    /**
     * Adds JS inline blocks of code to the internal registry
     *
     * @param string $name Javascript code block name
     * @param string $code Inline Javascript
345
     * @return self
346
     */
347
    public function addJavaScriptCode($name = '', $code = ''): self
348
349
    {
        $this->javascriptCodeArray[$name] = $code;
350
        return $this;
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
    }

    /**
     * Get the DocHeader
     *
     * @return DocHeaderComponent
     */
    public function getDocHeaderComponent()
    {
        return $this->docHeaderComponent;
    }

    /**
     * Returns the fully rendered view
     *
     * @return string
     */
    public function renderContent()
    {
        $this->setJavaScriptCodeArray();
371
        $this->pageRenderer->setTitle($this->title);
372
373
374
375
376
377
378
379

        $this->view->assign('docHeader', $this->docHeaderComponent->docHeaderContent());
        if ($this->moduleId) {
            $this->view->assign('moduleId', $this->moduleId);
        }
        if ($this->moduleName) {
            $this->view->assign('moduleName', $this->moduleName);
        }
380
        $this->view->assign('uiBlock', $this->uiBlock);
381
        $this->view->assign('flashMessageQueueIdentifier', $this->getFlashMessageQueue()->getIdentifier());
382
        $this->pageRenderer->addBodyContent($this->bodyTag . $this->view->render());
383
        $this->pageRenderer->addJsFooterInlineCode('updateSignals', BackendUtility::getUpdateSignalCode());
384
        return $this->pageRenderer->render();
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
    }

    /**
     * Get PageRenderer
     *
     * @return PageRenderer
     */
    public function getPageRenderer()
    {
        return $this->pageRenderer;
    }

    /**
     * Set form tag
     *
     * @param string $formTag Form tag to add
401
     * @return self
402
     */
403
    public function setForm($formTag = ''): self
404
405
    {
        $this->view->assign('formTag', $formTag);
406
        return $this;
407
408
409
410
411
412
    }

    /**
     * Sets the ModuleId
     *
     * @param string $moduleId ID of the module
413
     * @return self
414
     */
415
    public function setModuleId($moduleId): self
416
417
418
    {
        $this->moduleId = $moduleId;
        $this->registerModuleMenu($moduleId);
419
        return $this;
420
421
422
423
424
425
    }

    /**
     * Sets the ModuleName
     *
     * @param string $moduleName Name of the module
426
     * @return self
427
     */
428
    public function setModuleName($moduleName): self
429
430
    {
        $this->moduleName = $moduleName;
431
        return $this;
432
433
434
435
436
    }

    /**
     * Generates the Menu for things like Web->Info
     *
437
     * @param string $moduleMenuIdentifier
438
     * @return self
439
     */
440
    public function registerModuleMenu($moduleMenuIdentifier): self
441
442
443
444
445
446
447
448
449
450
451
452
453
    {
        if (isset($GLOBALS['TBE_MODULES_EXT'][$moduleMenuIdentifier])) {
            $menuEntries =
                $GLOBALS['TBE_MODULES_EXT'][$moduleMenuIdentifier]['MOD_MENU']['function'];
            $menu = $this->getDocHeaderComponent()->getMenuRegistry()->makeMenu()->setIdentifier('MOD_FUNC');
            foreach ($menuEntries as $menuEntry) {
                $menuItem = $menu->makeMenuItem()
                    ->setTitle($menuEntry['title'])
                    ->setHref('#');
                $menu->addMenuItem($menuItem);
            }
            $this->docHeaderComponent->getMenuRegistry()->addMenu($menu);
        }
454
        return $this;
455
456
    }

457
    /**
458
459
460
461
     * Creates a tab menu where the tabs or collapsible are rendered with bootstrap markup
     *
     * @param array $menuItems Tab elements, each element is an array with "label" and "content"
     * @param string $domId DOM id attribute, will be appended with an iteration number per tab.
462
463
464
465
466
467
468
469
470
471
472
473
     * @param int $defaultTabIndex Default tab to open (for toggle <=0). Value corresponds to integer-array index + 1
     *                             (index zero is "1", index "1" is 2 etc.). A value of zero (or something non-existing
     *                             will result in no default tab open.
     * @param bool $collapsible If set, the tabs are rendered as headers instead over each sheet. Effectively this means
     *                          there is no tab menu, but rather a foldout/fold-in menu.
     * @param bool $wrapContent If set, the content is wrapped in div structure which provides a padding and border
     *                          style. Set this FALSE to get unstyled content pane with fullsize content area.
     * @param bool $storeLastActiveTab If set, the last open tab is stored in local storage and will be re-open again.
     *                                 If you don't need this feature, e.g. for wizards like import/export you can
     *                                 disable this behaviour.
     * @return string
     */
474
    public function getDynamicTabMenu(array $menuItems, $domId, $defaultTabIndex = 1, $collapsible = false, $wrapContent = true, $storeLastActiveTab = true)
475
476
    {
        $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Tabs');
477
478
        $templatePath = ExtensionManagementUtility::extPath('backend')
            . 'Resources/Private/Templates/DocumentTemplate/';
479
        $view = GeneralUtility::makeInstance(StandaloneView::class);
480
481
        $view->setTemplatePathAndFilename($templatePath . ($collapsible ? 'Collapse.html' : 'Tabs.html'));
        $view->setPartialRootPaths([$templatePath . 'Partials']);
482
        $view->assignMultiple([
483
            'id' => 'DTM-' . GeneralUtility::shortMD5($domId),
484
485
486
487
            'items' => $menuItems,
            'defaultTabIndex' => $defaultTabIndex,
            'wrapContent' => $wrapContent,
            'storeLastActiveTab' => $storeLastActiveTab,
488
        ]);
489
490
491
        return $view->render();
    }

492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
    /*******************************************
     * THE FOLLOWING METHODS ARE SUBJECT TO BE DEPRECATED / DROPPED!
     *
     * These methods have been copied over from DocumentTemplate and enables
     * core modules to drop the dependency to DocumentTemplate altogether without
     * rewriting these modules now.
     * The methods below are marked as internal and will be removed
     * one-by-one with further refactoring of modules.
     *
     * Do not use these methods within own extensions if possible or
     * be prepared to change this later again.
     *******************************************/
    /**
     * Returns a linked shortcut-icon which will call the shortcut frame and set a
     * shortcut there back to the calling page/module
     *
     * @param string $gvList Is the list of GET variables to store (if any)
     * @param string $setList Is the list of SET[] variables to store
     * (if any) - SET[] variables a stored in $GLOBALS["SOBE"]->MOD_SETTINGS
     * for backend modules
     * @param string $modName Module name string
     * @param string|int $motherModName Is used to enter the "parent module
     * name" if the module is a submodule under eg. Web>* or File>*. You
     * can also set this value to 1 in which case the currentLoadedModule
     * is sent to the shortcut script (so - not a fixed value!) - that is used
     * in file_edit and wizard_rte modules where those are really running as
     * a part of another module.
519
520
521
     * @param string $displayName When given this name is used instead of the
     * module name.
     * @param string $classes Additional CSS classes for the link around the icon
522
523
524
525
     *
     * @return string HTML content
     * @todo Make this thing return a button object
     * @internal
526
     * @deprecated since v11, will be removed in v12
527
     */
528
    public function makeShortcutIcon($gvList, $setList, $modName, $motherModName = '', $displayName = '', $classes = 'btn btn-default btn-sm')
529
    {
530
        trigger_error('Method makeShortcutIcon() is deprecated and will be removed in v12. Please use ShortcutButton->setArguments() instead.', E_USER_DEPRECATED);
531
        $gvList = 'route,id,' . $gvList;
532
533
534
535
536
537
538
539
        $storeUrl = $this->makeShortcutUrl($gvList, $setList);
        $pathInfo = parse_url(GeneralUtility::getIndpEnv('REQUEST_URI'));
        // Fallback for alt_mod. We still pass in the old xMOD... stuff,
        // but TBE_MODULES only knows about "record_edit".
        // We still need to pass the xMOD name to createShortcut below,
        // since this is used for icons.
        $moduleName = $modName === 'xMOD_alt_doc.php' ? 'record_edit' : $modName;
        // Add the module identifier automatically if typo3/index.php is used:
540
541
542
        // @todo: routing
        if (GeneralUtility::_GET('route') !== null) {
            $storeUrl = '&route=' . $moduleName . $storeUrl;
543
544
545
546
        }

        $shortcutUrl = $pathInfo['path'] . '?' . $storeUrl;

547
548
549
550
551
        // We simply let the above functionality as it is for maximum backwards compatibility and now
        // just process the generated $shortcutUrl to match the new format (routeIdentifier & arguments)
        [$routeIdentifier, $arguments] = $this->getCreateShortcutProperties($shortcutUrl);

        if (GeneralUtility::makeInstance(ShortcutRepository::class)->shortcutExists($routeIdentifier, $arguments)) {
552
            return '<a class="active ' . htmlspecialchars($classes) . '" title="">' .
553
            $this->iconFactory->getIcon('actions-system-shortcut-active', Icon::SIZE_SMALL)->render() . '</a>';
554
555
        }

556
557
558
559
560
561
562
        $confirmationText =  $this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.makeBookmark');
        $onClick = 'top.TYPO3.ShortcutMenu.createShortcut('
            . GeneralUtility::quoteJSvalue($routeIdentifier)
            . ', ' . GeneralUtility::quoteJSvalue($arguments)
            . ', ' . GeneralUtility::quoteJSvalue($displayName)
            . ', ' . GeneralUtility::quoteJSvalue($confirmationText)
            . ', this);return false;';
563

564
        return '<a href="#" class="' . htmlspecialchars($classes) . '" onclick="' . htmlspecialchars($onClick) . '" title="' .
565
        htmlspecialchars($confirmationText) . '">' .
566
567
568
569
570
571
572
573
574
575
576
577
        $this->iconFactory->getIcon('actions-system-shortcut-new', Icon::SIZE_SMALL)->render() . '</a>';
    }

    /**
     * MAKE url for storing
     * Internal func
     *
     * @param string $gvList Is the list of GET variables to store (if any)
     * @param string $setList Is the list of SET[] variables to store (if any)
     * - SET[] variables a stored in $GLOBALS["SOBE"]->MOD_SETTINGS for backend
     * modules
     *
578
     * @return string GET-parameters for the shortcut-url only(!). String starts with '&'
579
     * @internal
580
     * @deprecated since v11, will be removed in v12. Deprecation logged by parent method makeShortcutIcon()
581
582
583
584
585
586
     */
    public function makeShortcutUrl($gvList, $setList)
    {
        $getParams = GeneralUtility::_GET();
        $storeArray = array_merge(
            GeneralUtility::compileSelectedGetVarsFromArray($gvList, $getParams),
587
            ['SET' => GeneralUtility::compileSelectedGetVarsFromArray($setList, (array)$GLOBALS['SOBE']->MOD_SETTINGS)]
588
        );
589
        return HttpUtility::buildQueryString($storeArray, '&');
590
591
    }

592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
    /**
     * Process the generated shortcut url and return properties needed for the
     * shortcut registration with route identifier and JSON encoded arguments.
     *
     * @param string $shortcutUrl
     *
     * @return array
     * @deprecated Only for backwards compatibility. Can be removed in v12
     */
    protected function getCreateShortcutProperties(string $shortcutUrl): array
    {
        $routeIdentifier = '';
        $arguments = [];

        parse_str(parse_url($shortcutUrl)['query'] ?? '', $arguments);
        $routePath = (string)($arguments['route'] ?? '');

        if ($routePath !== '') {
            foreach (GeneralUtility::makeInstance(Router::class)->getRoutes() as $identifier => $route) {
                if ($route->getPath() === $routePath
                    && (
                        $route->hasOption('moduleName')
                        || in_array($identifier, ['record_edit', 'file_edit', 'wizard_rte'], true)
                    )
                ) {
                    $routeIdentifier = $identifier;
                }
            }
        }

        unset($arguments['route'], $arguments['returnUrl']);

        return [$routeIdentifier, json_encode($arguments)];
    }

627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
    /**
     * Retrieves configured favicon for backend (with fallback)
     *
     * @return string
     */
    protected function getBackendFavicon()
    {
        $backendFavicon = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('backend', 'backendFavicon');
        if (!empty($backendFavicon)) {
            $path = $this->getUriForFileName($backendFavicon);
        } else {
            $path = ExtensionManagementUtility::extPath('backend') . 'Resources/Public/Icons/favicon.ico';
        }
        return PathUtility::getAbsoluteWebPath($path);
    }

    /**
     * Returns the uri of a relative reference, resolves the "EXT:" prefix
     * (way of referring to files inside extensions) and checks that the file is inside
     * the project root of the TYPO3 installation
     *
     * @param string $filename The input filename/filepath to evaluate
     * @return string Returns the filename of $filename if valid, otherwise blank string.
     */
    protected function getUriForFileName($filename)
    {
        if (strpos($filename, '://')) {
            return $filename;
        }
        $urlPrefix = '';
        if (strpos($filename, 'EXT:') === 0) {
            $absoluteFilename = GeneralUtility::getFileAbsFileName($filename);
            $filename = '';
            if ($absoluteFilename !== '') {
                $filename = PathUtility::getAbsoluteWebPath($absoluteFilename);
            }
        } elseif (strpos($filename, '/') !== 0) {
            $urlPrefix = GeneralUtility::getIndpEnv('TYPO3_SITE_PATH');
        }
        return $urlPrefix . $filename;
    }

669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
    /**
     * Returns the BE USER Object
     *
     * @return BackendUserAuthentication
     */
    protected function getBackendUserAuthentication()
    {
        return $GLOBALS['BE_USER'];
    }

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

689
690
691
692
693
694
695
696
697
698
    /**
     * Returns the header-bar in the top of most backend modules
     * Closes section if open.
     *
     * @param string $text The text string for the header
     * @return string HTML content
     * @internal
     */
    public function header($text)
    {
699
        return '
700
701
702
703
704

	<!-- MAIN Header in page top -->
	<h1 class="t3js-title-inlineedit">' . htmlspecialchars($text) . '</h1>
';
    }
705
706
707
708
709
710
711
712
713

    /**
     * Creates a Message object and adds it to the FlashMessageQueue.
     *
     * @param string $messageBody The message
     * @param string $messageTitle Optional message title
     * @param int $severity Optional severity, must be one of \TYPO3\CMS\Core\Messaging\FlashMessage constants
     * @param bool $storeInSession Optional, defines whether the message should be stored in the session (default)
     * @throws \InvalidArgumentException if the message body is no string
714
     * @return self
715
     */
716
    public function addFlashMessage($messageBody, $messageTitle = '', $severity = AbstractMessage::OK, $storeInSession = true): self
717
718
719
720
721
722
    {
        if (!is_string($messageBody)) {
            throw new \InvalidArgumentException('The message body must be of type string, "' . gettype($messageBody) . '" given.', 1446483133);
        }
        /* @var \TYPO3\CMS\Core\Messaging\FlashMessage $flashMessage */
        $flashMessage = GeneralUtility::makeInstance(
723
            FlashMessage::class,
724
725
726
727
728
729
            $messageBody,
            $messageTitle,
            $severity,
            $storeInSession
        );
        $this->getFlashMessageQueue()->enqueue($flashMessage);
730
        return $this;
731
732
    }

733
    /**
Benni Mack's avatar
Benni Mack committed
734
     * @param FlashMessageQueue $flashMessageQueue
735
     * @return self
736
     */
737
    public function setFlashMessageQueue($flashMessageQueue): self
738
739
    {
        $this->flashMessageQueue = $flashMessageQueue;
740
        return $this;
741
742
    }

743
    /**
Benni Mack's avatar
Benni Mack committed
744
     * @return FlashMessageQueue
745
746
747
748
     */
    protected function getFlashMessageQueue()
    {
        if (!isset($this->flashMessageQueue)) {
749
            $this->flashMessageQueue = $this->flashMessageService->getMessageQueueByIdentifier();
750
751
752
        }
        return $this->flashMessageQueue;
    }
753
754
755
756

    /**
     * @return bool
     */
757
    public function isUiBlock(): bool
758
759
760
761
762
763
    {
        return $this->uiBlock;
    }

    /**
     * @param bool $uiBlock
764
     * @return self
765
     */
766
    public function setUiBlock(bool $uiBlock): self
767
768
    {
        $this->uiBlock = $uiBlock;
769
        return $this;
770
    }
771
}