Skip to content

Commit

Permalink
Fixed GridFieldOrderableRows issue when data class is Versioned and r…
Browse files Browse the repository at this point in the history
…elation is has_many (symbiote#243)

* Fixed GridFieldOrderableRows issue when data class is Versioned and relation is has_many

* just compare table names rather than updating existing getSortTable() func

Conflicts:
	src/GridFieldOrderableRows.php
  • Loading branch information
Priyashantha authored and robbieaverill committed Feb 9, 2018
1 parent 509abf1 commit 3b3f4a9
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/GridFieldOrderableRows.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
use SilverStripe\ORM\DataObjectInterface;
use SilverStripe\ORM\DB;
use SilverStripe\ORM\ManyManyList;
use SilverStripe\ORM\Map;
use SilverStripe\ORM\SS_List;
use SilverStripe\ORM\SS_Map;
use SilverStripe\Versioned\Versioned;
use SilverStripe\View\ViewableData;

Expand Down Expand Up @@ -210,24 +210,19 @@ public function validateSortField(SS_List $list)
public function getSortTable(SS_List $list)
{
$field = $this->getSortField();

if ($list instanceof ManyManyList) {
$extra = $list->getExtraFields();
$table = $list->getJoinTable();

if ($extra && array_key_exists($field, $extra)) {
return $table;
}
}

$classes = ClassInfo::dataClassesFor($list->dataClass());

foreach ($classes as $class) {
if (singleton($class)->hasDataBaseField($field)) {
return DataObject::getSchema()->tableName($class);
}
}

throw new \Exception("Couldn't find the sort field '$field'");
}

Expand Down Expand Up @@ -529,14 +524,16 @@ protected function reorderItems($list, array $values, array $sortedIDs)
/** @var SS_List $map */
$map = $list->map('ID', $sortField);
//fix for versions of SS that return inconsistent types for `map` function
if ($map instanceof SS_Map) {
if ($map instanceof Map) {
$map = $map->toArray();
}

// If not a ManyManyList and using versioning, detect it.
$this->validateSortField($list);
$class = $list->dataClass();
$isVersioned = $class::has_extension(Versioned::class);
if (DataObject::getSchema()->tableName($class) == $this->getSortTable($list)) {
$isVersioned = $class::has_extension(Versioned::class);
}

// Loop through each item, and update the sort values which do not
// match to order the objects.
Expand Down

0 comments on commit 3b3f4a9

Please sign in to comment.