Merge pull request #3387 from halkyon/summary_fields_custom_label2

BUG Custom label set in summary_fields config gets overridden
This commit is contained in:
Simon Welsh 2014-08-14 14:22:28 +10:00
commit 66bacc69f0
2 changed files with 26 additions and 4 deletions

View File

@ -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;
}

View File

@ -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'