[!!!][FEATURE] Refactoring of FlashMessage rendering
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Messaging / FlashMessage.php
1 <?php
2 declare(strict_types=1);
3 namespace TYPO3\CMS\Core\Messaging;
4
5 /*
6 * This file is part of the TYPO3 CMS project.
7 *
8 * It is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, either version 2
10 * of the License, or any later version.
11 *
12 * For the full copyright and license information, please read the
13 * LICENSE.txt file that was distributed with this source code.
14 *
15 * The TYPO3 project - inspiring people to share!
16 */
17
18 use TYPO3\CMS\Core\Utility\GeneralUtility;
19
20 /**
21 * A class representing flash messages.
22 */
23 class FlashMessage extends AbstractMessage
24 {
25 /**
26 * Defines whether the message should be stored in the session (to survive redirects) or only for one request (default)
27 *
28 * @var bool
29 */
30 protected $storeInSession = false;
31
32 /**
33 * @var string The message severity class names
34 * @deprecated since TYPO3 v8, will be removed in TYPO3 v9
35 */
36 protected $classes = [
37 self::NOTICE => 'notice',
38 self::INFO => 'info',
39 self::OK => 'success',
40 self::WARNING => 'warning',
41 self::ERROR => 'danger'
42 ];
43
44 /**
45 * @var string The message severity icon names
46 * @deprecated since TYPO3 v8, will be removed in TYPO3 v9
47 */
48 protected $icons = [
49 self::NOTICE => 'lightbulb-o',
50 self::INFO => 'info',
51 self::OK => 'check',
52 self::WARNING => 'exclamation',
53 self::ERROR => 'times'
54 ];
55
56 /**
57 * Constructor for a flash message
58 *
59 * @param string $message The message.
60 * @param string $title Optional message title.
61 * @param int $severity Optional severity, must be either of one of \TYPO3\CMS\Core\Messaging\FlashMessage constants
62 * @param bool $storeInSession Optional, defines whether the message should be stored in the session or only for one request (default)
63 */
64 public function __construct($message, $title = '', $severity = self::OK, $storeInSession = false)
65 {
66 $this->setMessage($message);
67 $this->setTitle($title);
68 $this->setSeverity($severity);
69 $this->setStoreInSession($storeInSession);
70 }
71
72 /**
73 * Gets the message's storeInSession flag.
74 *
75 * @return bool TRUE if message should be stored in the session, otherwise FALSE.
76 */
77 public function isSessionMessage()
78 {
79 return $this->storeInSession;
80 }
81
82 /**
83 * Sets the message's storeInSession flag
84 *
85 * @param bool $storeInSession The persistence flag
86 * @return void
87 */
88 public function setStoreInSession($storeInSession)
89 {
90 $this->storeInSession = (bool)$storeInSession;
91 }
92
93 /**
94 * Gets the message severity class name
95 *
96 * @return string The message severity class name
97 * @deprecated since TYPO3 v8, will be removed in TYPO3 v9
98 */
99 public function getClass()
100 {
101 GeneralUtility::logDeprecatedFunction();
102 return 'alert-' . $this->classes[$this->severity];
103 }
104
105 /**
106 * Gets the message severity icon name
107 *
108 * @return string The message severity icon name
109 * @deprecated since TYPO3 v8, will be removed in TYPO3 v9
110 */
111 public function getIconName()
112 {
113 GeneralUtility::logDeprecatedFunction();
114 return $this->icons[$this->severity];
115 }
116 }