Permalink
Browse files

API CHANGE: Added $insertBefore argument to GridFiedlConfig::addCompo…

…nent()
  • Loading branch information...
1 parent c8e994d commit 1025524d8c51dae58d570b5fef5caa225f6e92cb @sminnee sminnee committed May 18, 2012
Showing with 17 additions and 2 deletions.
  1. +17 −2 forms/gridfield/GridFieldConfig.php
View
19 forms/gridfield/GridFieldConfig.php
@@ -38,9 +38,24 @@ public function __construct() {
/**
* @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;
}

0 comments on commit 1025524

Please sign in to comment.