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

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.

This commit is contained in:
Ryan Cramer
2021-11-19 10:24:54 -05:00
parent 8a22e5f095
commit 43347472f3

View File

@@ -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;
}