Commit 62493188 by Kartik Visweswaran

Nomenclature and code realignment.

1. Renamed closeButton to closeButtonOptions. 2. Generate unique id for each alert box. 3. Moved parent init to the top.
parent 2bff5f80
...@@ -15,8 +15,8 @@ namespace frontend\widgets; ...@@ -15,8 +15,8 @@ namespace frontend\widgets;
* - \Yii::$app->getSession()->setFlash('success', 'This is the message'); * - \Yii::$app->getSession()->setFlash('success', 'This is the message');
* - \Yii::$app->getSession()->setFlash('info', 'This is the message'); * - \Yii::$app->getSession()->setFlash('info', 'This is the message');
* *
* @author Alexander Makarov <sam@rmcerative.ru>
* @author Kartik Visweswaran <kartikv2@gmail.com> * @author Kartik Visweswaran <kartikv2@gmail.com>
* @author Alexander Makarov <sam@rmcerative.ru>
*/ */
class Alert extends \yii\bootstrap\Widget class Alert extends \yii\bootstrap\Widget
{ {
...@@ -37,23 +37,30 @@ class Alert extends \yii\bootstrap\Widget ...@@ -37,23 +37,30 @@ class Alert extends \yii\bootstrap\Widget
/** /**
* @var array the options for rendering the close button tag. * @var array the options for rendering the close button tag.
*/ */
public $closeButton = []; public $closeButtonOptions = [];
public function init() public function init()
{ {
parent::init();
$session = \Yii::$app->getSession(); $session = \Yii::$app->getSession();
$flashes = $session->getAllFlashes(); $flashes = $session->getAllFlashes();
$appendCss = isset($this->options['class']) ? ' ' . $this->options['class'] : ''; $appendCss = isset($this->options['class']) ? ' ' . $this->options['class'] : '';
foreach ($flashes as $type => $message) { foreach ($flashes as $type => $message) {
/* initialize css class for each alert box in loop */
$this->options['class'] = 'alert-' . $this->alertTypes[$type] . $appendCss; $this->options['class'] = 'alert-' . $this->alertTypes[$type] . $appendCss;
/* assign unique id to each alert box in the loop */
$this->options['id'] = $this->getId() . '-' . $type;
echo \yii\bootstrap\Alert::widget([ echo \yii\bootstrap\Alert::widget([
'body' => $message, 'body' => $message,
'closeButton' => $this->closeButton, 'closeButton' => $this->closeButtonOptions,
'options' => $this->options 'options' => $this->options
]); ]);
$session->removeFlash($type); $session->removeFlash($type);
} }
parent::init();
} }
} }
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