diff --git a/src/Forms/GridField/GridField.php b/src/Forms/GridField/GridField.php index 79d59741a..ae25e1ec3 100644 --- a/src/Forms/GridField/GridField.php +++ b/src/Forms/GridField/GridField.php @@ -53,6 +53,28 @@ class GridField extends FormField 'gridFieldAlterAction', ]; + /** + * Default globally configured readonly components. + * + * @see $readonlyComponents + * @var array + */ + private static $default_readonly_components = [ + GridField_ActionMenu::class, + GridFieldConfig_RecordViewer::class, + GridFieldButtonRow::class, + GridFieldDataColumns::class, + GridFieldDetailForm::class, + GridFieldLazyLoader::class, + GridFieldPageCount::class, + GridFieldPaginator::class, + GridFieldFilterHeader::class, + GridFieldSortableHeader::class, + GridFieldToolbarHeader::class, + GridFieldViewButton::class, + GridState_Component::class, + ]; + /** * Data source. * @@ -114,21 +136,7 @@ class GridField extends FormField * * @var array */ - protected $readonlyComponents = [ - GridField_ActionMenu::class, - GridFieldConfig_RecordViewer::class, - GridFieldButtonRow::class, - GridFieldDataColumns::class, - GridFieldDetailForm::class, - GridFieldLazyLoader::class, - GridFieldPageCount::class, - GridFieldPaginator::class, - GridFieldFilterHeader::class, - GridFieldSortableHeader::class, - GridFieldToolbarHeader::class, - GridFieldViewButton::class, - GridState_Component::class, - ]; + protected $readonlyComponents = []; /** * Pattern used for looking up @@ -145,6 +153,9 @@ class GridField extends FormField { parent::__construct($name, $title, null); + // Set readonly components for this gridfield. + $this->setReadonlyComponents($this->config()->get('default_readonly_components')); + $this->name = $name; if ($dataList) { @@ -262,6 +273,8 @@ class GridField extends FormField $copyConfig->addComponent(GridFieldViewButton::create()); } + $copy->extend('afterPerformReadonlyTransformation', $this); + return $copy; }