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

Update PagesEditor to throw descriptive exception when attempting to save a NullPage. This is to fix what were previously ambiguous error messages.

This commit is contained in:
Ryan Cramer
2023-09-15 08:22:09 -04:00
parent 36580883d7
commit b0414278f8
2 changed files with 14 additions and 6 deletions

View File

@@ -97,6 +97,14 @@ class NullPage extends Page implements WireNull {
*/
public function isHidden() { return true; }
/**
* #pw-internal
*
* @return bool
*
*/
public function isNew() { return false; }
/**
* #pw-internal
*

View File

@@ -447,9 +447,9 @@ class PagesEditor extends Wire {
$language = null;
// if language support active, switch to default language so that saved fields and hooks don't need to be aware of language
if($languages && $page->id != $user->id) {
$language = $user->language && $user->language->id ? $user->language : null;
if($language) $user->language = $languages->getDefault();
if($languages && $page->id != $user->id && "$user->language") {
$language = $user->language;
$user->setLanguage($languages->getDefault());
}
$reason = '';
@@ -457,8 +457,8 @@ class PagesEditor extends Wire {
if($isNew) $this->pages->setupNew($page);
if(!$this->isSaveable($page, $reason, '', $options)) {
if($language) $user->language = $language;
throw new WireException("Cant save page {$page->id}: {$page->path}: $reason");
if($language) $user->setLanguage($language);
throw new WireException(rtrim("Cant save page (id=$page->id): $page->path", ": ") . ": $reason");
}
if($page->hasStatus(Page::statusUnpublished) && $page->template->noUnpublish) {
@@ -476,7 +476,7 @@ class PagesEditor extends Wire {
if($options['adjustName']) $this->pages->names()->checkNameConflicts($page);
if(!$this->savePageQuery($page, $options)) return false;
$result = $this->savePageFinish($page, $isNew, $options);
if($language) $user->language = $language; // restore language
if($language) $user->setLanguage($language); // restore language
return $result;
}