forked from yiisoft/yii2
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. Renamed closeButton to closeButtonOptions. 2. Generate unique id for each alert box. 3. Moved parent init to the top.
- Loading branch information
Showing
1 changed file
with
13 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,8 +15,8 @@ | |
* - \Yii::$app->getSession()->setFlash('success', 'This is the message'); | ||
* - \Yii::$app->getSession()->setFlash('info', 'This is the message'); | ||
* | ||
* @author Alexander Makarov <[email protected]> | ||
* @author Kartik Visweswaran <[email protected]> | ||
* @author Alexander Makarov <[email protected]> | ||
*/ | ||
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. | ||
*/ | ||
public $closeButton = []; | ||
public $closeButtonOptions = []; | ||
|
||
public function init() | ||
{ | ||
parent::init(); | ||
|
||
$session = \Yii::$app->getSession(); | ||
$flashes = $session->getAllFlashes(); | ||
$appendCss = isset($this->options['class']) ? ' ' . $this->options['class'] : ''; | ||
|
||
foreach ($flashes as $type => $message) { | ||
$this->options['class'] = 'alert-' . $this->alertTypes[$type] . $appendCss; | ||
/* initialize css class for each alert box in loop */ | ||
$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([ | ||
'body' => $message, | ||
'closeButton' => $this->closeButton, | ||
'closeButton' => $this->closeButtonOptions, | ||
'options' => $this->options | ||
]); | ||
|
||
$session->removeFlash($type); | ||
} | ||
parent::init(); | ||
} | ||
} |