From 8a436c4acbccb16c3229238e2a974009a29c6c60 Mon Sep 17 00:00:00 2001 From: Kartik Visweswaran Date: Wed, 20 Nov 2013 22:45:49 +0530 Subject: [PATCH] Code cleanup. Removed redundant declarations and checks in the code. --- apps/advanced/frontend/widgets/Alert.php | 29 +++++------------------------ 1 file changed, 5 insertions(+), 24 deletions(-) diff --git a/apps/advanced/frontend/widgets/Alert.php b/apps/advanced/frontend/widgets/Alert.php index dc0cc30..b174437 100644 --- a/apps/advanced/frontend/widgets/Alert.php +++ b/apps/advanced/frontend/widgets/Alert.php @@ -7,10 +7,6 @@ namespace frontend\widgets; -use yii\helpers\Html; -use yii\bootstrap\Widget; -use yii\bootstrap\Alert as BsAlert; - /** * 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: @@ -22,7 +18,7 @@ use yii\bootstrap\Alert as BsAlert; * @author Alexander Makarov * @author Kartik Visweswaran */ -class Alert extends Widget +class Alert extends \yii\bootstrap\Widget { /** * @var array the allowed bootstrap alert types. @@ -34,38 +30,23 @@ class Alert extends Widget */ public $closeButton = []; - private $_doNotRender = true; - public function init() { - $this->_doNotRender = true; $session = \Yii::$app->getSession(); - $flashes = $session->getAllFlashes(); - $baseCssClass = isset($this->options['class']) ? $this->options['class'] : ''; + $appendCss = isset($this->options['class']) ? $this->options['class'] : ''; foreach ($flashes as $type => $message) { if (in_array($type, $this->allowedTypes)) { - $this->options['class'] = (($type === 'error') ? "alert-danger" : "alert-{$type}") . ' ' . $baseCssClass; - echo BsAlert::widget([ + $this->options['class'] = (($type === 'error') ? 'alert-danger' : 'alert-' . $type) . ' ' . $appendCss; + echo \yii\bootstrap\Alert::widget([ 'body' => $message, 'closeButton' => $this->closeButton, 'options' => $this->options ]); - Html::removeCssClass($this->options, $class); $session->removeFlash($type); $this->_doNotRender = false; } } - - if (!$this->_doNotRender) { - parent::init(); - } - } - - public function run() - { - if (!$this->_doNotRender) { - parent::run(); - } + parent::init(); } }