mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
API CHANGE: Added $insertBefore argument to GridFiedlConfig::addComponent()
This commit is contained in:
parent
c8e994d573
commit
1025524d8c
@ -38,9 +38,24 @@ class GridFieldConfig {
|
||||
|
||||
/**
|
||||
* @param GridFieldComponent $component
|
||||
* @param string $insertBefore The class of the component to insert this one before
|
||||
*/
|
||||
public function addComponent(GridFieldComponent $component) {
|
||||
$this->getComponents()->push($component);
|
||||
public function addComponent(GridFieldComponent $component, $insertBefore = null) {
|
||||
if($insertBefore) {
|
||||
$existingItems = $this->getComponents();
|
||||
$this->components = new ArrayList;
|
||||
$inserted = false;
|
||||
foreach($existingItems as $existingItem) {
|
||||
if(!$inserted && $existingItem instanceof $insertBefore) {
|
||||
$this->components->push($component);
|
||||
$inserted = true;
|
||||
}
|
||||
$this->components->push($existingItem);
|
||||
}
|
||||
if(!$inserted) $this->components->push($component);
|
||||
} else {
|
||||
$this->getComponents()->push($component);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user