mirror of
https://github.com/processwire/processwire.git
synced 2025-08-11 09:14:58 +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) {
|
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
|
||||||
@@ -407,12 +410,21 @@ class PagesType extends Wire implements \IteratorAggregate, \Countable {
|
|||||||
// selector string with operators, can pass through
|
// selector string with operators, can pass through
|
||||||
}
|
}
|
||||||
|
|
||||||
$page = $this->pages->get($this->selectorString($selectorString), array(
|
if($page === null) {
|
||||||
|
$page = $pages->get($this->selectorString($selectorString), array(
|
||||||
'caller' => $caller,
|
'caller' => $caller,
|
||||||
'loadOptions' => $options
|
'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;
|
return $page;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user