1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-10 08:44:46 +02:00
This commit is contained in:
Ryan Cramer
2022-02-24 12:09:54 -05:00
parent aa87cc5603
commit 1eb156f1aa
2 changed files with 44 additions and 10 deletions

View File

@@ -1834,7 +1834,7 @@ class PagesEditor extends Wire {
// detect name from path
$options['name'] = $name;
}
if(empty($parent)) {
if(empty($parent) && !$this->pages->loader()->isLoading()) {
// detect parent from path
$parentPath = count($parts) ? implode('/', $parts) : '/';
$parent = $this->pages->getByPath($parentPath);
@@ -1844,7 +1844,7 @@ class PagesEditor extends Wire {
}
// detect template from parent (when possible)
if(!$template && !empty($parent) && empty($options['id'])) {
if(!$template && !empty($parent) && empty($options['id']) && !$this->pages->loader()->isLoading()) {
$parent = is_object($parent) ? $parent : $this->pages->get($parent);
if($parent->id) {
if(count($parent->template->childTemplates) === 1) {
@@ -1856,14 +1856,17 @@ class PagesEditor extends Wire {
}
// detect parent from template (when possible)
if($template && empty($parent) && empty($options['id']) && count($template->parentTemplates) === 1) {
$parentTemplates = $template->parentTemplates();
if($parentTemplates->count()) {
$numParents = $this->pages->count("template=$parentTemplates, include=all");
if($numParents === 1) {
$parent = $this->pages->get("template=$parentTemplates");
if($template && empty($parent) && empty($options['id']) && !$this->pages->loader()->isLoading()) {
if(count($template->parentTemplates) === 1) {
$parentTemplates = $template->parentTemplates();
if($parentTemplates->count()) {
$numParents = $this->pages->count("template=$parentTemplates, include=all");
if($numParents === 1) {
$parent = $this->pages->get("template=$parentTemplates");
if(!$parent->id) $parent = null;
}
}
}
}
}
// detect class from template

View File

@@ -64,6 +64,14 @@ class PagesLoader extends Wire {
*/
protected $debug = false;
/**
* Are we currenty loading pages?
*
* @var bool
*
*/
protected $loading = false;
/**
* Page instance ID
*
@@ -415,7 +423,9 @@ class PagesLoader extends Wire {
$cachePages = false;
$template = null;
$templatesByID = array();
$loading = $this->loading;
if(!$loading) $this->loading = true;
foreach($pagesIDs as $id => $templateID) {
if(isset($templatesByID[$templateID])) {
$template = $templatesByID[$templateID];
@@ -429,6 +439,7 @@ class PagesLoader extends Wire {
$pages->add($page);
}
if(!$loading) $this->loading = false;
$pages->setDuplicateChecking(true);
if(count($pagesIDs)) $pages->_lazy(true);
unset($template, $templatesByID);
@@ -934,6 +945,7 @@ class PagesLoader extends Wire {
/** @var WireDatabasePDO $database */
$database = $this->wire('database');
$idsByTemplate = array();
$loading = $this->loading;
if(is_array($template)) {
// $template property specifies an array of options
@@ -1045,6 +1057,7 @@ class PagesLoader extends Wire {
return $pages;
}
if(!$loading) $this->loading = true;
if(count($idsByTemplate)) {
// ok
@@ -1205,11 +1218,16 @@ class PagesLoader extends Wire {
$template = null;
}
if($options['getOne']) return count($loaded) ? reset($loaded) : $this->pages->newNullPage();
if($options['getOne']) {
if(!$loading) $this->loading = false;
return count($loaded) ? reset($loaded) : $this->pages->newNullPage();
}
$pages = $this->pages->newPageArray($options);
$pages->setDuplicateChecking(false);
$pages->import($loaded);
$pages->setDuplicateChecking(true);
if(!$loading) $this->loading = false;
// debug mode only
if($this->debug) {
@@ -1230,6 +1248,7 @@ class PagesLoader extends Wire {
}
}
}
return $pages;
}
@@ -1921,5 +1940,17 @@ class PagesLoader extends Wire {
public function getLastPageFinder() {
return $this->lastPageFinder;
}
/**
* Are we currently loading pages?
*
* @return bool
* @since 3.0.195
*
*
*/
public function isLoading() {
return $this->loading;
}
}