Skip to content

Commit

Permalink
ModelAdmin can now handle both DataObjects and PersistentDataObjects
Browse files Browse the repository at this point in the history
  • Loading branch information
Zauberfisch committed Jan 16, 2018
1 parent 65b0df1 commit ce86520
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions src/Admin/ModelAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,30 @@ class ModelAdmin extends \ModelAdmin {
public function getEditForm($id = null, $fields = null) {
/** @var \Form $return */
$return = parent::getEditForm($id, $fields);
/** @var \GridField $grid */
$grid = $return->Fields()->fieldByName($this->sanitiseClassName($this->modelClass));
$config = new Config_RecordEditor();
$config->removeComponentsByType(\GridFieldFilterHeader::class);
// Validation
if (singleton($this->modelClass)->hasMethod('getCMSValidator')) {
$detailValidator = singleton($this->modelClass)->getCMSValidator();
/** @var DetailForm $detailForm */
$detailForm = $config->getComponentByType(DetailForm::class);
$detailForm->setValidator($detailValidator);
if (is_a($this->modelClass, \PersistentDataObject_Model_DataObject::class)) {

/** @var \GridField $grid */
$grid = $return->Fields()->fieldByName($this->sanitiseClassName($this->modelClass));
$config = new Config_RecordEditor();
$config->removeComponentsByType(\GridFieldFilterHeader::class);
// Validation
if (singleton($this->modelClass)->hasMethod('getCMSValidator')) {
$detailValidator = singleton($this->modelClass)->getCMSValidator();
/** @var DetailForm $detailForm */
$detailForm = $config->getComponentByType(DetailForm::class);
$detailForm->setValidator($detailValidator);
}
// Import / Export
$config->addComponent((new \GridFieldExportButton('buttons-before-left'))->setExportColumns($this->getExportFields()));
//if ($this->showImportForm) {
// $config->addComponent(
// GridFieldImportButton::create('buttons-before-left')
// ->setImportForm($this->ImportForm())
// ->setModalTitle(_t('ModelAdmin.IMPORT', 'Import from CSV'))
// );
//}
$grid->setConfig($config);
}
// Import / Export
$config->addComponent((new \GridFieldExportButton('buttons-before-left'))->setExportColumns($this->getExportFields()));
//if ($this->showImportForm) {
// $config->addComponent(
// GridFieldImportButton::create('buttons-before-left')
// ->setImportForm($this->ImportForm())
// ->setModalTitle(_t('ModelAdmin.IMPORT', 'Import from CSV'))
// );
//}
$grid->setConfig($config);
return $return;
}
}
Expand Down

0 comments on commit ce86520

Please sign in to comment.