1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-11 09:14:58 +02:00
This commit is contained in:
Ryan Cramer
2022-04-15 08:59:34 -04:00
parent 047ffb1c20
commit 0d2b570454

View File

@@ -371,7 +371,13 @@ class PagesType extends Wire implements \IteratorAggregate, \Countable {
*/ */
public function get($selectorString) { public function get($selectorString) {
$pages = $this->wire()->pages;
$page = null;
if(empty($selectorString)) return $pages->newNullPage();
$options = $this->getLoadOptions(array('getOne' => true)); $options = $this->getLoadOptions(array('getOne' => true));
if(empty($options['caller'])) { if(empty($options['caller'])) {
$caller = $this->className() . ".get($selectorString)"; $caller = $this->className() . ".get($selectorString)";
$options['caller'] = $caller; $options['caller'] = $caller;
@@ -381,23 +387,20 @@ class PagesType extends Wire implements \IteratorAggregate, \Countable {
if(ctype_digit("$selectorString")) { if(ctype_digit("$selectorString")) {
// selector string contains a page ID // selector string contains a page ID
if(count($this->templates) == 1 && count($this->parents) == 1) { if(count($this->templates) === 1 && count($this->parents) === 1) {
// optimization for when there is only 1 template and 1 parent // optimization for when there is only 1 template and 1 parent
$options['template'] = $this->template; $options['template'] = $this->template;
$options['parent_id'] = $this->parent_id; $options['parent_id'] = $this->parent_id;
$page = $this->wire('pages')->getById(array((int) $selectorString), $options);
return $page ? $page : $this->wire('pages')->newNullPage();
} else { } else {
// multiple possible templates/parents // multiple templates and/or parents possible
$page = $this->wire('pages')->getById(array((int) $selectorString), $options);
return $page;
} }
$page = $pages->getById(array((int) $selectorString), $options);
} else if(strpos($selectorString, '=') === false) { } else if(strpos($selectorString, '=') === false) {
// selector string contains no operators, so it is a page name or path // selector string contains no operators, so it is a page name or path
if(strpos($selectorString, '/') === false) { if(strpos($selectorString, '/') === false) {
// selector string contains no operators or slashes, so we assume it to be a page ame // selector string contains no operators or slashes, so we assume it to be a page ame
$s = $this->sanitizer->name($selectorString); $s = $this->wire()->sanitizer->name($selectorString);
if($s === $selectorString) $selectorString = "name=$s"; if($s === $selectorString) $selectorString = "name=$s";
} else { } else {
// page path, can pass through // page path, can pass through
@@ -406,13 +409,22 @@ class PagesType extends Wire implements \IteratorAggregate, \Countable {
} else { } else {
// selector string with operators, can pass through // selector string with operators, can pass through
} }
if($page === null) {
$page = $pages->get($this->selectorString($selectorString), array(
'caller' => $caller,
'loadOptions' => $options
));
}
$page = $this->pages->get($this->selectorString($selectorString), array( if($page->id) {
'caller' => $caller, if($this->isValid($page)) {
'loadOptions' => $options $this->loaded($page);
)); } else {
if($page->id && !$this->isValid($page)) $page = $this->wire('pages')->newNullPage(); $pages->uncache($page);
if($page->id) $this->loaded($page); $page = $pages->newNullPage();
}
}
return $page; return $page;
} }