ENH Prefer dependency injection for GridFieldComponents

GridFieldComponents packaged with silverstripe/framework are injectable as of 4.11.0
Explicitly invoking the injector here instead of using `create()` allows backwards compatability with framework < 4.11.0 while ensuring dependency injection is still used from 4.11.0 onwards.
This commit is contained in:
Guy Sartorelli 2022-02-12 18:48:17 +13:00
parent 367b9c9bf2
commit b4e3a08b8a
2 changed files with 5 additions and 5 deletions

View File

@ -1632,9 +1632,9 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
}
$list = $this->getList($params, $parentID);
$gridFieldConfig = GridFieldConfig::create()->addComponents(
new GridFieldSortableHeader(),
new GridFieldDataColumns(),
new GridFieldPaginator($this->config()->get('page_length'))
Injector::inst()->create(GridFieldSortableHeader::class),
Injector::inst()->create(GridFieldDataColumns::class),
Injector::inst()->createWithArgs(GridFieldPaginator::class, [$this->config()->get('page_length')])
);
if ($parentID) {
$linkSpec = $this->LinkListViewChildren('%d');
@ -1645,7 +1645,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
);
$this->setCurrentPageID($parentID);
}
$gridField = new GridField('Page', 'Pages', $list, $gridFieldConfig);
$gridField = GridField::create('Page', 'Pages', $list, $gridFieldConfig);
$gridField->setAttribute('cms-loading-ignore-url-params', true);
/** @var GridFieldDataColumns $columns */
$columns = $gridField->getConfig()->getComponentByType(GridFieldDataColumns::class);

View File

@ -1996,7 +1996,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
);
}
]);
$dependentTable->getConfig()->addComponent(new GridFieldLazyLoader());
$dependentTable->getConfig()->addComponent(Injector::inst()->create(GridFieldLazyLoader::class));
}
$baseLink = Controller::join_links(