1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-13 18:24:57 +02:00

Update PageArray setSelectors() and getSelectors() methods to support setting/getting as string as an alternate to previously only allowing a Selectors-instance

This commit is contained in:
Ryan Cramer
2019-09-24 11:42:08 -04:00
parent a2fb255de0
commit aae7302283
2 changed files with 14 additions and 8 deletions

View File

@@ -36,7 +36,7 @@ class PageArray extends PaginatedArray implements WirePaginatable {
/**
* Reference to the selectors that led to this PageArray, if applicable
*
* @var Selectors
* @var Selectors|string
*
*/
protected $selectors = null;
@@ -420,12 +420,14 @@ class PageArray extends PaginatedArray implements WirePaginatable {
*
* #pw-internal
*
* @param Selectors $selectors
* @param Selectors|string $selectors Option to add as string added in 3.0.142
* @return $this
*
*/
public function setSelectors(Selectors $selectors) {
$this->selectors = $selectors;
public function setSelectors($selectors) {
if(is_string($selectors) || $selectors instanceof Selectors || $selectors === null) {
$this->selectors = $selectors;
}
return $this;
}
@@ -440,11 +442,15 @@ class PageArray extends PaginatedArray implements WirePaginatable {
* echo $products->getSelectors(); // outputs the selector above
* ~~~~~
*
* @return Selectors|null Returns Selectors object if available, or null if not.
* @param bool $getString Specify true to get selector string rather than Selectors object (default=false) added in 3.0.142
* @return Selectors|string|null Returns Selectors object if available, or null if not. Always return string if $getString argument is true.
*
*/
public function getSelectors() {
return $this->selectors;
public function getSelectors($getString = false) {
if($getString) return (string) $this->selectors;
if($this->selectors === null) return null;
if(is_string($this->selectors)) $this->selectors = $this->wire(new Selectors($this->selectors));
return $this->selectors;
}
/**

View File

@@ -315,7 +315,7 @@ class Selectors extends WireArray {
}
/**
* Is the give string a Selector string?
* Is the given string a Selector string?
*
* #pw-group-static-helpers
*