TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
FlashMessage.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Core\Messaging;
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 
21 {
27  protected $storeInSession = false;
28 
32  protected $classes = [
33  self::NOTICE => 'notice',
34  self::INFO => 'info',
35  self::OK => 'success',
36  self::WARNING => 'warning',
37  self::ERROR => 'danger'
38  ];
39 
43  protected $icons = [
44  self::NOTICE => 'lightbulb-o',
45  self::INFO => 'info',
46  self::OK => 'check',
47  self::WARNING => 'exclamation',
48  self::ERROR => 'times'
49  ];
50 
59  public function __construct($message, $title = '', $severity = self::OK, $storeInSession = false)
60  {
61  $this->setMessage($message);
62  $this->setTitle($title);
63  $this->setSeverity($severity);
65  }
66 
72  public function isSessionMessage()
73  {
74  return $this->storeInSession;
75  }
76 
84  {
85  $this->storeInSession = (bool)$storeInSession;
86  }
87 
93  public function getClass()
94  {
95  return 'alert-' . $this->classes[$this->severity];
96  }
97 
103  public function getIconName()
104  {
105  return $this->icons[$this->severity];
106  }
107 
113  public function getMessageAsMarkup()
114  {
115  $messageTitle = $this->getTitle();
116  $markup = [];
117  $markup[] = '<div class="alert ' . htmlspecialchars($this->getClass()) . '">';
118  $markup[] = ' <div class="media">';
119  $markup[] = ' <div class="media-left">';
120  $markup[] = ' <span class="fa-stack fa-lg">';
121  $markup[] = ' <i class="fa fa-circle fa-stack-2x"></i>';
122  $markup[] = ' <i class="fa fa-' . htmlspecialchars($this->getIconName()) . ' fa-stack-1x"></i>';
123  $markup[] = ' </span>';
124  $markup[] = ' </div>';
125  $markup[] = ' <div class="media-body">';
126  if (!empty($messageTitle)) {
127  $markup[] = ' <h4 class="alert-title">' . htmlspecialchars($messageTitle) . '</h4>';
128  }
129  $markup[] = ' <p class="alert-message">' . htmlspecialchars($this->getMessage()) . '</p>';
130  $markup[] = ' </div>';
131  $markup[] = ' </div>';
132  $markup[] = '</div>';
133  return implode('', $markup);
134  }
135 }
__construct($message, $title= '', $severity=self::OK, $storeInSession=false)