From 49f6e64db023903095941997dc7137c480e572de Mon Sep 17 00:00:00 2001 From: Samuel Georges Date: Sat, 28 Feb 2015 13:54:00 +1100 Subject: [PATCH] Refactor the toolbar widget --- modules/backend/widgets/Toolbar.php | 44 ++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/modules/backend/widgets/Toolbar.php b/modules/backend/widgets/Toolbar.php index 5ae3f5642..1f0199c81 100644 --- a/modules/backend/widgets/Toolbar.php +++ b/modules/backend/widgets/Toolbar.php @@ -11,6 +11,24 @@ use Backend\Classes\WidgetBase; */ class Toolbar extends WidgetBase { + // + // Configurable properties + // + + /** + * @var string Partial name containing the toolbar buttons + */ + public $buttons; + + /** + * @var array|string Search widget configuration or partial name, optional. + */ + public $search; + + // + // Object properties + // + /** * {@inheritDoc} */ @@ -21,33 +39,31 @@ class Toolbar extends WidgetBase */ protected $searchWidget; - /** - * @var string Name of partial containing control panel. - */ - public $controlPanel; - /** * @var array List of CSS classes to apply to the toolbar container element */ public $cssClasses = []; /** - * Constructor. + * Initialize the widget, called by the constructor and free from its parameters. */ - public function __construct($controller, $configuration = []) + public function init() { - parent::__construct($controller, $configuration); + $this->fillFromConfig([ + 'buttons', + 'search', + ]); /* * Prepare the search widget (optional) */ - if (isset($this->config->search)) { + if (isset($this->search)) { - if (is_string($this->config->search)) { - $searchConfig = $this->makeConfig(['partial' => $this->config->search]); + if (is_string($this->search)) { + $searchConfig = $this->makeConfig(['partial' => $this->search]); } else { - $searchConfig = $this->makeConfig($this->config->search); + $searchConfig = $this->makeConfig($this->search); } $searchConfig->alias = $this->alias . 'Search'; @@ -82,10 +98,10 @@ class Toolbar extends WidgetBase public function makeControlPanel() { - if (!isset($this->config->buttons)) { + if (!isset($this->buttons)) { return false; } - return $this->controller->makePartial($this->config->buttons, $this->vars); + return $this->controller->makePartial($this->buttons, $this->vars); } }