Merge pull request #498 from Flynsarmy/dynamicDataSourceValues

Improve getDataSourceValues so model knows what attribute it's dealing w...
This commit is contained in:
Samuel Georges 2014-07-30 22:28:03 +10:00
commit 12a7d07774

View File

@ -105,12 +105,25 @@ class DataGrid extends FormWidgetBase
return $result;
}
/**
* Looks at the model for getXXXDataSourceValues or getGridDataSourceValues methods
* to obtain the starting values for the grid.
* @return array
*/
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();
else
$result = $this->model->getGridDataSourceValues($this->columnName);
if (!is_array($result))
$result = [];
return $result;
}