[TASK] Removes extra empty lines
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Template / ModuleTemplate.php
1 <?php
2 namespace TYPO3\CMS\Backend\Template;
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 TYPO3\CMS\Backend\Template\Components\DocHeaderComponent;
18 use TYPO3\CMS\Backend\Utility\BackendUtility;
19 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
20 use TYPO3\CMS\Core\Imaging\Icon;
21 use TYPO3\CMS\Core\Imaging\IconFactory;
22 use TYPO3\CMS\Core\Messaging\AbstractMessage;
23 use TYPO3\CMS\Core\Messaging\FlashMessageService;
24 use TYPO3\CMS\Core\Page\PageRenderer;
25 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
26 use TYPO3\CMS\Core\Utility\GeneralUtility;
27 use TYPO3\CMS\Fluid\View\Exception\InvalidTemplateResourceException;
28 use TYPO3\CMS\Fluid\View\StandaloneView;
29 use TYPO3\CMS\Lang\LanguageService;
30 use TYPO3\CMS\Version\View\VersionView;
31
32 /**
33 * A class taking care of the "outer" HTML of a module, especially
34 * the doc header and other related parts.
35 *
36 * @internal This API is not yet carved in stone and may be adapted later.
37 */
38 class ModuleTemplate
39 {
40 /**
41 * Error Icon Constant
42 *
43 * @internal
44 */
45 const STATUS_ICON_ERROR = 3;
46
47 /**
48 * Warning Icon Constant
49 *
50 * @internal
51 */
52 const STATUS_ICON_WARNING = 2;
53
54 /**
55 * Notification Icon Constant
56 *
57 * @internal
58 */
59 const STATUS_ICON_NOTIFICATION = 1;
60
61 /**
62 * OK Icon Constant
63 *
64 * @internal
65 */
66 const STATUS_ICON_OK = -1;
67
68 /**
69 * DocHeaderComponent
70 *
71 * @var DocHeaderComponent
72 */
73 protected $docHeaderComponent;
74
75 /**
76 * Javascript Code Array
77 * Used for inline JS
78 *
79 * @var array
80 */
81 protected $javascriptCodeArray = [];
82
83 /**
84 * Expose the pageRenderer
85 *
86 * @var PageRenderer
87 */
88 protected $pageRenderer;
89
90 /**
91 * TemplateRootPath
92 *
93 * @var string[]
94 */
95 protected $templateRootPaths = ['EXT:backend/Resources/Private/Templates'];
96
97 /**
98 * PartialRootPath
99 *
100 * @var string[]
101 */
102 protected $partialRootPaths = ['EXT:backend/Resources/Private/Partials'];
103
104 /**
105 * LayoutRootPath
106 *
107 * @var string[]
108 */
109 protected $layoutRootPaths = ['EXT:backend/Resources/Private/Layouts'];
110
111 /**
112 * Template name
113 *
114 * @var string
115 */
116 protected $templateFile = 'Module.html';
117
118 /**
119 * Fluid Standalone View
120 *
121 * @var StandaloneView
122 */
123 protected $view;
124
125 /**
126 * Content String
127 *
128 * @var string
129 */
130 protected $content = '';
131
132 /**
133 * Defines whether a section has been opened before
134 *
135 * @var int
136 */
137 protected $sectionFlag = 0;
138
139 /**
140 * IconFactory Member
141 *
142 * @var IconFactory
143 */
144 protected $iconFactory;
145
146 /**
147 * Module ID
148 *
149 * @var string
150 */
151 protected $moduleId = '';
152
153 /**
154 * Module Name
155 *
156 * @var string
157 */
158 protected $moduleName = '';
159
160 /**
161 * Title Tag
162 *
163 * @var string
164 */
165 protected $title = '';
166
167 /**
168 * Body Tag
169 *
170 * @var string
171 */
172 protected $bodyTag = '<body>';
173
174 /**
175 * Flash message queue
176 *
177 * @var \TYPO3\CMS\Core\Messaging\FlashMessageQueue
178 */
179 protected $flashMessageQueue;
180
181 /**
182 * Returns the current body tag
183 *
184 * @return string
185 */
186 public function getBodyTag()
187 {
188 return $this->bodyTag;
189 }
190
191 /**
192 * Sets the body tag
193 *
194 * @param string $bodyTag
195 */
196 public function setBodyTag($bodyTag)
197 {
198 $this->bodyTag = $bodyTag;
199 }
200
201 /**
202 * Gets the standalone view.
203 *
204 * @return StandaloneView
205 */
206 public function getView()
207 {
208 return $this->view;
209 }
210
211 /**
212 * Set content
213 *
214 * @param string $content Content of the module
215 * @return void
216 */
217 public function setContent($content)
218 {
219 $this->view->assign('content', $content);
220 }
221
222 /**
223 * Set title tag
224 *
225 * @param string $title
226 */
227 public function setTitle($title)
228 {
229 $this->title = $title;
230 }
231
232 /**
233 * Returns the IconFactory
234 *
235 * @return IconFactory
236 */
237 public function getIconFactory()
238 {
239 return $this->iconFactory;
240 }
241
242 /**
243 * Class constructor
244 * Sets up view and property objects
245 *
246 * @throws InvalidTemplateResourceException In case a template is invalid
247 */
248 public function __construct()
249 {
250 $this->view = GeneralUtility::makeInstance(StandaloneView::class);
251 $this->view->setPartialRootPaths($this->partialRootPaths);
252 $this->view->setTemplateRootPaths($this->templateRootPaths);
253 $this->view->setLayoutRootPaths($this->layoutRootPaths);
254 $this->view->setTemplate($this->templateFile);
255 $this->pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
256 $this->docHeaderComponent = GeneralUtility::makeInstance(DocHeaderComponent::class);
257 $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
258 }
259
260 /**
261 * Loads all necessary Javascript Files
262 *
263 * @return void
264 */
265 protected function loadJavaScripts()
266 {
267 $this->pageRenderer->loadJquery();
268 $this->pageRenderer->loadRequireJsModule('bootstrap');
269 $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/ContextHelp');
270 $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/DocumentHeader');
271 $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/SplitButtons');
272 }
273
274 /**
275 * Loads all necessary stylesheets
276 *
277 * @return void
278 */
279 protected function loadStylesheets()
280 {
281 if ($GLOBALS['TBE_STYLES']['stylesheet']) {
282 $this->pageRenderer->addCssFile($GLOBALS['TBE_STYLES']['stylesheet']);
283 }
284 if ($GLOBALS['TBE_STYLES']['stylesheet2']) {
285 $this->pageRenderer->addCssFile($GLOBALS['TBE_STYLES']['stylesheet2']);
286 }
287 }
288
289 /**
290 * Sets mandatory parameters for the view (pageRenderer)
291 *
292 * @return void
293 */
294 protected function setupPage()
295 {
296 // Yes, hardcoded on purpose
297 $this->pageRenderer->setXmlPrologAndDocType('<!DOCTYPE html>');
298 $this->pageRenderer->setCharSet('utf-8');
299 $this->pageRenderer->setLanguage('default');
300 $this->pageRenderer->addMetaTag('<meta name="viewport" content="width=device-width, initial-scale=1">');
301 }
302
303 /**
304 * Wrapper function for adding JS inline blocks
305 *
306 * @return void
307 */
308 protected function setJavaScriptCodeArray()
309 {
310 foreach ($this->javascriptCodeArray as $name => $code) {
311 $this->pageRenderer->addJsInlineCode($name, $code, false);
312 }
313 }
314
315 /**
316 * Adds JS inline blocks of code to the internal registry
317 *
318 * @param string $name Javascript code block name
319 * @param string $code Inline Javascript
320 *
321 * @return void
322 */
323 public function addJavaScriptCode($name = '', $code = '')
324 {
325 $this->javascriptCodeArray[$name] = $code;
326 }
327
328 /**
329 * Get the DocHeader
330 *
331 * @return DocHeaderComponent
332 */
333 public function getDocHeaderComponent()
334 {
335 return $this->docHeaderComponent;
336 }
337
338 /**
339 * Returns the fully rendered view
340 *
341 * @return string
342 */
343 public function renderContent()
344 {
345 $this->setupPage();
346 $this->pageRenderer->setTitle($this->title);
347 $this->loadJavaScripts();
348 $this->setJavaScriptCodeArray();
349 $this->loadStylesheets();
350
351 $this->view->assign('docHeader', $this->docHeaderComponent->docHeaderContent());
352 if ($this->moduleId) {
353 $this->view->assign('moduleId', $this->moduleId);
354 }
355 if ($this->moduleName) {
356 $this->view->assign('moduleName', $this->moduleName);
357 }
358 $this->view->assign('flashMessageQueueIdentifier', $this->getFlashMessageQueue()->getIdentifier());
359 $renderedPage = $this->pageRenderer->render(PageRenderer::PART_HEADER);
360 $renderedPage .= $this->bodyTag;
361 $renderedPage .= $this->view->render();
362 $this->pageRenderer->addJsFooterInlineCode('updateSignals', BackendUtility::getUpdateSignalCode());
363 $renderedPage .= $this->pageRenderer->render(PageRenderer::PART_FOOTER);
364
365 return $renderedPage;
366 }
367
368 /**
369 * Get PageRenderer
370 *
371 * @return PageRenderer
372 */
373 public function getPageRenderer()
374 {
375 return $this->pageRenderer;
376 }
377
378 /**
379 * Set form tag
380 *
381 * @param string $formTag Form tag to add
382 *
383 * @return void
384 */
385 public function setForm($formTag = '')
386 {
387 $this->view->assign('formTag', $formTag);
388 }
389
390 /**
391 * Sets the ModuleId
392 *
393 * @param string $moduleId ID of the module
394 *
395 * @return void
396 */
397 public function setModuleId($moduleId)
398 {
399 $this->moduleId = $moduleId;
400 $this->registerModuleMenu($moduleId);
401 }
402
403 /**
404 * Sets the ModuleName
405 *
406 * @param string $moduleName Name of the module
407 *
408 * @return void
409 */
410 public function setModuleName($moduleName)
411 {
412 $this->moduleName = $moduleName;
413 }
414
415 /**
416 * Generates the Menu for things like Web->Info
417 *
418 * @param $moduleMenuIdentifier
419 */
420 public function registerModuleMenu($moduleMenuIdentifier)
421 {
422 if (isset($GLOBALS['TBE_MODULES_EXT'][$moduleMenuIdentifier])) {
423 $menuEntries =
424 $GLOBALS['TBE_MODULES_EXT'][$moduleMenuIdentifier]['MOD_MENU']['function'];
425 $menu = $this->getDocHeaderComponent()->getMenuRegistry()->makeMenu()->setIdentifier('MOD_FUNC');
426 foreach ($menuEntries as $menuEntry) {
427 $menuItem = $menu->makeMenuItem()
428 ->setTitle($menuEntry['title'])
429 ->setHref('#');
430 $menu->addMenuItem($menuItem);
431 }
432 $this->docHeaderComponent->getMenuRegistry()->addMenu($menu);
433 }
434 }
435
436 /**
437 * Creates a tab menu where the tabs or collapsible are rendered with bootstrap markup
438 *
439 * @param array $menuItems Tab elements, each element is an array with "label" and "content"
440 * @param string $domId DOM id attribute, will be appended with an iteration number per tab.
441 * @param int $defaultTabIndex Default tab to open (for toggle <=0). Value corresponds to integer-array index + 1
442 * (index zero is "1", index "1" is 2 etc.). A value of zero (or something non-existing
443 * will result in no default tab open.
444 * @param bool $collapsible If set, the tabs are rendered as headers instead over each sheet. Effectively this means
445 * there is no tab menu, but rather a foldout/fold-in menu.
446 * @param bool $wrapContent If set, the content is wrapped in div structure which provides a padding and border
447 * style. Set this FALSE to get unstyled content pane with fullsize content area.
448 * @param bool $storeLastActiveTab If set, the last open tab is stored in local storage and will be re-open again.
449 * If you don't need this feature, e.g. for wizards like import/export you can
450 * disable this behaviour.
451 * @return string
452 */
453 public function getDynamicTabMenu(array $menuItems, $domId, $defaultTabIndex = 1, $collapsible = false, $wrapContent = true, $storeLastActiveTab = true)
454 {
455 $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Tabs');
456 $templatePathAndFileName = 'EXT:backend/Resources/Private/Templates/DocumentTemplate/' . ($collapsible ? 'Collapse.html' : 'Tabs.html');
457 $view = GeneralUtility::makeInstance(StandaloneView::class);
458 $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName($templatePathAndFileName));
459 $view->assignMultiple(array(
460 'id' => 'DTM-' . GeneralUtility::shortMD5($domId),
461 'items' => $menuItems,
462 'defaultTabIndex' => $defaultTabIndex,
463 'wrapContent' => $wrapContent,
464 'storeLastActiveTab' => $storeLastActiveTab,
465 ));
466 return $view->render();
467 }
468
469 /*******************************************
470 * THE FOLLOWING METHODS ARE SUBJECT TO BE DEPRECATED / DROPPED!
471 *
472 * These methods have been copied over from DocumentTemplate and enables
473 * core modules to drop the dependency to DocumentTemplate altogether without
474 * rewriting these modules now.
475 * The methods below are marked as internal and will be removed
476 * one-by-one with further refactoring of modules.
477 *
478 * Do not use these methods within own extensions if possible or
479 * be prepared to change this later again.
480 *******************************************/
481
482 /**
483 * Includes a javascript library that exists in the core /typo3/ directory
484 *
485 * @param string $lib Library name. Call it with the full path like
486 * "sysext/core/Resources/Public/JavaScript/QueryGenerator.js" to load it
487 *
488 * @return void
489 * @internal
490 */
491 public function loadJavascriptLib($lib)
492 {
493 // @todo: maybe we can remove this one as well
494 $this->pageRenderer->addJsFile($lib);
495 }
496
497 /**
498 * Returns a linked shortcut-icon which will call the shortcut frame and set a
499 * shortcut there back to the calling page/module
500 *
501 * @param string $gvList Is the list of GET variables to store (if any)
502 * @param string $setList Is the list of SET[] variables to store
503 * (if any) - SET[] variables a stored in $GLOBALS["SOBE"]->MOD_SETTINGS
504 * for backend modules
505 * @param string $modName Module name string
506 * @param string|int $motherModName Is used to enter the "parent module
507 * name" if the module is a submodule under eg. Web>* or File>*. You
508 * can also set this value to 1 in which case the currentLoadedModule
509 * is sent to the shortcut script (so - not a fixed value!) - that is used
510 * in file_edit and wizard_rte modules where those are really running as
511 * a part of another module.
512 * @param string $displayName When given this name is used instead of the
513 * module name.
514 * @param string $classes Additional CSS classes for the link around the icon
515 *
516 * @return string HTML content
517 * @todo Make this thing return a button object
518 * @internal
519 */
520 public function makeShortcutIcon($gvList, $setList, $modName, $motherModName = '', $displayName = '', $classes = 'btn btn-default btn-sm')
521 {
522 $gvList = 'route,' . $gvList;
523 $storeUrl = $this->makeShortcutUrl($gvList, $setList);
524 $pathInfo = parse_url(GeneralUtility::getIndpEnv('REQUEST_URI'));
525 // Fallback for alt_mod. We still pass in the old xMOD... stuff,
526 // but TBE_MODULES only knows about "record_edit".
527 // We still need to pass the xMOD name to createShortcut below,
528 // since this is used for icons.
529 $moduleName = $modName === 'xMOD_alt_doc.php' ? 'record_edit' : $modName;
530 // Add the module identifier automatically if typo3/index.php is used:
531 if (GeneralUtility::_GET('M') !== null && isset($GLOBALS['TBE_MODULES']['_PATHS'][$moduleName])) {
532 $storeUrl = '&M=' . $moduleName . $storeUrl;
533 }
534 if ((int)$motherModName === 1) {
535 $motherModule = 'top.currentModuleLoaded';
536 } elseif ($motherModName) {
537 $motherModule = GeneralUtility::quoteJSvalue($motherModName);
538 } else {
539 $motherModule = '\'\'';
540 }
541 $confirmationText = GeneralUtility::quoteJSvalue(
542 $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.makeBookmark')
543 );
544
545 $shortcutUrl = $pathInfo['path'] . '?' . $storeUrl;
546 $shortcutExist = BackendUtility::shortcutExists($shortcutUrl);
547
548 if ($shortcutExist) {
549 return '<a class="active ' . htmlspecialchars($classes) . '" title="">' .
550 $this->iconFactory->getIcon('actions-system-shortcut-active', Icon::SIZE_SMALL)->render() . '</a>';
551 }
552
553 $url = GeneralUtility::quoteJSvalue(rawurlencode($shortcutUrl));
554 $onClick = 'top.TYPO3.ShortcutMenu.createShortcut(' . GeneralUtility::quoteJSvalue(rawurlencode($modName)) .
555 ', ' . $url . ', ' . $confirmationText . ', ' . $motherModule . ', this, ' . GeneralUtility::quoteJSvalue($displayName) . ');return false;';
556
557 return '<a href="#" class="' . htmlspecialchars($classes) . '" onclick="' . htmlspecialchars($onClick) . '" title="' .
558 $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.makeBookmark', true) . '">' .
559 $this->iconFactory->getIcon('actions-system-shortcut-new', Icon::SIZE_SMALL)->render() . '</a>';
560 }
561
562 /**
563 * MAKE url for storing
564 * Internal func
565 *
566 * @param string $gvList Is the list of GET variables to store (if any)
567 * @param string $setList Is the list of SET[] variables to store (if any)
568 * - SET[] variables a stored in $GLOBALS["SOBE"]->MOD_SETTINGS for backend
569 * modules
570 *
571 * @return string
572 * @internal
573 */
574 public function makeShortcutUrl($gvList, $setList)
575 {
576 $getParams = GeneralUtility::_GET();
577 $storeArray = array_merge(
578 GeneralUtility::compileSelectedGetVarsFromArray($gvList, $getParams),
579 array('SET' => GeneralUtility::compileSelectedGetVarsFromArray($setList, (array)$GLOBALS['SOBE']->MOD_SETTINGS))
580 );
581 return GeneralUtility::implodeArrayForUrl('', $storeArray);
582 }
583
584 /**
585 * Creates the version selector for the page id inputted.
586 * Requires the core version management extension, "version" to be loaded.
587 *
588 * @param int $id Page id to create selector for.
589 * @param bool $noAction If set, there will be no button for swapping page.
590 *
591 * @return string
592 * @internal
593 */
594 public function getVersionSelector($id, $noAction = false)
595 {
596 if (ExtensionManagementUtility::isLoaded('version')
597 && !ExtensionManagementUtility::isLoaded('workspaces')
598 ) {
599 /**
600 * For Code Completion
601 *
602 * @var $versionGuiObj VersionView
603 */
604 $versionGuiObj = GeneralUtility::makeInstance(VersionView::class);
605 return $versionGuiObj->getVersionSelector($id, $noAction);
606 }
607 return '';
608 }
609
610 /**
611 * Begins an output section and sets header and content
612 *
613 * @param string $label The header
614 * @param string $text The HTML-content
615 * @param bool $noStrToUpper A flag that will prevent the header from
616 * being converted to uppercase
617 * @param bool $sH Defines the type of header (if set, "<h3>" rather
618 * than the default "h4")
619 * @param int $type The number of an icon to show with the header
620 * (see the icon-function). -1,1,2,3
621 * @param bool $allowHtmlInHeader If set, HTML tags are allowed in
622 * $label (otherwise this value is by default htmlspecialchars()'ed)
623 *
624 * @return string HTML content
625 * @internal
626 */
627 public function section($label, $text, $noStrToUpper = false, $sH = false, $type = 0, $allowHtmlInHeader = false)
628 {
629 $str = '';
630 // Setting header
631 if ($label) {
632 if (!$allowHtmlInHeader) {
633 $label = htmlspecialchars($label);
634 }
635 $str .= $this->sectionHeader($this->icons($type) . $label, $sH, $noStrToUpper ? '' : ' class="uppercase"');
636 }
637 // Setting content
638 $str .= '
639
640 <!-- Section content -->
641 ' . $text;
642 return $this->sectionBegin() . $str;
643 }
644
645 /**
646 * Inserts a divider image
647 * Ends a section (if open) before inserting the image
648 *
649 * @param int $dist The margin-top/-bottom of the <hr> ruler.
650 *
651 * @return string HTML content
652 * @internal
653 */
654 public function divider($dist)
655 {
656 $dist = (int)$dist;
657 $str = '
658
659 <!-- DIVIDER -->
660 <hr style="margin-top: ' . $dist . 'px; margin-bottom: ' . $dist . 'px;" />
661 ';
662 return $this->sectionEnd() . $str;
663 }
664
665 /**
666 * Make a section header.
667 * Begins a section if not already open.
668 *
669 * @param string $label The label between the <h3> or <h4> tags. (Allows HTML)
670 * @param bool $sH If set, <h3> is used, otherwise <h4>
671 * @param string $addAttribute Additional attributes to h-tag, eg. ' class=""'
672 *
673 * @return string HTML content
674 * @internal
675 */
676 public function sectionHeader($label, $sH = false, $addAttribute = '')
677 {
678 $tag = $sH ? 'h2' : 'h3';
679 if ($addAttribute && $addAttribute[0] !== ' ') {
680 $addAttribute = ' ' . $addAttribute;
681 }
682 $str = '
683
684 <!-- Section header -->
685 <' . $tag . $addAttribute . '>' . $label . '</' . $tag . '>
686 ';
687 return $this->sectionBegin() . $str;
688 }
689
690 /**
691 * Begins an output section.
692 * Returns the <div>-begin tag AND sets the ->sectionFlag TRUE
693 * (if the ->sectionFlag is not already set!)
694 * You can call this function even if a section is already begun
695 * since the function will only return something if the sectionFlag
696 * is not already set!
697 *
698 * @return string HTML content
699 * @internal
700 */
701 public function sectionBegin()
702 {
703 if (!$this->sectionFlag) {
704 $this->sectionFlag = 1;
705 $str = '
706
707 <!-- ***********************
708 Begin output section.
709 *********************** -->
710 <div>
711 ';
712 return $str;
713 }
714 return '';
715 }
716
717 /**
718 * Ends and output section
719 * Returns the </div>-end tag AND clears the ->sectionFlag
720 * (but does so only IF the sectionFlag is set - that is a section is 'open')
721 * See sectionBegin() also.
722 *
723 * @return string HTML content
724 * @internal
725 */
726 public function sectionEnd()
727 {
728 if ($this->sectionFlag) {
729 $this->sectionFlag = 0;
730 return '
731 </div>
732 <!-- *********************
733 End output section.
734 ********************* -->
735 ';
736 }
737 return '';
738 }
739
740 /**
741 * Returns the BE USER Object
742 *
743 * @return BackendUserAuthentication
744 */
745 protected function getBackendUserAuthentication()
746 {
747 return $GLOBALS['BE_USER'];
748 }
749
750 /**
751 * Returns the LanguageService
752 *
753 * @return LanguageService
754 */
755 protected function getLanguageService()
756 {
757 return $GLOBALS['LANG'];
758 }
759
760 /**
761 * Returns an image-tag with an 18x16 icon of the following types:
762 *
763 * $type:
764 * -1:» OK icon (Check-mark)
765 * 1:» Notice (Speach-bubble)
766 * 2:» Warning (Yellow triangle)
767 * 3:» Fatal error (Red stop sign)
768 *
769 * @param int $type See description
770 *
771 * @return string HTML image tag (if applicable)
772 * @internal
773 */
774 public function icons($type)
775 {
776 $icon = '';
777 switch ($type) {
778 case self::STATUS_ICON_ERROR:
779 $icon = 'status-dialog-error';
780 break;
781 case self::STATUS_ICON_WARNING:
782 $icon = 'status-dialog-warning';
783 break;
784 case self::STATUS_ICON_NOTIFICATION:
785 $icon = 'status-dialog-notification';
786 break;
787 case self::STATUS_ICON_OK:
788 $icon = 'status-dialog-ok';
789 break;
790 default:
791 // Do nothing
792 }
793 if ($icon != '') {
794 return $this->iconFactory->getIcon($icon, Icon::SIZE_SMALL)->render();
795 }
796 return '';
797 }
798
799 /**
800 * Returns JavaScript variables setting the returnUrl and thisScript location for use by JavaScript on the page.
801 * Used in fx. db_list.php (Web>List)
802 *
803 * @param string $thisLocation URL to "this location" / current script
804 * @return string Urls are returned as JavaScript variables T3_RETURN_URL and T3_THIS_LOCATION
805 * @see typo3/db_list.php
806 * @internal
807 */
808 public function redirectUrls($thisLocation = '')
809 {
810 $thisLocation = $thisLocation ? $thisLocation : GeneralUtility::linkThisScript(array(
811 'CB' => '',
812 'SET' => '',
813 'cmd' => '',
814 'popViewId' => ''
815 ));
816 $out = '
817 var T3_RETURN_URL = ' . GeneralUtility::quoteJSvalue(str_replace('%20', '', rawurlencode(GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'))))) . ';
818 var T3_THIS_LOCATION = ' . GeneralUtility::quoteJSvalue(str_replace('%20', '', rawurlencode($thisLocation))) . '
819 ';
820 return $out;
821 }
822
823 /**
824 * Returns the header-bar in the top of most backend modules
825 * Closes section if open.
826 *
827 * @param string $text The text string for the header
828 * @return string HTML content
829 * @internal
830 */
831 public function header($text)
832 {
833 $str = '
834
835 <!-- MAIN Header in page top -->
836 <h1 class="t3js-title-inlineedit">' . htmlspecialchars($text) . '</h1>
837 ';
838 return $this->sectionEnd() . $str;
839 }
840
841 /**
842 * Creates a Message object and adds it to the FlashMessageQueue.
843 *
844 * @param string $messageBody The message
845 * @param string $messageTitle Optional message title
846 * @param int $severity Optional severity, must be one of \TYPO3\CMS\Core\Messaging\FlashMessage constants
847 * @param bool $storeInSession Optional, defines whether the message should be stored in the session (default)
848 * @return void
849 * @throws \InvalidArgumentException if the message body is no string
850 */
851 public function addFlashMessage($messageBody, $messageTitle = '', $severity = AbstractMessage::OK, $storeInSession = true)
852 {
853 if (!is_string($messageBody)) {
854 throw new \InvalidArgumentException('The message body must be of type string, "' . gettype($messageBody) . '" given.', 1446483133);
855 }
856 /* @var \TYPO3\CMS\Core\Messaging\FlashMessage $flashMessage */
857 $flashMessage = GeneralUtility::makeInstance(
858 \TYPO3\CMS\Core\Messaging\FlashMessage::class,
859 $messageBody,
860 $messageTitle,
861 $severity,
862 $storeInSession
863 );
864 $this->getFlashMessageQueue()->enqueue($flashMessage);
865 }
866
867 /**
868 * @param \TYPO3\CMS\Core\Messaging\FlashMessageQueue $flashMessageQueue
869 */
870 public function setFlashMessageQueue($flashMessageQueue)
871 {
872 $this->flashMessageQueue = $flashMessageQueue;
873 }
874
875 /**
876 * @return \TYPO3\CMS\Core\Messaging\FlashMessageQueue
877 */
878 protected function getFlashMessageQueue()
879 {
880 if (!isset($this->flashMessageQueue)) {
881 /** @var FlashMessageService $service */
882 $service = GeneralUtility::makeInstance(FlashMessageService::class);
883 $this->flashMessageQueue = $service->getMessageQueueByIdentifier();
884 }
885 return $this->flashMessageQueue;
886 }
887 }