1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-10 00:37:02 +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 $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 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 $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 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 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 * @property null|array _statusCorruptedFields Field names that caused the page to have Page::statusCorrupted status. #pw-internal
@@ -377,7 +378,15 @@ class Page extends WireData implements \Countable, WireMatchable {
* @var string * @var string
* *
*/ */
private $namePrevious; 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. * 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->parentPrevious = null;
$this->templatePrevious = null; $this->templatePrevious = null;
$this->statusPrevious = null; $this->statusPrevious = null;
$this->sortPrevious = null;
} }
/** /**
@@ -700,7 +710,8 @@ class Page extends WireData implements \Countable, WireMatchable {
$this->setStatus($value); $this->setStatus($value);
break; break;
case 'statusPrevious': case 'statusPrevious':
$this->statusPrevious = is_null($value) ? null : (int) $value; case 'sortPrevious':
$this->$key = is_null($value) ? null : (int) $value;
break; break;
case 'name': case 'name':
$this->setName($value); $this->setName($value);
@@ -4040,6 +4051,8 @@ class Page extends WireData implements \Countable, WireMatchable {
$this->namePrevious = $old; $this->namePrevious = $old;
} else if($what === 'status' && $old !== null) { } else if($what === 'status' && $old !== null) {
$this->statusPrevious = (int) $old; $this->statusPrevious = (int) $old;
} else if($what === 'sort' && $old !== null && $this->sortPrevious === null) {
$this->sortPrevious = (int) $old;
} }
} }
return parent::trackChange($what, $old, $new); return parent::trackChange($what, $old, $new);

View File

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