mirror of
https://github.com/processwire/processwire.git
synced 2025-08-10 00:37:02 +02:00
Updates for processwire/processwire-issues#1552
This commit is contained in:
@@ -371,7 +371,13 @@ class PagesType extends Wire implements \IteratorAggregate, \Countable {
|
||||
*/
|
||||
public function get($selectorString) {
|
||||
|
||||
$pages = $this->wire()->pages;
|
||||
$page = null;
|
||||
|
||||
if(empty($selectorString)) return $pages->newNullPage();
|
||||
|
||||
$options = $this->getLoadOptions(array('getOne' => true));
|
||||
|
||||
if(empty($options['caller'])) {
|
||||
$caller = $this->className() . ".get($selectorString)";
|
||||
$options['caller'] = $caller;
|
||||
@@ -381,23 +387,20 @@ class PagesType extends Wire implements \IteratorAggregate, \Countable {
|
||||
|
||||
if(ctype_digit("$selectorString")) {
|
||||
// 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
|
||||
$options['template'] = $this->template;
|
||||
$options['parent_id'] = $this->parent_id;
|
||||
$page = $this->wire('pages')->getById(array((int) $selectorString), $options);
|
||||
return $page ? $page : $this->wire('pages')->newNullPage();
|
||||
} else {
|
||||
// multiple possible templates/parents
|
||||
$page = $this->wire('pages')->getById(array((int) $selectorString), $options);
|
||||
return $page;
|
||||
// multiple templates and/or parents possible
|
||||
}
|
||||
$page = $pages->getById(array((int) $selectorString), $options);
|
||||
|
||||
} else if(strpos($selectorString, '=') === false) {
|
||||
// selector string contains no operators, so it is a page name or path
|
||||
if(strpos($selectorString, '/') === false) {
|
||||
// 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";
|
||||
} else {
|
||||
// page path, can pass through
|
||||
@@ -406,13 +409,22 @@ class PagesType extends Wire implements \IteratorAggregate, \Countable {
|
||||
} else {
|
||||
// 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(
|
||||
'caller' => $caller,
|
||||
'loadOptions' => $options
|
||||
));
|
||||
if($page->id && !$this->isValid($page)) $page = $this->wire('pages')->newNullPage();
|
||||
if($page->id) $this->loaded($page);
|
||||
if($page->id) {
|
||||
if($this->isValid($page)) {
|
||||
$this->loaded($page);
|
||||
} else {
|
||||
$pages->uncache($page);
|
||||
$page = $pages->newNullPage();
|
||||
}
|
||||
}
|
||||
|
||||
return $page;
|
||||
}
|
||||
|
Reference in New Issue
Block a user