Created
June 9, 2017 12:49
-
-
Save zanderwar/9df38a5ab7584a02254a656bdfc7a86b to your computer and use it in GitHub Desktop.
An example of swapping the GridFieldConfig of a particular GridField in a ModelAdmin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Example extends ModelAdmin | |
{ | |
private static $url_segment = 'Example'; | |
private static $menu_title = 'Example'; | |
private static $managed_models = [ | |
Site::class | |
]; | |
/** | |
* @param null $id | |
* @param null $fields | |
* | |
* @return Form | |
*/ | |
public function getEditForm($id = null, $fields = null) | |
{ | |
/** @var Form $form */ | |
$form = parent::getEditForm($id, $fields); | |
$fields = $form->Fields(); | |
foreach ($fields as $field) { | |
if (!$field instanceof GridField) { | |
continue; | |
} | |
/** @var GridField $field */ | |
if ($field->getName() === TestScraperResult::class) { | |
$field->setConfig(GridFieldConfig_RecordViewer::create()); | |
} | |
} | |
return $form; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
SS4 equivalent: