mirror of
https://github.com/processwire/processwire.git
synced 2025-08-15 03:05:26 +02:00
Fix issue processwire/processwire-issues#778
This commit is contained in:
@@ -223,6 +223,7 @@ class Templates extends WireSaveableItems {
|
|||||||
public function ___clone(Saveable $item, $name = '') {
|
public function ___clone(Saveable $item, $name = '') {
|
||||||
|
|
||||||
$original = $item;
|
$original = $item;
|
||||||
|
/** @var Template $item */
|
||||||
$item = clone $item;
|
$item = clone $item;
|
||||||
|
|
||||||
if($item->flags & Template::flagSystem) {
|
if($item->flags & Template::flagSystem) {
|
||||||
@@ -479,6 +480,7 @@ class Templates extends WireSaveableItems {
|
|||||||
|
|
||||||
$foundParent = null;
|
$foundParent = null;
|
||||||
$foundParents = $getAll ? $this->wire('pages')->newPageArray() : null;
|
$foundParents = $getAll ? $this->wire('pages')->newPageArray() : null;
|
||||||
|
$foundParentQty = 0;
|
||||||
|
|
||||||
if($template->noShortcut || !count($template->parentTemplates)) return $foundParents;
|
if($template->noShortcut || !count($template->parentTemplates)) return $foundParents;
|
||||||
if($template->noParents == -1) {
|
if($template->noParents == -1) {
|
||||||
@@ -508,11 +510,13 @@ class Templates extends WireSaveableItems {
|
|||||||
if(!$numParentPages) continue;
|
if(!$numParentPages) continue;
|
||||||
|
|
||||||
if($getAll) {
|
if($getAll) {
|
||||||
|
// build list of all parents (will check access outside loop)
|
||||||
if($numParentPages) $foundParents->add($parentPages);
|
if($numParentPages) $foundParents->add($parentPages);
|
||||||
continue;
|
continue;
|
||||||
} else if($numParentPages > 1) {
|
} else if($numParentPages > 1) {
|
||||||
// multiple possible parents
|
// multiple possible parents, we can early-exit
|
||||||
$parentPage = $this->wire('pages')->newNullPage();
|
$foundParentQty += $numParentPages;
|
||||||
|
break;
|
||||||
} else {
|
} else {
|
||||||
// one possible parent
|
// one possible parent
|
||||||
$parentPage = $parentPages->first();
|
$parentPage = $parentPages->first();
|
||||||
@@ -529,11 +533,12 @@ class Templates extends WireSaveableItems {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($parentPage && $parentPage->id) $foundParentQty++;
|
||||||
$foundParent = $parentPage;
|
$foundParent = $parentPage;
|
||||||
break;
|
if($foundParentQty > 1) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($checkAccess && $foundParents && $foundParents->count()) {
|
if($checkAccess && $getAll && $foundParents && $foundParents->count()) {
|
||||||
$p = $this->wire('pages')->newPage(array('template' => $template));
|
$p = $this->wire('pages')->newPage(array('template' => $template));
|
||||||
foreach($foundParents as $parentPage) {
|
foreach($foundParents as $parentPage) {
|
||||||
if(!$parentPage->addable($p)) $foundParents->remove($parentPage);
|
if(!$parentPage->addable($p)) $foundParents->remove($parentPage);
|
||||||
@@ -541,6 +546,8 @@ class Templates extends WireSaveableItems {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if($getAll) return $foundParents;
|
if($getAll) return $foundParents;
|
||||||
|
if($foundParentQty > 1) return $this->wire('pages')->newNullPage();
|
||||||
|
|
||||||
return $foundParent;
|
return $foundParent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -286,10 +286,14 @@ class ProcessPageAdd extends Process implements ConfigurableModule, WirePageEdit
|
|||||||
if(!$templateID) throw new WireException("No template specified");
|
if(!$templateID) throw new WireException("No template specified");
|
||||||
$template = $this->templates->get($templateID);
|
$template = $this->templates->get($templateID);
|
||||||
if(!$template) throw new WireException("Unknown template");
|
if(!$template) throw new WireException("Unknown template");
|
||||||
$parentTemplates = $template->parentTemplates;
|
$parentTemplates = new TemplatesArray();;
|
||||||
$parentTemplate = $this->wire('templates')->get(reset($parentTemplates));
|
foreach($template->parentTemplates as $templateID) {
|
||||||
if(!$parentTemplate) throw new WireException("Unable to locate parent template " . reset($parentTemplates));
|
$t = $this->templates->get((int) $templateID);
|
||||||
$parents = $this->wire('pages')->find("template=$parentTemplate, include=hidden, limit=500, sort=name");
|
if($t) $parentTemplates->add($t);
|
||||||
|
}
|
||||||
|
if(!count($parentTemplates)) throw new WireException("No parent templates defined for $template->name");
|
||||||
|
$parentTemplateIDs = $parentTemplates->implode('|', 'id');
|
||||||
|
$parents = $this->wire('pages')->find("templates_id=$parentTemplateIDs, include=hidden, limit=500, sort=name");
|
||||||
if(!count($parents)) throw new WireException("No usable parents match this template");
|
if(!count($parents)) throw new WireException("No usable parents match this template");
|
||||||
if(count($parents) == 1) {
|
if(count($parents) == 1) {
|
||||||
$url = "./?parent_id=" . $parents->first()->id;
|
$url = "./?parent_id=" . $parents->first()->id;
|
||||||
@@ -298,7 +302,6 @@ class ProcessPageAdd extends Process implements ConfigurableModule, WirePageEdit
|
|||||||
}
|
}
|
||||||
|
|
||||||
$templateLabel = $this->getTemplateLabel($template);
|
$templateLabel = $this->getTemplateLabel($template);
|
||||||
$parentTemplateLabel = $this->getTemplateLabel($parentTemplate);
|
|
||||||
$form = $this->wire('modules')->get('InputfieldForm');
|
$form = $this->wire('modules')->get('InputfieldForm');
|
||||||
$form->description = $this->getTemplateLabel($template);
|
$form->description = $this->getTemplateLabel($template);
|
||||||
$form->method = 'get';
|
$form->method = 'get';
|
||||||
@@ -316,7 +319,7 @@ class ProcessPageAdd extends Process implements ConfigurableModule, WirePageEdit
|
|||||||
$f->attr('name', 'parent_id');
|
$f->attr('name', 'parent_id');
|
||||||
$f->attr('id', 'select_parent_id');
|
$f->attr('id', 'select_parent_id');
|
||||||
$f->label = sprintf($this->_('Where do you want to add the new %s?'), "\"$templateLabel\"");
|
$f->label = sprintf($this->_('Where do you want to add the new %s?'), "\"$templateLabel\"");
|
||||||
$f->description = sprintf($this->_('Please select a parent %s page below:'), "\"$parentTemplateLabel\"");
|
$f->description = sprintf($this->_('Please select a parent %s page below:'), ''); // Select parent label // you can omit the '%s' (no longer used)
|
||||||
|
|
||||||
$options = array();
|
$options = array();
|
||||||
foreach($parents as $parent) {
|
foreach($parents as $parent) {
|
||||||
@@ -381,8 +384,9 @@ class ProcessPageAdd extends Process implements ConfigurableModule, WirePageEdit
|
|||||||
$url = $item['url'];
|
$url = $item['url'];
|
||||||
if(strpos($url, 'parent_id') === false) $url .= "&parent_id=$parent->id";
|
if(strpos($url, 'parent_id') === false) $url .= "&parent_id=$parent->id";
|
||||||
$out .= "<li><a href='./$url'>";
|
$out .= "<li><a href='./$url'>";
|
||||||
foreach($parent->parents()->and($parent) as $p) {
|
$parentParents = $parent->parents()->and($parent);
|
||||||
if($p->id == 1) continue;
|
foreach($parentParents as $p) {
|
||||||
|
if($p->id == 1 && $parentParents->count() > 1) continue;
|
||||||
$out .= "$p->title<i class='ui-priority-secondary fa fa-fw fa-angle-right'></i>";
|
$out .= "$p->title<i class='ui-priority-secondary fa fa-fw fa-angle-right'></i>";
|
||||||
}
|
}
|
||||||
$out .= "</a></li>";
|
$out .= "</a></li>";
|
||||||
|
Reference in New Issue
Block a user