Permalink
Browse files

ENHANCEMENT Allow multiple column providers for a single column

  • Loading branch information...
1 parent e7f9c2c commit df716eff45481e0b05726c0bf35c54d1d0736e62 @andrewandante andrewandante committed Feb 7, 2012
Showing with 40 additions and 25 deletions.
  1. +31 −18 forms/gridfield/GridField.php
  2. +8 −6 forms/gridfield/GridFieldAction.php
  3. +1 −1 forms/gridfield/GridFieldDefaultColumns.php
@@ -371,6 +371,7 @@ public function getColumns() {
$item->augmentColumns($this, $columns);
}
}
+
return $columns;
}
@@ -389,8 +390,11 @@ public function getColumnContent($record, $column) {
}
if(!empty($this->columnDispatch[$column])) {
- $handler = $this->columnDispatch[$column];
- return $handler->getColumnContent($this, $record, $column);
+ $content = "";
+ foreach($this->columnDispatch[$column] as $handler) {
+ $content .= $handler->getColumnContent($this, $record, $column);
+ }
+ return $content;
} else {
throw new InvalidArgumentException("Bad column '$column'");
}
@@ -412,15 +416,18 @@ public function getColumnAttributes($record, $column) {
}
if(!empty($this->columnDispatch[$column])) {
- $handler = $this->columnDispatch[$column];
- $attrs = $handler->getColumnAttributes($this, $record, $column);
- if(is_array($attrs)) {
- return $attrs;
- } elseif($attrs) {
- throw new LogicException("Non-array response from " . get_class($handler) . "::getColumnAttributes()");
- } else {
- return array();
+ $attrs = array();
+
+ foreach($this->columnDispatch[$column] as $handler) {
+ $column_attrs = $handler->getColumnAttributes($this, $record, $column);
+
+ if(is_array($column_attrs))
+ $attrs = array_merge($attrs, $column_attrs);
+ elseif($column_attrs)
+ throw new LogicException("Non-array response from " . get_class($handler) . "::getColumnAttributes()");
}
+
+ return $attrs;
} else {
throw new InvalidArgumentException("Bad column '$column'");
}
@@ -441,13 +448,19 @@ public function getColumnMetadata($column) {
}
if(!empty($this->columnDispatch[$column])) {
- $handler = $this->columnDispatch[$column];
- $metadata = $handler->getColumnMetadata($this, $column);
- if(is_array($metadata)) {
- return $metadata;
- } elseif($metadata) {
- throw new LogicException("Non-array response from " . get_class($handler) . "::getColumnMetadata()");
+ $metadata = array();
+
+ foreach($this->columnDispatch[$column] as $handler) {
+ $column_metadata = $handler->getColumnMetadata($this, $column);
+
+ if(is_array($column_metadata))
+ $metadata = array_merge($metadata, $column_metadata);
+ else
+ throw new LogicException("Non-array response from " . get_class($handler) . "::getColumnMetadata()");
+
}
+
+ return $metadata;
}
throw new InvalidArgumentException("Bad column '$column'");
}
@@ -474,10 +487,10 @@ protected function buildColumnDispatch() {
if($item instanceof GridField_ColumnProvider) {
$columns = $item->getColumnsHandled($this);
foreach($columns as $column) {
- $this->columnDispatch[$column] = $item;
+ $this->columnDispatch[$column][] = $item;
}
}
- }
+ }
}
/**
@@ -12,7 +12,8 @@ class GridFieldAction_Edit implements GridField_ColumnProvider {
* @param array $columns
*/
public function augmentColumns($gridField, &$columns) {
- $columns[] = 'EditAction';
+ if(!in_array('Actions', $columns))
+ $columns[] = 'Actions';
}
/**
@@ -35,7 +36,7 @@ public function getColumnAttributes($gridField, $record, $columnName) {
* @return array
*/
public function getColumnMetadata($gridField, $columnName) {
- if($columnName == 'EditAction') {
+ if($columnName == 'Actions') {
return array('title' => '');
}
}
@@ -47,7 +48,7 @@ public function getColumnMetadata($gridField, $columnName) {
* @return type
*/
public function getColumnsHandled($gridField) {
- return array('EditAction');
+ return array('Actions');
}
/**
@@ -98,7 +99,8 @@ class GridFieldAction_Delete implements GridField_ColumnProvider, GridField_Acti
* @param array $columns
*/
public function augmentColumns($gridField, &$columns) {
- $columns[] = 'DeleteAction';
+ if(!in_array('Actions', $columns))
+ $columns[] = 'Actions';
}
/**
@@ -121,7 +123,7 @@ public function getColumnAttributes($gridField, $record, $columnName) {
* @return array
*/
public function getColumnMetadata($gridField, $columnName) {
- if($columnName == 'DeleteAction') {
+ if($columnName == 'Actions') {
return array('title' => '');
}
}
@@ -133,7 +135,7 @@ public function getColumnMetadata($gridField, $columnName) {
* @return type
*/
public function getColumnsHandled($gridField) {
- return array('DeleteAction');
+ return array('Actions');
}
/**
@@ -59,7 +59,7 @@ public function getColumnContent($gridField, $item, $column) {
}
public function getColumnAttributes($gridField, $item, $column) {
- return null;
+ return array();
}
public function getColumnMetadata($gridField, $column) {

0 comments on commit df716ef

Please sign in to comment.