Improve getDataSourceValues so model knows what attribute it's dealing with

This commit is contained in:
flynsarmy 2014-07-30 20:11:47 +10:00
parent 8a246a8193
commit 8da4b38672
1 changed files with 10 additions and 2 deletions

View File

@ -107,10 +107,18 @@ class DataGrid extends FormWidgetBase
public function getDataSourceValues()
{
if (!$this->model->methodExists('getGridDataSourceValues'))
$methodName = 'get'.studly_case($this->columnName).'DataSourceValues';
if (!$this->model->methodExists($methodName) && !$this->model->methodExists('getGridDataSourceValues'))
throw new ApplicationException('Model :model does not contain a method getGridDataSourceValues()');
$result = $this->model->getGridDataSourceValues();
if ($this->model->methodExists($methodName))
$result = $this->model->$methodName($field, $value, $data);
else
$result = $this->model->getGridDataSourceValues($this->columnName, $field, $value, $data);
if (!is_array($result))
$result = [];
return $result;
}