1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-09 08:17:12 +02:00

Add support for a $page->sortPrevious property, which is populated with the old value when a page's sort value is changed at runtime.

This commit is contained in:
Ryan Cramer
2024-01-12 11:45:31 -05:00
parent ef4444dd7f
commit 98fe7f94a0
2 changed files with 16 additions and 2 deletions

View File

@@ -70,6 +70,7 @@
* @property bool $hasFiles Does this page have one or more files in its files path? #pw-group-files
* @property bool $outputFormatting Whether output formatting is enabled or not. #pw-advanced
* @property int $sort Sort order of this page relative to siblings (applicable when manual sorting is used). #pw-group-system
* @property int|null $sortPrevious Previous sort order, if changed (3.0.235+) #pw-group-system
* @property int $index Index of this page relative to its siblings, regardless of sort (starting from 0). #pw-group-traversal
* @property string $sortfield Field that a page is sorted by relative to its siblings (default="sort", which means drag/drop manual) #pw-group-system
* @property null|array _statusCorruptedFields Field names that caused the page to have Page::statusCorrupted status. #pw-internal
@@ -379,6 +380,14 @@ class Page extends WireData implements \Countable, WireMatchable {
*/
private $namePrevious;
/**
* The previous sort value used by page, if changed during runtime.
*
* @var int
*
*/
private $sortPrevious;
/**
* The previous status used by this page, if it changed during runtime.
*
@@ -601,6 +610,7 @@ class Page extends WireData implements \Countable, WireMatchable {
$this->parentPrevious = null;
$this->templatePrevious = null;
$this->statusPrevious = null;
$this->sortPrevious = null;
}
/**
@@ -700,7 +710,8 @@ class Page extends WireData implements \Countable, WireMatchable {
$this->setStatus($value);
break;
case 'statusPrevious':
$this->statusPrevious = is_null($value) ? null : (int) $value;
case 'sortPrevious':
$this->$key = is_null($value) ? null : (int) $value;
break;
case 'name':
$this->setName($value);
@@ -4040,6 +4051,8 @@ class Page extends WireData implements \Countable, WireMatchable {
$this->namePrevious = $old;
} else if($what === 'status' && $old !== null) {
$this->statusPrevious = (int) $old;
} else if($what === 'sort' && $old !== null && $this->sortPrevious === null) {
$this->sortPrevious = (int) $old;
}
}
return parent::trackChange($what, $old, $new);

View File

@@ -137,6 +137,7 @@ abstract class PageProperties {
'rootParent' => 'm',
'siblings' => 'm',
'sort' => 's',
'sortPrevious' => 'p',
'sortable' => 'm',
'sortfield' => 's',
'status' => 's',