mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUG Fix incorrect merge of associative / non-associative summary fields
Fixes #7696
This commit is contained in:
parent
a2fa9f0943
commit
ed6561d9f5
@ -3337,12 +3337,15 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
|||||||
*/
|
*/
|
||||||
public function summaryFields()
|
public function summaryFields()
|
||||||
{
|
{
|
||||||
$fields = $this->config()->get('summary_fields');
|
$rawFields = $this->config()->get('summary_fields');
|
||||||
|
|
||||||
// if fields were passed in numeric array,
|
// Merge associative / numeric keys
|
||||||
// convert to an associative array
|
$fields = [];
|
||||||
if ($fields && array_key_exists(0, $fields)) {
|
foreach ($rawFields as $key => $value) {
|
||||||
$fields = array_combine(array_values($fields), array_values($fields));
|
if (is_int($key)) {
|
||||||
|
$key = $value;
|
||||||
|
}
|
||||||
|
$fields[$key] = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$fields) {
|
if (!$fields) {
|
||||||
|
@ -2,25 +2,23 @@
|
|||||||
|
|
||||||
namespace SilverStripe\ORM\Tests;
|
namespace SilverStripe\ORM\Tests;
|
||||||
|
|
||||||
|
use InvalidArgumentException;
|
||||||
use SilverStripe\Core\Config\Config;
|
use SilverStripe\Core\Config\Config;
|
||||||
use SilverStripe\Dev\SapphireTest;
|
use SilverStripe\Dev\SapphireTest;
|
||||||
use SilverStripe\i18n\i18n;
|
use SilverStripe\i18n\i18n;
|
||||||
|
use SilverStripe\ORM\Connect\MySQLDatabase;
|
||||||
|
use SilverStripe\ORM\DataObject;
|
||||||
use SilverStripe\ORM\DataObjectSchema;
|
use SilverStripe\ORM\DataObjectSchema;
|
||||||
|
use SilverStripe\ORM\DB;
|
||||||
use SilverStripe\ORM\FieldType\DBBoolean;
|
use SilverStripe\ORM\FieldType\DBBoolean;
|
||||||
use SilverStripe\ORM\FieldType\DBDatetime;
|
use SilverStripe\ORM\FieldType\DBDatetime;
|
||||||
use SilverStripe\ORM\FieldType\DBField;
|
use SilverStripe\ORM\FieldType\DBField;
|
||||||
use SilverStripe\ORM\DataObject;
|
|
||||||
use SilverStripe\ORM\DB;
|
|
||||||
use SilverStripe\ORM\Connect\MySQLDatabase;
|
|
||||||
use SilverStripe\ORM\FieldType\DBPolymorphicForeignKey;
|
use SilverStripe\ORM\FieldType\DBPolymorphicForeignKey;
|
||||||
use SilverStripe\ORM\FieldType\DBVarchar;
|
use SilverStripe\ORM\FieldType\DBVarchar;
|
||||||
use SilverStripe\ORM\ManyManyList;
|
use SilverStripe\ORM\ManyManyList;
|
||||||
use SilverStripe\ORM\Tests\DataObjectTest\Player;
|
use SilverStripe\ORM\Tests\DataObjectTest\Player;
|
||||||
use SilverStripe\ORM\ValidationException;
|
|
||||||
use SilverStripe\View\ViewableData;
|
use SilverStripe\View\ViewableData;
|
||||||
use stdClass;
|
use stdClass;
|
||||||
use ReflectionException;
|
|
||||||
use InvalidArgumentException;
|
|
||||||
|
|
||||||
class DataObjectTest extends SapphireTest
|
class DataObjectTest extends SapphireTest
|
||||||
{
|
{
|
||||||
@ -1190,15 +1188,13 @@ class DataObjectTest extends SapphireTest
|
|||||||
$summaryFields = $team->summaryFields();
|
$summaryFields = $team->summaryFields();
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'Custom Title',
|
[
|
||||||
$summaryFields['Title'],
|
'Title' => 'Custom Title',
|
||||||
'Custom title is preserved'
|
'Title.UpperCase' => 'Title',
|
||||||
);
|
'Captain.ShirtNumber' => 'Captain\'s shirt number',
|
||||||
|
'Captain.FavouriteTeam.Title' => 'Captain\'s favourite team',
|
||||||
$this->assertEquals(
|
],
|
||||||
'Captain\'s shirt number',
|
$summaryFields
|
||||||
$summaryFields['Captain.ShirtNumber'],
|
|
||||||
'Custom title on relation is preserved'
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ class Team extends DataObject implements TestOnly
|
|||||||
);
|
);
|
||||||
|
|
||||||
private static $summary_fields = array(
|
private static $summary_fields = array(
|
||||||
'Title' => 'Custom Title',
|
'Title', // Overridden by Team_Extension
|
||||||
'Title.UpperCase' => 'Title',
|
'Title.UpperCase' => 'Title',
|
||||||
'Captain.ShirtNumber' => 'Captain\'s shirt number',
|
'Captain.ShirtNumber' => 'Captain\'s shirt number',
|
||||||
'Captain.FavouriteTeam.Title' => 'Captain\'s favourite team'
|
'Captain.FavouriteTeam.Title' => 'Captain\'s favourite team'
|
||||||
|
@ -7,6 +7,10 @@ use SilverStripe\ORM\DataExtension;
|
|||||||
|
|
||||||
class Team_Extension extends DataExtension implements TestOnly
|
class Team_Extension extends DataExtension implements TestOnly
|
||||||
{
|
{
|
||||||
|
private static $summary_fields = [
|
||||||
|
'Title' => 'Custom Title', // override non-associative 'Title'
|
||||||
|
];
|
||||||
|
|
||||||
private static $db = array(
|
private static $db = array(
|
||||||
'ExtendedDatabaseField' => 'Varchar'
|
'ExtendedDatabaseField' => 'Varchar'
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user