1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-26 16:14:35 +02:00

Update $pages->newPage() method to support option of accepting array of fields/properties to set when creating the page object

This commit is contained in:
Ryan Cramer
2018-04-27 11:21:13 -04:00
parent b0abd3b9de
commit cfed957df2

View File

@@ -1224,6 +1224,7 @@ class Pages extends Wire {
* @param array $options Optionally specify array of any of the following:
* - `pageClass` (string): Class to use for Page object (default='Page').
* - `template` (Template|id|string): Template to use.
* - Plus any other Page properties or fields you want to set at this time
* @return Page
*
*/
@@ -1242,9 +1243,16 @@ class Pages extends Wire {
} else {
$template = null;
}
$class = wireClassName($class, true);
$page = $this->wire(new $class($template));
if(!$page instanceof Page) $page = $this->wire(new Page($template));
unset($options['pageClass'], $options['template']);
foreach($options as $name => $value) {
$page->set($name, $value);
}
return $page;
}