Commit cca34951 by Alexander Makarov

Fixes #3979: Alert widget in advanced app is now able to display multiple flash…

Fixes #3979: Alert widget in advanced app is now able to display multiple flash messages of the same type
parent b12f4dd7
......@@ -11,9 +11,17 @@ namespace frontend\widgets;
* Alert widget renders a message from session flash. All flash messages are displayed
* in the sequence they were assigned using setFlash. You can set message as following:
*
* - \Yii::$app->getSession()->setFlash('error', 'This is the message');
* - \Yii::$app->getSession()->setFlash('success', 'This is the message');
* - \Yii::$app->getSession()->setFlash('info', 'This is the message');
* ```php
* \Yii::$app->getSession()->setFlash('error', 'This is the message');
* \Yii::$app->getSession()->setFlash('success', 'This is the message');
* \Yii::$app->getSession()->setFlash('info', 'This is the message');
* ```
*
* Multiple messages could be set as follows:
*
* ```php
* \Yii::$app->getSession()->setFlash('error', ['Error 1', 'Error 2']);
* ```
*
* @author Kartik Visweswaran <kartikv2@gmail.com>
* @author Alexander Makarov <sam@rmcreative.ru>
......@@ -47,8 +55,10 @@ class Alert extends \yii\bootstrap\Widget
$flashes = $session->getAllFlashes();
$appendCss = isset($this->options['class']) ? ' ' . $this->options['class'] : '';
foreach ($flashes as $type => $message) {
foreach ($flashes as $type => $data) {
if (isset($this->alertTypes[$type])) {
$data = (array) $data;
foreach ($data as $message) {
/* initialize css class for each alert box */
$this->options['class'] = $this->alertTypes[$type] . $appendCss;
......@@ -60,6 +70,7 @@ class Alert extends \yii\bootstrap\Widget
'closeButton' => $this->closeButton,
'options' => $this->options,
]);
}
$session->removeFlash($type);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment