[BUGFIX] Remove superflous parameter that blocks the test
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / FlashMessagesViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Fluid\ViewHelpers;
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\Core\Messaging\FlashMessageRendererResolver;
18 use TYPO3\CMS\Core\Utility\GeneralUtility;
19 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
20 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
21 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
22
23 /**
24 * View helper which renders the flash messages (if there are any) as an unsorted list.
25 *
26 * In case you need custom Flash Message HTML output, please write your own ViewHelper for the moment.
27 *
28 *
29 * Examples
30 * ========
31 *
32 * Simple::
33 *
34 * <f:flashMessages />
35 *
36 * A list of flash messages.
37 *
38 * TYPO3 core style::
39 *
40 * <f:flashMessages />
41 *
42 * Output::
43 *
44 * <div class="typo3-messages">
45 * <div class="alert alert-info">
46 * <div class="media">
47 * <div class="media-left">
48 * <span class="fa-stack fa-lg">
49 * <i class="fa fa-circle fa-stack-2x"></i>
50 * <i class="fa fa-info fa-stack-1x"></i>
51 * </span>
52 * </div>
53 * <div class="media-body">
54 * <h4 class="alert-title">Info - Title for Info message</h4>
55 * <p class="alert-message">Message text here.</p>
56 * </div>
57 * </div>
58 * </div>
59 * </div>
60 *
61 * Output flash messages as a description list::
62 *
63 * <f:flashMessages as="flashMessages">
64 * <dl class="messages">
65 * <f:for each="{flashMessages}" as="flashMessage">
66 * <dt>{flashMessage.code}</dt>
67 * <dd>{flashMessage.message}</dd>
68 * </f:for>
69 * </dl>
70 * </f:flashMessages>
71 *
72 * Output::
73 *
74 * <dl class="messages">
75 * <dt>1013</dt>
76 * <dd>Some Warning Message.</dd>
77 * </dl>
78 *
79 * Using a specific queue::
80 *
81 * <f:flashMessages queueIdentifier="myQueue" />
82 */
83 class FlashMessagesViewHelper extends AbstractViewHelper
84 {
85 use CompileWithRenderStatic;
86
87 /**
88 * ViewHelper outputs HTML therefore output escaping has to be disabled
89 *
90 * @var bool
91 */
92 protected $escapeOutput = false;
93
94 /**
95 * Initialize arguments
96 */
97 public function initializeArguments()
98 {
99 $this->registerArgument('queueIdentifier', 'string', 'Flash-message queue to use');
100 $this->registerArgument('as', 'string', 'The name of the current flashMessage variable for rendering inside');
101 }
102
103 /**
104 * Renders FlashMessages and flushes the FlashMessage queue
105 * Note: This disables the current page cache in order to prevent FlashMessage output
106 * from being cached.
107 *
108 * @see \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController::no_cache
109 * @param array $arguments
110 * @param \Closure $renderChildrenClosure
111 * @param RenderingContextInterface $renderingContext
112 * @return mixed
113 */
114 public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
115 {
116 $as = $arguments['as'];
117 $queueIdentifier = $arguments['queueIdentifier'] ?? null;
118 $flashMessages = $renderingContext->getControllerContext()
119 ->getFlashMessageQueue($queueIdentifier)->getAllMessagesAndFlush();
120 if ($flashMessages === null || count($flashMessages) === 0) {
121 return '';
122 }
123
124 if ($as === null) {
125 return GeneralUtility::makeInstance(FlashMessageRendererResolver::class)
126 ->resolve()
127 ->render($flashMessages);
128 }
129 $templateVariableContainer = $renderingContext->getVariableProvider();
130 $templateVariableContainer->add($as, $flashMessages);
131 $content = $renderChildrenClosure();
132 $templateVariableContainer->remove($as);
133
134 return $content;
135 }
136 }