Skip to content

Commit

Permalink
Merge branch '3' into 4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Apr 27, 2023
2 parents 55cb9cc + 6d46483 commit c9eac61
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/GridFieldOrderableRows.php
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,13 @@ public function getManipulatedData(GridField $grid, SS_List $list)
if ($list instanceof DataList) {
$classname = $list->dataClass();
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
// This may result in redundancy... but it seems to work
$sortterm .= ($sortterm ? ', ' : '') . $defaultSort;
Expand Down
12 changes: 12 additions & 0 deletions tests/GridFieldOrderableRowsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use Symbiote\GridFieldExtensions\Tests\Stub\ThroughIntermediary;
use Symbiote\GridFieldExtensions\Tests\Stub\TitleObject;
use Symbiote\GridFieldExtensions\Tests\Stub\TitleSortedObject;
use Symbiote\GridFieldExtensions\Tests\Stub\TitleArraySortedObject;
use Symbiote\GridFieldExtensions\Tests\Stub\ThroughIntermediaryVersioned;

/**
Expand Down Expand Up @@ -54,6 +55,7 @@ class GridFieldOrderableRowsTest extends SapphireTest
ThroughBelongs::class,
TitleObject::class,
TitleSortedObject::class,
TitleArraySortedObject::class,
ThroughDefinerVersioned::class,
ThroughIntermediaryVersioned::class,
ThroughBelongsVersioned::class,
Expand Down Expand Up @@ -387,6 +389,16 @@ public function provideGetManipulatedData(): array
],
['B', 'A', 'C']
],
[
TitleArraySortedObject::class,
DataList::class,
[
['Title' => 'X', 'Iden' => 'C', 'OtherSort' => 3],
['Title' => 'Z', 'Iden' => 'A', 'OtherSort' => 2],
['Title' => 'Z', 'Iden' => 'B', 'OtherSort' => 1],
],
['C', 'B', 'A']
],
];
}
}
22 changes: 22 additions & 0 deletions tests/Stub/TitleArraySortedObject.php
Original file line number Diff line number Diff line change
@@ -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';
}

0 comments on commit c9eac61

Please sign in to comment.