mirror of
https://github.com/processwire/processwire.git
synced 2025-08-12 01:34:31 +02:00
Update for multi-instance to cover the case where someone might do something like new User()
(or Permission, Role, Language) and have its template instance be from the wrong ProcessWire instance. This ensures that gets corrected as soon as the new object is wired to the instance. But we also have to account for the case where they never end up wiring the object for whatever reason, which is why there is some redundant code between construct() and wired()
This commit is contained in:
@@ -52,8 +52,19 @@ class Permission extends Page {
|
||||
*/
|
||||
public function __construct(Template $tpl = null) {
|
||||
parent::__construct($tpl);
|
||||
if(is_null($tpl)) $this->template = $this->wire('templates')->get('permission');
|
||||
$this->parent = $this->wire('pages')->get($this->wire('config')->permissionsPageID);
|
||||
if(!$tpl) $this->template = $this->wire()->templates->get('permission');
|
||||
$this->_parent_id = $this->wire()->config->permissionsPageID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wired to API
|
||||
*
|
||||
*/
|
||||
public function wired() {
|
||||
parent::wired();
|
||||
$template = $this->wire()->templates->get('permission');
|
||||
if($template !== $this->template && (!$this->template || $this->template->name === 'permission')) $this->template = $template;
|
||||
$this->_parent_id = $this->wire()->config->permissionsPageID;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -30,8 +30,16 @@ class Role extends Page {
|
||||
*/
|
||||
public function __construct(Template $tpl = null) {
|
||||
parent::__construct($tpl);
|
||||
if(is_null($tpl)) $this->template = $this->getPredefinedTemplate();
|
||||
$this->parent = $this->getPredefinedParent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Wired to API
|
||||
*
|
||||
*/
|
||||
public function wired() {
|
||||
parent::wired();
|
||||
if(!$this->template) $this->template = $this->getPredefinedTemplate();
|
||||
if(!$this->_parent) $this->setParent($this->getPredefinedParent());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -45,11 +45,22 @@ class User extends Page {
|
||||
*
|
||||
*/
|
||||
public function __construct(Template $tpl = null) {
|
||||
if(!$tpl) $this->template = $this->wire()->templates->get('user');
|
||||
$this->_parent_id = $this->wire()->config->usersPageID;
|
||||
parent::__construct($tpl);
|
||||
if(is_null($tpl)) {
|
||||
$this->template = $this->wire('templates')->get('user');
|
||||
}
|
||||
if(!$this->parent_id) $this->set('parent_id', $this->wire('config')->usersPageID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wired to API
|
||||
*
|
||||
* @throws WireException
|
||||
*
|
||||
*/
|
||||
public function wired() {
|
||||
parent::wired();
|
||||
$template = $this->wire()->templates->get('user');
|
||||
if($template !== $this->template && (!$this->template || $this->template->name === 'user')) $this->template = $template;
|
||||
$this->_parent_id = $this->wire()->config->usersPageID;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -30,9 +30,17 @@ class Language extends Page {
|
||||
*/
|
||||
public function __construct(Template $tpl = null) {
|
||||
parent::__construct($tpl);
|
||||
if(is_null($tpl)) {
|
||||
$this->template = $this->wire('templates')->get('language');
|
||||
}
|
||||
if(!$tpl) $this->template = $this->wire()->templates->get('language');
|
||||
}
|
||||
|
||||
/**
|
||||
* Wired to API
|
||||
*
|
||||
*/
|
||||
public function wired() {
|
||||
parent::wired();
|
||||
$template = $this->wire()->templates->get('language');
|
||||
if($template !== $this->template && (!$this->template || $this->template->name === 'language')) $this->template = $template;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user