setDatasource($datasource); } $this->setPresenter($dataPresenterClassName); } /** * @param string $modelClassName */ public function setModelClass($modelClassName) { $this->modelClassName = $modelClassName; return $this; } /** * @throws Exception * @return string */ public function getModelClass() { if ($this->modelClassName) { return $this->modelClassName; } if ($this->datasource->dataClass) { return $this->datasource->dataClass; } throw new Exception(get_class($this).' does not have a modelClassName'); } /** * @param string|GridFieldPresenter * * @throws Exception */ public function setPresenter($presenter) { if(!$presenter){ throw new Exception('setPresenter() for GridField must be set with a class'); } if(is_object($presenter)) { $this->presenter = $presenter; $this->presenter->setGridField($this); return; } if(!class_exists($presenter)){ throw new Exception('DataPresenter for GridField must be set with an existing class, '.$presenter.' does not exists.'); } if($presenter !='GridFieldPresenter' && !ClassInfo::is_subclass_of($presenter, 'GridFieldPresenter')) { throw new Exception(sprintf( 'DataPresenter "%s" must subclass GridFieldPresenter', $presenter )); } $this->presenter = new $presenter; $this->presenter->setGridField($this); return $this; } /** * @return GridFieldPresenter */ public function getPresenter(){ return $this->presenter; } /** * Set the datasource * * @param SS_List $datasource */ public function setDataSource(SS_List $datasource) { $this->datasource = $datasource; return $this; } /** * Get the datasource * * @return SS_List */ public function getDataSource() { return $this->datasource; } /** * @return string - html for the form */ function FieldHolder() { return $this->getPresenter()->render(); } }