diff --git a/model/DataObject.php b/model/DataObject.php index 0950fef4f..3f10f4a63 100644 --- a/model/DataObject.php +++ b/model/DataObject.php @@ -3333,7 +3333,7 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity * * @return array */ - public function summaryFields(){ + public function summaryFields() { $fields = $this->stat('summary_fields'); // if fields were passed in numeric array, @@ -3357,9 +3357,13 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity // 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; } diff --git a/tests/model/DataObjectTest.php b/tests/model/DataObjectTest.php index bbd76436b..6f235ea75 100644 --- a/tests/model/DataObjectTest.php +++ b/tests/model/DataObjectTest.php @@ -682,7 +682,24 @@ class DataObjectTest extends SapphireTest { $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 */ @@ -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'