From 43347472f32aed848adfcbb3f0c6bfbfc1093bd3 Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Fri, 19 Nov 2021 10:24:54 -0500 Subject: [PATCH] Update the $pages->add() method to pull a fresh copy of the $page from the database after it has been added. This helps with some API usages where returned $page may have not been fully initialized in some cases. --- wire/core/PagesEditor.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/wire/core/PagesEditor.php b/wire/core/PagesEditor.php index ae2e207a..9c223423 100644 --- a/wire/core/PagesEditor.php +++ b/wire/core/PagesEditor.php @@ -102,6 +102,11 @@ class PagesEditor extends Wire { unset($values['title']); } + if(isset($values['status'])) { + $page->status = $values['status']; + unset($values['status']); + } + // save page before setting $values just in case any fieldtypes // require the page to have an ID already (like file-based) if(!$this->pages->save($page)) throw new WireException($exceptionMessage); @@ -112,6 +117,15 @@ class PagesEditor extends Wire { foreach($values as $key => $value) $page->set($key, $value); $this->pages->save($page); } + + // get a fresh copy of the page + if($page->id) { + $of = $this->pages->outputFormatting; + if($of) $this->pages->setOutputFormatting(false); + $p = $this->pages->getById($page->id, $template, $page->parent_id); + if($p->id) $page = $p; + if($of) $this->pages->setOutputFormatting(true); + } return $page; }