‪TYPO3CMS  10.4
FlashMessagesViewHelper.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
20 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
21 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
22 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
23 
95 class ‪FlashMessagesViewHelper extends AbstractViewHelper
96 {
97  use CompileWithRenderStatic;
98 
104  protected ‪$escapeOutput = false;
105 
109  public function ‪initializeArguments()
110  {
111  $this->registerArgument('queueIdentifier', 'string', 'Flash-message queue to use');
112  $this->registerArgument('as', 'string', 'The name of the current flashMessage variable for rendering inside');
113  }
114 
129  public static function ‪renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
130  {
131  $as = $arguments['as'];
132  $queueIdentifier = $arguments['queueIdentifier'] ?? null;
133  $flashMessages = $renderingContext->getControllerContext()
134  ->getFlashMessageQueue($queueIdentifier)->getAllMessagesAndFlush();
135  if ($flashMessages === null || count($flashMessages) === 0) {
136  return '';
137  }
138 
139  if ($as === null) {
140  return GeneralUtility::makeInstance(FlashMessageRendererResolver::class)
141  ->resolve()
142  ->render($flashMessages);
143  }
144  $templateVariableContainer = $renderingContext->getVariableProvider();
145  $templateVariableContainer->add($as, $flashMessages);
146  $content = $renderChildrenClosure();
147  $templateVariableContainer->remove($as);
148 
149  return $content;
150  }
151 }
‪TYPO3\CMS\Fluid\ViewHelpers\FlashMessagesViewHelper\initializeArguments
‪initializeArguments()
Definition: FlashMessagesViewHelper.php:107
‪TYPO3\CMS\Fluid\ViewHelpers\FlashMessagesViewHelper\$escapeOutput
‪bool $escapeOutput
Definition: FlashMessagesViewHelper.php:102
‪TYPO3\CMS\Core\Messaging\FlashMessageRendererResolver
Definition: FlashMessageRendererResolver.php:31
‪TYPO3\CMS\Fluid\ViewHelpers
‪TYPO3\CMS\Fluid\ViewHelpers\FlashMessagesViewHelper
Definition: FlashMessagesViewHelper.php:96
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Fluid\ViewHelpers\FlashMessagesViewHelper\renderStatic
‪static mixed renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
Definition: FlashMessagesViewHelper.php:127