From 3ecdf2c74ba0a6a98ab17237c0c7b303432fc1d9 Mon Sep 17 00:00:00 2001 From: Samuel Georges Date: Sat, 7 Mar 2015 13:14:13 +1100 Subject: [PATCH] Fixes #977 - Look to related models for getting dropdown-type options --- modules/backend/widgets/Form.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/modules/backend/widgets/Form.php b/modules/backend/widgets/Form.php index f7446e71a..39d86ca96 100644 --- a/modules/backend/widgets/Form.php +++ b/modules/backend/widgets/Form.php @@ -913,22 +913,25 @@ class Form extends WidgetBase * Refer to the model method or any of its behaviors */ if (!is_array($fieldOptions) && !$fieldOptions) { - $methodName = 'get'.studly_case($field->fieldName).'Options'; + $htmlArray = HtmlHelper::nameToArray($field->fieldName); + list($model, $attribute) = $this->model->resolveAttribute($htmlArray); + + $methodName = 'get'.studly_case($attribute).'Options'; if ( - !$this->methodExists($this->model, $methodName) && - !$this->methodExists($this->model, 'getDropdownOptions') + !$this->methodExists($model, $methodName) && + !$this->methodExists($model, 'getDropdownOptions') ) { throw new ApplicationException(Lang::get( 'backend::lang.field.options_method_not_exists', - ['model'=>get_class($this->model), 'method'=>$methodName, 'field'=>$field->fieldName] + ['model'=>get_class($model), 'method'=>$methodName, 'field'=>$field->fieldName] )); } - if ($this->methodExists($this->model, $methodName)) { - $fieldOptions = $this->model->$methodName($field->value); + if ($this->methodExists($model, $methodName)) { + $fieldOptions = $model->$methodName($field->value); } else { - $fieldOptions = $this->model->getDropdownOptions($field->fieldName, $field->value); + $fieldOptions = $model->getDropdownOptions($attribute, $field->value); } } /*