From 3fc49dd4ce222b14881b76c57c4bde24a5d4a6cf Mon Sep 17 00:00:00 2001 From: Luke Edwards Date: Thu, 20 Sep 2018 13:32:52 +1200 Subject: [PATCH] Lint fixes and allow a few other components by default --- src/Forms/GridField/GridField.php | 13 ++++++++----- .../GridField/GridFieldConfig_RecordViewer.php | 1 + tests/php/Forms/GridField/GridFieldReadonlyTest.php | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Forms/GridField/GridField.php b/src/Forms/GridField/GridField.php index 5d959596d..629b1e681 100644 --- a/src/Forms/GridField/GridField.php +++ b/src/Forms/GridField/GridField.php @@ -111,13 +111,16 @@ class GridField extends FormField * @var array */ protected $readonlyComponents = array( + GridField_ActionMenu::class, + GridState_Component::class, + GridFieldConfig_RecordViewer::class, GridFieldDetailForm::class, GridFieldDataColumns::class, - GridFieldConfig_RecordViewer::class, - GridFieldToolbarHeader::class, GridFieldPageCount::class, GridFieldPaginator::class, - GridState_Component::class + GridFieldSortableHeader::class, + GridFieldToolbarHeader::class, + GridFieldViewButton::class, ); /** @@ -241,7 +244,6 @@ class GridField extends FormField // get the whitelist for allowable readonly components $allowedComponents = $this->getReadonlyComponents(); foreach ($this->getConfig()->getComponents() as $component) { - // if a component doesn't exist, remove it from the readonly version. if (!in_array(get_class($component), $allowedComponents)) { $copy->getConfig()->removeComponent($component); @@ -256,7 +258,8 @@ class GridField extends FormField * * @return GridField */ - public function performDisabledTransformation(){ + public function performDisabledTransformation() + { parent::performDisabledTransformation(); return $this->performReadonlyTransformation(); diff --git a/src/Forms/GridField/GridFieldConfig_RecordViewer.php b/src/Forms/GridField/GridFieldConfig_RecordViewer.php index 07ea8977a..fdaa91139 100644 --- a/src/Forms/GridField/GridFieldConfig_RecordViewer.php +++ b/src/Forms/GridField/GridFieldConfig_RecordViewer.php @@ -14,6 +14,7 @@ class GridFieldConfig_RecordViewer extends GridFieldConfig_Base $this->addComponent(new GridFieldViewButton()); $this->addComponent(new GridFieldDetailForm()); + $this->removeComponentsByType(GridFieldFilterHeader::class); $this->extend('updateConfig'); } diff --git a/tests/php/Forms/GridField/GridFieldReadonlyTest.php b/tests/php/Forms/GridField/GridFieldReadonlyTest.php index bb3d7136f..c4a1e1deb 100644 --- a/tests/php/Forms/GridField/GridFieldReadonlyTest.php +++ b/tests/php/Forms/GridField/GridFieldReadonlyTest.php @@ -80,7 +80,7 @@ class GridFieldReadonlyTest extends SapphireTest $readonlyComponents = $readonlyGridField->getReadonlyComponents(); // assert that all the components in the readonly version are present in the whitelist. - foreach($readonlyGridField->getConfig()->getComponents() as $component){ + foreach ($readonlyGridField->getConfig()->getComponents() as $component) { $this->assertTrue(in_array(get_class($component), $readonlyComponents)); } }