mirror of
https://github.com/processwire/processwire.git
synced 2025-08-18 12:31:17 +02:00
Fix issue processwire/processwire-issues#1495
This commit is contained in:
@@ -1844,7 +1844,7 @@ class PagesEditor extends Wire {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// detect template from parent (when possible)
|
// detect template from parent (when possible)
|
||||||
if(!$template && !empty($parent)) {
|
if(!$template && !empty($parent) && empty($options['id'])) {
|
||||||
$parent = is_object($parent) ? $parent : $this->pages->get($parent);
|
$parent = is_object($parent) ? $parent : $this->pages->get($parent);
|
||||||
if($parent->id) {
|
if($parent->id) {
|
||||||
if(count($parent->template->childTemplates) === 1) {
|
if(count($parent->template->childTemplates) === 1) {
|
||||||
@@ -1856,7 +1856,7 @@ class PagesEditor extends Wire {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// detect parent from template (when possible)
|
// detect parent from template (when possible)
|
||||||
if($template && empty($parent) && count($template->parentTemplates) === 1) {
|
if($template && empty($parent) && empty($options['id']) && count($template->parentTemplates) === 1) {
|
||||||
$parentTemplates = $template->parentTemplates();
|
$parentTemplates = $template->parentTemplates();
|
||||||
if($parentTemplates->count()) {
|
if($parentTemplates->count()) {
|
||||||
$numParents = $this->pages->count("template=$parentTemplates, include=all");
|
$numParents = $this->pages->count("template=$parentTemplates, include=all");
|
||||||
@@ -1875,6 +1875,7 @@ class PagesEditor extends Wire {
|
|||||||
|
|
||||||
if(isset($options['id']) && ctype_digit("$options[id]") && (int) $options['id'] > 0) {
|
if(isset($options['id']) && ctype_digit("$options[id]") && (int) $options['id'] > 0) {
|
||||||
$options['id'] = (int) $options['id'];
|
$options['id'] = (int) $options['id'];
|
||||||
|
if($parent && "$options[id]" === "$parent") unset($options['parent']);
|
||||||
} else {
|
} else {
|
||||||
unset($options['id']);
|
unset($options['id']);
|
||||||
}
|
}
|
||||||
|
@@ -407,6 +407,7 @@ class PagesLoader extends Wire {
|
|||||||
|
|
||||||
if($lazy) {
|
if($lazy) {
|
||||||
// lazy load: create empty pages containing only id and template
|
// lazy load: create empty pages containing only id and template
|
||||||
|
$templates = $this->wire()->templates;
|
||||||
$pages = $this->pages->newPageArray($loadOptions);
|
$pages = $this->pages->newPageArray($loadOptions);
|
||||||
$pages->finderOptions($options);
|
$pages->finderOptions($options);
|
||||||
$pages->setDuplicateChecking(false);
|
$pages->setDuplicateChecking(false);
|
||||||
@@ -419,7 +420,7 @@ class PagesLoader extends Wire {
|
|||||||
if(isset($templatesByID[$templateID])) {
|
if(isset($templatesByID[$templateID])) {
|
||||||
$template = $templatesByID[$templateID];
|
$template = $templatesByID[$templateID];
|
||||||
} else {
|
} else {
|
||||||
$template = $this->wire('templates')->get($templateID);
|
$template = $templates->get($templateID);
|
||||||
$templatesByID[$templateID] = $template;
|
$templatesByID[$templateID] = $template;
|
||||||
}
|
}
|
||||||
$page = $this->pages->newPage($template);
|
$page = $this->pages->newPage($template);
|
||||||
@@ -441,6 +442,7 @@ class PagesLoader extends Wire {
|
|||||||
|
|
||||||
} else if($loadPages) {
|
} else if($loadPages) {
|
||||||
// parent_id is null unless a single parent was specified in the selectors
|
// parent_id is null unless a single parent was specified in the selectors
|
||||||
|
$templates = $this->wire()->templates;
|
||||||
$parent_id = $pageFinder->getParentID();
|
$parent_id = $pageFinder->getParentID();
|
||||||
$idsSorted = array();
|
$idsSorted = array();
|
||||||
$idsByTemplate = array();
|
$idsByTemplate = array();
|
||||||
@@ -462,7 +464,7 @@ class PagesLoader extends Wire {
|
|||||||
$unsortedPages = $this->pages->newPageArray($loadOptions);
|
$unsortedPages = $this->pages->newPageArray($loadOptions);
|
||||||
foreach($idsByTemplate as $tpl_id => $ids) {
|
foreach($idsByTemplate as $tpl_id => $ids) {
|
||||||
$opt = $loadOptions;
|
$opt = $loadOptions;
|
||||||
$opt['template'] = $this->wire('templates')->get($tpl_id);
|
$opt['template'] = $templates->get($tpl_id);
|
||||||
$opt['parent_id'] = $parent_id;
|
$opt['parent_id'] = $parent_id;
|
||||||
$unsortedPages->import($this->getById($ids, $opt));
|
$unsortedPages->import($this->getById($ids, $opt));
|
||||||
}
|
}
|
||||||
@@ -482,7 +484,7 @@ class PagesLoader extends Wire {
|
|||||||
$pages = $this->pages->newPageArray($loadOptions);
|
$pages = $this->pages->newPageArray($loadOptions);
|
||||||
reset($idsByTemplate);
|
reset($idsByTemplate);
|
||||||
$opt = $loadOptions;
|
$opt = $loadOptions;
|
||||||
$opt['template'] = $this->wire('templates')->get(key($idsByTemplate));
|
$opt['template'] = $templates->get(key($idsByTemplate));
|
||||||
$opt['parent_id'] = $parent_id;
|
$opt['parent_id'] = $parent_id;
|
||||||
$pages->import($this->getById($idsSorted, $opt));
|
$pages->import($this->getById($idsSorted, $opt));
|
||||||
}
|
}
|
||||||
@@ -1168,9 +1170,10 @@ class PagesLoader extends Wire {
|
|||||||
$page = $this->pages->newPage(array(
|
$page = $this->pages->newPage(array(
|
||||||
'pageClass' => $pageClass,
|
'pageClass' => $pageClass,
|
||||||
'template' => $pageTemplate ? $pageTemplate : $row['templates_id'],
|
'template' => $pageTemplate ? $pageTemplate : $row['templates_id'],
|
||||||
|
'parent' => $row['parent_id'],
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
unset($row['templates_id']);
|
unset($row['templates_id'], $row['parent_id']);
|
||||||
foreach($row as $key => $value) $page->set($key, $value);
|
foreach($row as $key => $value) $page->set($key, $value);
|
||||||
if($options['cache'] === false) $page->loaderCache = false;
|
if($options['cache'] === false) $page->loaderCache = false;
|
||||||
$page->instanceID = ++self::$pageInstanceID;
|
$page->instanceID = ++self::$pageInstanceID;
|
||||||
|
Reference in New Issue
Block a user