Skip to content

Commit

Permalink
BUG Custom label set in summary_fields config gets overridden
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Harvey committed Aug 14, 2014
1 parent 9bc7dd3 commit 5f1552b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
10 changes: 7 additions & 3 deletions model/DataObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -3333,7 +3333,7 @@ public function fieldLabel($name) {
*
* @return array
*/
public function summaryFields(){
public function summaryFields() {
$fields = $this->stat('summary_fields');

// if fields were passed in numeric array,
Expand All @@ -3357,9 +3357,13 @@ public function summaryFields(){

// Localize fields (if possible)
foreach($this->fieldLabels(false) as $name => $label) {
if(isset($fields[$name])) $fields[$name] = $label;
// only attempt to localize if the label definition is the same as the field name.
// this will preserve any custom labels set in the summary_fields configuration
if(isset($fields[$name]) && $name === $fields[$name]) {
$fields[$name] = $label;
}
}

return $fields;
}

Expand Down
20 changes: 19 additions & 1 deletion tests/model/DataObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,24 @@ public function testSearchableFields() {
$fields = $testObj->searchableFields();
$this->assertEmpty($fields);
}


public function testSummaryFieldsCustomLabels() {
$team = $this->objFromFixture('DataObjectTest_Team', 'team1');
$summaryFields = $team->summaryFields();

$this->assertEquals(
'Custom Title',
$summaryFields['Title'],
'Custom title is preserved'
);

$this->assertEquals(
'Captain\'s shirt number',
$summaryFields['Captain.ShirtNumber'],
'Custom title on relation is preserved'
);
}

public function testDataObjectUpdate() {
/* update() calls can use the dot syntax to reference has_one relations and other methods that return
* objects */
Expand Down Expand Up @@ -1263,6 +1280,7 @@ class DataObjectTest_Team extends DataObject implements TestOnly {
);

private static $summary_fields = array(
'Title' => 'Custom Title',
'Title.UpperCase' => 'Title',
'Captain.ShirtNumber' => 'Captain\'s shirt number',
'Captain.FavouriteTeam.Title' => 'Captain\'s favourite team'
Expand Down

0 comments on commit 5f1552b

Please sign in to comment.