From bcff1d3ecd6e10f1c1a7c75750d84259166febcd Mon Sep 17 00:00:00 2001 From: Samuel Georges Date: Wed, 15 Jun 2016 17:10:46 +1000 Subject: [PATCH] Widget classes are now extendable Fixes #2078 Fixes #1586 --- modules/backend/classes/WidgetBase.php | 7 +++++-- modules/backend/widgets/Form.php | 10 +++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/modules/backend/classes/WidgetBase.php b/modules/backend/classes/WidgetBase.php index 209d4f92b..b05af847b 100644 --- a/modules/backend/classes/WidgetBase.php +++ b/modules/backend/classes/WidgetBase.php @@ -4,6 +4,7 @@ use Str; use File; use Session; use October\Rain\Html\Helper as HtmlHelper; +use October\Rain\Extension\Extendable; use stdClass; /** @@ -12,7 +13,7 @@ use stdClass; * @package october\backend * @author Alexey Bobkov, Samuel Georges */ -abstract class WidgetBase +abstract class WidgetBase extends Extendable { use \System\Traits\ViewMaker; use \System\Traits\AssetMaker; @@ -71,6 +72,8 @@ abstract class WidgetBase */ $this->loadAssets(); + parent::__construct(); + /* * Initialize the widget. */ @@ -111,7 +114,7 @@ abstract class WidgetBase public function bindToController() { if ($this->controller->widget === null) { - $this->controller->widget = new \stdClass(); + $this->controller->widget = new stdClass(); } $this->controller->widget->{$this->alias} = $this; diff --git a/modules/backend/widgets/Form.php b/modules/backend/widgets/Form.php index bacbd91b0..95bc6d473 100644 --- a/modules/backend/widgets/Form.php +++ b/modules/backend/widgets/Form.php @@ -1031,8 +1031,8 @@ class Form extends WidgetBase $methodName = 'get'.studly_case($attribute).'Options'; if ( - !$this->methodExists($model, $methodName) && - !$this->methodExists($model, 'getDropdownOptions') + !$this->objectMethodExists($model, $methodName) && + !$this->objectMethodExists($model, 'getDropdownOptions') ) { throw new ApplicationException(Lang::get( 'backend::lang.field.options_method_not_exists', @@ -1040,7 +1040,7 @@ class Form extends WidgetBase )); } - if ($this->methodExists($model, $methodName)) { + if ($this->objectMethodExists($model, $methodName)) { $fieldOptions = $model->$methodName($field->value); } else { @@ -1051,7 +1051,7 @@ class Form extends WidgetBase * Field options are an explicit method reference */ elseif (is_string($fieldOptions)) { - if (!$this->methodExists($this->model, $fieldOptions)) { + if (!$this->objectMethodExists($this->model, $fieldOptions)) { throw new ApplicationException(Lang::get( 'backend::lang.field.options_method_not_exists', ['model'=>get_class($this->model), 'method'=>$fieldOptions, 'field'=>$field->fieldName] @@ -1099,7 +1099,7 @@ class Form extends WidgetBase * @param string $method * @return boolean */ - protected function methodExists($object, $method) + protected function objectMethodExists($object, $method) { if (method_exists($object, 'methodExists')) { return $object->methodExists($method);