1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-09 08:17:12 +02:00

Add support to Pages/PagesLoader for populating directly to existing PageArray

This commit is contained in:
Ryan Cramer
2017-09-08 10:07:25 -04:00
parent d427b7f563
commit cc34ec8752
3 changed files with 11 additions and 2 deletions

View File

@@ -645,6 +645,7 @@ class Pages extends Wire {
* - `findTemplates` (boolean): Determine which templates will be used (when no template specified) for more specific autojoins. (default=true)
* - `pageClass` (string): Class to instantiate Page objects with. Leave blank to determine from template. (default=auto-detect)
* - `pageArrayClass` (string): PageArray-derived class to store pages in (when 'getOne' is false). (default=PageArray)
* - `pageArray` (PageArray|null): Populate this existing PageArray rather than creating a new one. (default=null)
* - `page` (Page|null): Existing Page object to populate (also requires the getOne option to be true). (default=null)
*
* **Use the `$options` array for potential speed optimizations:**
@@ -1196,11 +1197,17 @@ class Pages extends Wire {
*
* #pw-internal
*
* @param array $options Optionally specify array('pageArrayClass' => 'YourPageArrayClass')
* @param array $options Optionally specify ONE of the following:
* - `pageArrayClass` (string): Name of PageArray class to use (if not “PageArray”).
* - `pageArray` (PageArray): Wire and return this given PageArray, rather than instantiating a new one.
* @return PageArray
*
*/
public function newPageArray(array $options = array()) {
if(!empty($options['pageArray']) && $options['pageArray'] instanceof PageArray) {
$this->wire($options['pageArray']);
return $options['pageArray'];
}
$class = 'PageArray';
if(!empty($options['pageArrayClass'])) $class = $options['pageArrayClass'];
$class = wireClassName($class, true);

View File

@@ -446,6 +446,7 @@ class PagesLoader extends Wire {
* - findTemplates: boolean, default=true. Determine which templates will be used (when no template specified) for more specific autojoins.
* - pageClass: string, default=auto-detect. Class to instantiate Page objects with. Leave blank to determine from template.
* - pageArrayClass: string, default=PageArray. PageArray-derived class to store pages in (when 'getOne' is false).
* - pageArray: PageArray, default=null. Optional predefined PageArray to populate to.
* - page (Page|null): Existing Page object to populate (also requires the getOne option to be true). (default=null)
* - caller (string): Name of calling function, for debugging purposes (default=blank).
*
@@ -483,6 +484,7 @@ class PagesLoader extends Wire {
'joinFields' => array(),
'page' => null,
'pageClass' => '', // blank = auto detect
'pageArray' => null, // PageArray to populate to
'pageArrayClass' => 'PageArray',
'caller' => '',
);

View File

@@ -189,7 +189,7 @@ class PagesLoaderCache extends Wire {
* @param string $selector
* @param array $options
* @param bool $returnSelector default false
* @return array|null|string
* @return array|null|string|PageArray
*
*/
public function getSelectorCache($selector, $options, $returnSelector = false) {