Skip to content

Commit

Permalink
Merge pull request silverstripe#2720 from signify-nz/enh/gridfieldcom…
Browse files Browse the repository at this point in the history
…ponents-di

ENH Prefer dependency injection for GridFieldComponents
  • Loading branch information
michalkleiner authored Feb 12, 2022
2 parents 367b9c9 + b4e3a08 commit 07df04f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions code/Controllers/CMSMain.php
Original file line number Diff line number Diff line change
Expand Up @@ -1632,9 +1632,9 @@ public function ListViewForm()
}
$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');
Expand All @@ -1645,7 +1645,7 @@ public function ListViewForm()
);
$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);
Expand Down
2 changes: 1 addition & 1 deletion code/Model/SiteTree.php
Original file line number Diff line number Diff line change
Expand Up @@ -1996,7 +1996,7 @@ public function getCMSFields()
);
}
]);
$dependentTable->getConfig()->addComponent(new GridFieldLazyLoader());
$dependentTable->getConfig()->addComponent(Injector::inst()->create(GridFieldLazyLoader::class));
}

$baseLink = Controller::join_links(
Expand Down

0 comments on commit 07df04f

Please sign in to comment.