TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
FlashMessagesViewHelper.php
Go to the documentation of this file.
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  */
17 
87 {
91  protected $tagName = 'div';
92 
99  public function initializeArguments()
100  {
101  parent::initializeArguments();
103  $this->registerArgument('queueIdentifier', 'string', 'Flash-message queue to use');
104  $this->registerArgument('as', 'string', 'The name of the current flashMessage variable for rendering inside');
105  }
106 
116  public function render()
117  {
118  $as = $this->arguments['as'];
119  $queueIdentifier = isset($this->arguments['queueIdentifier']) ? $this->arguments['queueIdentifier'] : null;
120  $flashMessages = $this->renderingContext->getControllerContext()->getFlashMessageQueue($queueIdentifier)->getAllMessagesAndFlush();
121  if ($flashMessages === null || count($flashMessages) === 0) {
122  return '';
123  }
124 
125  if ($as === null) {
126  $content = $this->renderDefault($flashMessages);
127  } else {
128  $content = $this->renderFromTemplate($flashMessages, $as);
129  }
130 
131  return $content;
132  }
133 
140  protected function renderDefault(array $flashMessages)
141  {
142  $flashMessagesClass = $this->hasArgument('class') ? $this->arguments['class'] : 'typo3-messages';
143  $tagContent = '';
144  $this->tag->addAttribute('class', $flashMessagesClass);
146  foreach ($flashMessages as $singleFlashMessage) {
147  $tagContent .= $singleFlashMessage->getMessageAsMarkup();
148  }
149  $this->tag->setContent($tagContent);
150  return $this->tag->render();
151  }
152 
163  protected function renderFromTemplate(array $flashMessages, $as)
164  {
165  $templateVariableContainer = $this->renderingContext->getVariableProvider();
166  $templateVariableContainer->add($as, $flashMessages);
167  $content = $this->renderChildren();
168  $templateVariableContainer->remove($as);
169 
170  return $content;
171  }
172 }