From df25c5d9f73fa4086b591b52070c96635c5e1e97 Mon Sep 17 00:00:00 2001 From: Sam Georges Date: Mon, 16 Jun 2014 22:22:31 +1000 Subject: [PATCH] Fixes #308 --- modules/backend/widgets/Form.php | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/modules/backend/widgets/Form.php b/modules/backend/widgets/Form.php index 9ae93dd57..bd624ec8c 100644 --- a/modules/backend/widgets/Form.php +++ b/modules/backend/widgets/Form.php @@ -624,10 +624,10 @@ class Form extends WidgetBase */ if (!is_array($fieldOptions) && !$fieldOptions) { $methodName = 'get'.studly_case($field->columnName).'Options'; - if (!$this->model->methodExists($methodName) && !$this->model->methodExists('getDropdownOptions')) + if (!$this->methodExists($this->model, $methodName) && !$this->methodExists($this->model, 'getDropdownOptions')) throw new ApplicationException(Lang::get('backend::lang.field.options_method_not_exists', ['model'=>get_class($this->model), 'method'=>$methodName, 'field'=>$field->columnName])); - if ($this->model->methodExists($methodName)) + if ($this->methodExists($this->model, $methodName)) $fieldOptions = $this->model->$methodName($field->value); else $fieldOptions = $this->model->getDropdownOptions($field->columnName, $field->value); @@ -637,7 +637,7 @@ class Form extends WidgetBase * Field options are an explicit method reference */ elseif (is_string($fieldOptions)) { - if (!$this->model->methodExists($fieldOptions)) + if (!$this->methodExists($this->model, $fieldOptions)) throw new ApplicationException(Lang::get('backend::lang.field.options_method_not_exists', ['model'=>get_class($this->model), 'method'=>$fieldOptions, 'field'=>$field->columnName])); $fieldOptions = $this->model->$fieldOptions($field->value, $field->columnName); @@ -668,4 +668,18 @@ class Form extends WidgetBase return $this->activeContext; } + /** + * Internal helper for method existence checks + * @param object $object + * @param string $method + * @return boolean + */ + private function methodExists($object, $method) + { + if (method_exists($object, 'methodExists')) + return $object->methodExists($method); + + return method_exists($object, $method); + } + } \ No newline at end of file