Skip to content

Commit

Permalink
Sort order save in _Live table
Browse files Browse the repository at this point in the history
  • Loading branch information
amolswnz committed May 12, 2019
1 parent b6f0322 commit 2eb6213
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions code/GridFieldOrderableRows.php
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,9 @@ protected function reorderItems($list, array $values, array $sortedIDs) {
if ($class == $this->getSortTable($list)) {
$isVersioned = $class::has_extension('Versioned');
}
if ($class::has_extension('Versioned')) {
$isVersioned = true;
}

// Loop through each item, and update the sort values which do not
// match to order the objects.
Expand Down Expand Up @@ -505,11 +508,15 @@ protected function reorderItems($list, array $values, array $sortedIDs) {
// similar to the SiteTree where you change the position, and then
// you go into the record and publish it.
foreach($sortedIDs as $sortValue => $id) {
if($map[$id] != $sortValue) {
$record = $class::get()->byID($id);
$record = $class::get()->byID($id);
if ($map[$id] != $sortValue) {
$record->$sortField = $sortValue;
$record->write();
}
// Update stage to live only for published records
if ($record->isPublished()) {
$record->publish('Stage', 'Live');
}
}
}

Expand Down

0 comments on commit 2eb6213

Please sign in to comment.