mirror of
https://github.com/symbiote/silverstripe-gridfieldextensions.git
synced 2024-10-22 17:05:39 +02:00
Merge branch '3.5' into 3.6
This commit is contained in:
commit
bb6c0396f1
@ -396,6 +396,13 @@ class GridFieldOrderableRows extends RequestHandler implements
|
|||||||
if ($list instanceof DataList) {
|
if ($list instanceof DataList) {
|
||||||
$classname = $list->dataClass();
|
$classname = $list->dataClass();
|
||||||
if ($defaultSort = Config::inst()->get($classname, 'default_sort')) {
|
if ($defaultSort = Config::inst()->get($classname, 'default_sort')) {
|
||||||
|
if (is_array($defaultSort)) {
|
||||||
|
$defaultSortArray = [];
|
||||||
|
foreach ($defaultSort as $column => $direction) {
|
||||||
|
$defaultSortArray[] = "\"$column\" $direction";
|
||||||
|
}
|
||||||
|
$defaultSort = implode(', ', $defaultSortArray);
|
||||||
|
}
|
||||||
// Append the default sort to the end of the sort string
|
// Append the default sort to the end of the sort string
|
||||||
// This may result in redundancy... but it seems to work
|
// This may result in redundancy... but it seems to work
|
||||||
$sortterm .= ($sortterm ? ', ' : '') . $defaultSort;
|
$sortterm .= ($sortterm ? ', ' : '') . $defaultSort;
|
||||||
|
@ -24,6 +24,7 @@ use Symbiote\GridFieldExtensions\Tests\Stub\ThroughDefinerVersioned;
|
|||||||
use Symbiote\GridFieldExtensions\Tests\Stub\ThroughIntermediary;
|
use Symbiote\GridFieldExtensions\Tests\Stub\ThroughIntermediary;
|
||||||
use Symbiote\GridFieldExtensions\Tests\Stub\TitleObject;
|
use Symbiote\GridFieldExtensions\Tests\Stub\TitleObject;
|
||||||
use Symbiote\GridFieldExtensions\Tests\Stub\TitleSortedObject;
|
use Symbiote\GridFieldExtensions\Tests\Stub\TitleSortedObject;
|
||||||
|
use Symbiote\GridFieldExtensions\Tests\Stub\TitleArraySortedObject;
|
||||||
use Symbiote\GridFieldExtensions\Tests\Stub\ThroughIntermediaryVersioned;
|
use Symbiote\GridFieldExtensions\Tests\Stub\ThroughIntermediaryVersioned;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -53,6 +54,7 @@ class GridFieldOrderableRowsTest extends SapphireTest
|
|||||||
ThroughBelongs::class,
|
ThroughBelongs::class,
|
||||||
TitleObject::class,
|
TitleObject::class,
|
||||||
TitleSortedObject::class,
|
TitleSortedObject::class,
|
||||||
|
TitleArraySortedObject::class,
|
||||||
ThroughDefinerVersioned::class,
|
ThroughDefinerVersioned::class,
|
||||||
ThroughIntermediaryVersioned::class,
|
ThroughIntermediaryVersioned::class,
|
||||||
ThroughBelongsVersioned::class,
|
ThroughBelongsVersioned::class,
|
||||||
@ -332,6 +334,17 @@ class GridFieldOrderableRowsTest extends SapphireTest
|
|||||||
$this->assertSame(['B', 'A', 'C'], $sortedList->column('Iden'));
|
$this->assertSame(['B', 'A', 'C'], $sortedList->column('Iden'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testGetManipulatedDataWithDefaultSortArray()
|
||||||
|
{
|
||||||
|
$sortedList = $this->getTitleSortedListForManipuatedData(TitleArraySortedObject::class, [
|
||||||
|
['Title' => 'X', 'Iden' => 'C', 'OtherSort' => 3],
|
||||||
|
['Title' => 'Z', 'Iden' => 'A', 'OtherSort' => 2],
|
||||||
|
['Title' => 'Z', 'Iden' => 'B', 'OtherSort' => 1],
|
||||||
|
]);
|
||||||
|
$this->assertSame(['C', 'B', 'A'], $sortedList->column('Iden'));
|
||||||
|
}
|
||||||
|
|
||||||
private function getTitleSortedListForManipuatedData(string $dataClass, array $data): DataList
|
private function getTitleSortedListForManipuatedData(string $dataClass, array $data): DataList
|
||||||
{
|
{
|
||||||
$list = new DataList($dataClass);
|
$list = new DataList($dataClass);
|
||||||
|
22
tests/Stub/TitleArraySortedObject.php
Normal file
22
tests/Stub/TitleArraySortedObject.php
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Symbiote\GridFieldExtensions\Tests\Stub;
|
||||||
|
|
||||||
|
use SilverStripe\Dev\TestOnly;
|
||||||
|
use SilverStripe\ORM\DataObject;
|
||||||
|
|
||||||
|
class TitleArraySortedObject extends DataObject implements TestOnly
|
||||||
|
{
|
||||||
|
private static $db = [
|
||||||
|
'Title' => 'Varchar',
|
||||||
|
'Iden' => 'Varchar',
|
||||||
|
'OtherSort' => 'Int'
|
||||||
|
];
|
||||||
|
|
||||||
|
private static array $default_sort = [
|
||||||
|
'Title' => 'ASC',
|
||||||
|
'OtherSort' => 'ASC',
|
||||||
|
];
|
||||||
|
|
||||||
|
private static $table_name = 'TitleArraySortedObject';
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user