Widget classes are now extendable

Fixes #2078
Fixes #1586
This commit is contained in:
Samuel Georges 2016-06-15 17:10:46 +10:00
parent 5d4afff97f
commit bcff1d3ecd
2 changed files with 10 additions and 7 deletions

View File

@ -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;

View File

@ -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);