mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
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:
commit
66bacc69f0
@ -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,7 +3357,11 @@ 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;
|
||||
|
@ -683,6 +683,23 @@ class DataObjectTest extends SapphireTest {
|
||||
$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'
|
||||
|
Loading…
x
Reference in New Issue
Block a user