1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-19 04:51:22 +02:00

Refactoring of core Template class to improve, optimize and simplify it, plus add new dedicated methods for childTemplates(), parentTemplates(), and allowNewPages().

This commit is contained in:
Ryan Cramer
2020-03-20 14:13:33 -04:00
parent 00b89f71b3
commit 542e138e42
2 changed files with 354 additions and 145 deletions

View File

@@ -23,12 +23,16 @@ class Templates extends WireSaveableItems {
/**
* Reference to all the Fieldgroups
*
* @var Fieldgroups
*
*/
protected $fieldgroups = null;
/**
* WireArray of all Template instances
*
* @var TemplatesArray
*
*/
protected $templatesArray;
@@ -82,6 +86,30 @@ class Templates extends WireSaveableItems {
return $this->templatesArray;
}
/**
* Make an item and populate with given data
*
* #pw-internal
*
* @param array $a Associative array of data to populate
* @return Saveable|Wire
* @since 3.0.146
*
*/
public function makeItem(array $a = array()) {
/** @var Template $item */
$template = $this->wire(new Template());
$template->loaded(false);
foreach($a as $key => $value) {
$template->set($key, $value);
}
$template->loaded(true);
$template->resetTrackChanges(true);
return $template;
}
/**
* Return a new blank item
*