Lint fixes and allow a few other components by default

This commit is contained in:
Luke Edwards 2018-09-20 13:32:52 +12:00
parent 4c3a068859
commit 3fc49dd4ce
3 changed files with 10 additions and 6 deletions

View File

@ -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();

View File

@ -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');
}

View File

@ -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));
}
}