TYPO3 CMS  TYPO3_6-2
FlashMessagesViewHelper.php
Go to the documentation of this file.
1 <?php
3 
4 /* *
5  * This script is backported from the TYPO3 Flow package "TYPO3.Fluid". *
6  * *
7  * It is free software; you can redistribute it and/or modify it under *
8  * the terms of the GNU Lesser General Public License, either version 3 *
9  * of the License, or (at your option) any later version. *
10  * *
11  * *
12  * This script is distributed in the hope that it will be useful, but *
13  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
14  * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
15  * General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU Lesser General Public *
18  * License along with the script. *
19  * If not, see http://www.gnu.org/licenses/lgpl.html *
20  * *
21  * The TYPO3 project - inspiring people to share! *
22  * */
65 
66  const RENDER_MODE_UL = 'ul';
67  const RENDER_MODE_DIV = 'div';
68 
72  protected $contentObject;
73 
78 
83  public function injectConfigurationManager(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager) {
84  $this->configurationManager = $configurationManager;
85  $this->contentObject = $this->configurationManager->getContentObject();
86  }
87 
94  public function initializeArguments() {
96  }
97 
108  public function render($renderMode = self::RENDER_MODE_UL) {
109  $flashMessages = $this->controllerContext->getFlashMessageQueue()->getAllMessagesAndFlush();
110  if ($flashMessages === NULL || count($flashMessages) === 0) {
111  return '';
112  }
113  if (isset($GLOBALS['TSFE']) && $this->contentObject->getUserObjectType() === \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::OBJECTTYPE_USER) {
114  $GLOBALS['TSFE']->no_cache = 1;
115  }
116  switch ($renderMode) {
117  case self::RENDER_MODE_UL:
118  return $this->renderUl($flashMessages);
119  case self::RENDER_MODE_DIV:
120  return $this->renderDiv($flashMessages);
121  default:
122  throw new \TYPO3\CMS\Fluid\Core\ViewHelper\Exception('Invalid render mode "' . $renderMode . '" passed to FlashMessageViewhelper', 1290697924);
123  }
124  }
125 
132  protected function renderUl(array $flashMessages) {
133  $this->tag->setTagName('ul');
134  if ($this->hasArgument('class')) {
135  $this->tag->addAttribute('class', $this->arguments['class']);
136  }
137  $tagContent = '';
138  foreach ($flashMessages as $singleFlashMessage) {
139  $tagContent .= '<li>' . htmlspecialchars($singleFlashMessage->getMessage()) . '</li>';
140  }
141  $this->tag->setContent($tagContent);
142  return $this->tag->render();
143  }
144 
151  protected function renderDiv(array $flashMessages) {
152  $this->tag->setTagName('div');
153  if ($this->hasArgument('class')) {
154  $this->tag->addAttribute('class', $this->arguments['class']);
155  } else {
156  $this->tag->addAttribute('class', 'typo3-messages');
157  }
158  $tagContent = '';
159  foreach ($flashMessages as $singleFlashMessage) {
160  $tagContent .= $singleFlashMessage->render();
161  }
162  $this->tag->setContent($tagContent);
163  return $this->tag->render();
164  }
165 }
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
injectConfigurationManager(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager)