API CHANGE: Added $insertBefore argument to GridFiedlConfig::addComponent()

This commit is contained in:
Sam Minnee 2012-05-18 13:36:52 +12:00
parent c8e994d573
commit 1025524d8c

View File

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