Skip to content

Commit

Permalink
BUGFIX: Fixed notice-level errors in GridField, exposed by test failu…
Browse files Browse the repository at this point in the history
…res.
  • Loading branch information
Sam Minnee committed Jan 10, 2012
1 parent 06605ff commit 489191b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
19 changes: 9 additions & 10 deletions forms/gridfield/GridField.php
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,8 @@ public function getColumnContent($record, $column) {
$this->buildColumnDispatch();
}

$handler = $this->columnDispatch[$column];
if($handler) {
if(!empty($this->columnDispatch[$column])) {
$handler = $this->columnDispatch[$column];
return $handler->getColumnContent($this, $record, $column);
} else {
throw new InvalidArgumentException("Bad column '$column'");
Expand All @@ -422,8 +422,8 @@ public function getColumnAttributes($record, $column) {
$this->buildColumnDispatch();
}

$handler = $this->columnDispatch[$column];
if($handler) {
if(!empty($this->columnDispatch[$column])) {
$handler = $this->columnDispatch[$column];
$attrs = $handler->getColumnAttributes($this, $record, $column);
if(is_array($attrs)) {
return $attrs;
Expand Down Expand Up @@ -451,8 +451,8 @@ public function getColumnMetadata($column) {
$this->buildColumnDispatch();
}

$handler = $this->columnDispatch[$column];
if($handler) {
if(!empty($this->columnDispatch[$column])) {
$handler = $this->columnDispatch[$column];
$metadata = $handler->getColumnMetadata($this, $column);
if(is_array($metadata)) {
return $metadata;
Expand Down Expand Up @@ -502,13 +502,12 @@ public function gridFieldAlterAction($data, $form, SS_HTTPRequest $request) {
$stateChange = Session::get($id);
$gridName = $stateChange['grid'];
$grid = $form->Fields()->dataFieldByName($gridName);

$state = $grid->getState(false);
$state->setValue($data['GridState']);
if(isset($data['GridState'])) $state->setValue($data['GridState']);

$actionName = $stateChange['actionName'];

$args = $stateChange['args'];
$args = isset($stateChange['args']) ? $stateChange['args'] : array();
$grid->handleAction($actionName, $args, $data);

switch($request->getHeader('X-Get-Fragment')) {
Expand Down
2 changes: 1 addition & 1 deletion tests/forms/GridFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ public function testGridFieldAlterAction() {
$obj = new GridField('testfield', 'testfield', ArrayList::create(), $config);
$id = 'testGridStateActionField';
Session::set($id, array('grid'=>'', 'actionName'=>'jump'));
$form = new Form($this, 'mockform', new FieldList(array($obj)), new FieldList());
$form = new Form(new Controller(), 'mockform', new FieldList(array($obj)), new FieldList());
$request = new SS_HTTPRequest('POST', 'url');
$obj->gridFieldAlterAction(array('StateID'=>$id), $form, $request);
}
Expand Down

0 comments on commit 489191b

Please sign in to comment.