‪TYPO3CMS  9.5
FlashMessagesViewHelper.php
Go to the documentation of this file.
1 <?php
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 
19 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
20 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
21 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
22 
94 class ‪FlashMessagesViewHelper extends AbstractViewHelper
95 {
96  use CompileWithRenderStatic;
97 
103  protected ‪$escapeOutput = false;
104 
108  public function ‪initializeArguments()
109  {
110  $this->registerArgument('queueIdentifier', 'string', 'Flash-message queue to use');
111  $this->registerArgument('as', 'string', 'The name of the current flashMessage variable for rendering inside');
112  }
113 
125  public static function ‪renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
126  {
127  $as = $arguments['as'];
128  $queueIdentifier = $arguments['queueIdentifier'] ?? null;
129  $flashMessages = $renderingContext->getControllerContext()
130  ->getFlashMessageQueue($queueIdentifier)->getAllMessagesAndFlush();
131  if ($flashMessages === null || count($flashMessages) === 0) {
132  return '';
133  }
134 
135  if ($as === null) {
136  return GeneralUtility::makeInstance(FlashMessageRendererResolver::class)
137  ->resolve()
138  ->render($flashMessages);
139  }
140  $templateVariableContainer = $renderingContext->getVariableProvider();
141  $templateVariableContainer->add($as, $flashMessages);
142  $content = $renderChildrenClosure();
143  $templateVariableContainer->remove($as);
144 
145  return $content;
146  }
147 }
‪TYPO3\CMS\Fluid\ViewHelpers\FlashMessagesViewHelper\initializeArguments
‪initializeArguments()
Definition: FlashMessagesViewHelper.php:106
‪TYPO3\CMS\Fluid\ViewHelpers\FlashMessagesViewHelper\$escapeOutput
‪bool $escapeOutput
Definition: FlashMessagesViewHelper.php:101
‪TYPO3\CMS\Core\Messaging\FlashMessageRendererResolver
Definition: FlashMessageRendererResolver.php:26
‪TYPO3\CMS\Fluid\ViewHelpers
Definition: BaseViewHelper.php:2
‪TYPO3\CMS\Fluid\ViewHelpers\FlashMessagesViewHelper
Definition: FlashMessagesViewHelper.php:95
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Fluid\ViewHelpers\FlashMessagesViewHelper\renderStatic
‪static mixed renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
Definition: FlashMessagesViewHelper.php:123