TYPO3 CMS  TYPO3_8-7
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 
22 
83 {
85 
91  protected $escapeOutput = false;
92 
98  public function initializeArguments()
99  {
100  parent::initializeArguments();
101  $this->registerArgument('queueIdentifier', 'string', 'Flash-message queue to use');
102  $this->registerArgument('as', 'string', 'The name of the current flashMessage variable for rendering inside');
103  }
104 
116  public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
117  {
118  $as = $arguments['as'];
119  $queueIdentifier = isset($arguments['queueIdentifier']) ? $arguments['queueIdentifier'] : null;
120  $flashMessages = $renderingContext->getControllerContext()
121  ->getFlashMessageQueue($queueIdentifier)->getAllMessagesAndFlush();
122  if ($flashMessages === null || count($flashMessages) === 0) {
123  return '';
124  }
125 
126  if ($as === null) {
127  return GeneralUtility::makeInstance(FlashMessageRendererResolver::class)
128  ->resolve()
129  ->render($flashMessages);
130  }
131  $templateVariableContainer = $renderingContext->getVariableProvider();
132  $templateVariableContainer->add($as, $flashMessages);
133  $content = $renderChildrenClosure();
134  $templateVariableContainer->remove($as);
135 
136  return $content;
137  }
138 }
static makeInstance($className,... $constructorArguments)
static renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)