mirror of
https://github.com/processwire/processwire.git
synced 2025-08-09 16:26:59 +02:00
Various minor code improvements to several core classes primarily aimed at improved IDE inspection and debugging
This commit is contained in:
@@ -528,11 +528,12 @@ class Field extends WireData implements Saveable, Exportable {
|
||||
|
||||
// convert access roles from IDs to names
|
||||
if($this->useRoles) {
|
||||
$roles = $this->wire()->roles;
|
||||
foreach(array('viewRoles', 'editRoles') as $roleType) {
|
||||
if(!is_array($data[$roleType])) $data[$roleType] = array();
|
||||
$roleNames = array();
|
||||
foreach($data[$roleType] as $key => $roleID) {
|
||||
$role = $this->wire('roles')->get($roleID);
|
||||
$role = $roles->get($roleID);
|
||||
if(!$role || !$role->id) continue;
|
||||
$roleNames[] = $role->name;
|
||||
}
|
||||
@@ -586,12 +587,12 @@ class Field extends WireData implements Saveable, Exportable {
|
||||
|
||||
// prep data for actual import
|
||||
if(!empty($data['type']) && ((string) $this->type) != $data['type']) {
|
||||
$this->type = $this->wire('fieldtypes')->get($data['type']);
|
||||
$this->type = $this->wire()->fieldtypes->get($data['type']);
|
||||
}
|
||||
|
||||
if(!$this->type) {
|
||||
if(!empty($data['type'])) $this->error("Unable to locate field type: $data[type]");
|
||||
$this->type = $this->wire('fieldtypes')->get('FieldtypeText');
|
||||
$this->type = $this->wire()->fieldtypes->get('FieldtypeText');
|
||||
}
|
||||
|
||||
$data = $this->type->importConfigData($this, $data);
|
||||
@@ -810,7 +811,7 @@ class Field extends WireData implements Saveable, Exportable {
|
||||
} else if($role instanceof Role) {
|
||||
$ids[] = (int) $role->id;
|
||||
} else if(is_string($role) && strlen($role)) {
|
||||
$rolePage = $this->wire('roles')->get($role);
|
||||
$rolePage = $this->wire()->roles->get($role);
|
||||
if($rolePage && $rolePage->id) {
|
||||
$ids[] = $rolePage->id;
|
||||
} else {
|
||||
@@ -1139,7 +1140,7 @@ class Field extends WireData implements Saveable, Exportable {
|
||||
}
|
||||
|
||||
$inputfields = $this->wire(new InputfieldWrapper());
|
||||
$dummyPage = $this->wire('pages')->get("/"); // only using this to satisfy param requirement
|
||||
$dummyPage = $this->wire()->pages->get('/'); // only using this to satisfy param requirement
|
||||
|
||||
$inputfield = $this->getInputfield($dummyPage);
|
||||
if($inputfield) {
|
||||
@@ -1232,6 +1233,13 @@ class Field extends WireData implements Saveable, Exportable {
|
||||
return $this->settings['name'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Isset
|
||||
*
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*
|
||||
*/
|
||||
public function __isset($key) {
|
||||
if(parent::__isset($key)) return true;
|
||||
return isset($this->settings[$key]);
|
||||
@@ -1268,8 +1276,9 @@ class Field extends WireData implements Saveable, Exportable {
|
||||
*
|
||||
*/
|
||||
protected function setText($property, $value, $language = null) {
|
||||
if($this->wire('languages') && $language != null) {
|
||||
if(is_string($language) || is_int($language)) $language = $this->wire('languages')->get($language);
|
||||
$languages = $this->wire()->languages;
|
||||
if($languages && $language != null) {
|
||||
if(is_string($language) || is_int($language)) $language = $languages->get($language);
|
||||
if($language && (!$language->id || $language->isDefault())) $language = null;
|
||||
} else {
|
||||
$language = null;
|
||||
|
@@ -172,6 +172,8 @@ class Fields extends WireSaveableItems {
|
||||
*
|
||||
* #pw-internal
|
||||
*
|
||||
* @return Field
|
||||
*
|
||||
*/
|
||||
public function makeBlankItem() {
|
||||
return $this->wire(new Field());
|
||||
@@ -320,7 +322,7 @@ class Fields extends WireSaveableItems {
|
||||
if($item->flags & Field::flagFieldgroupContext) throw new WireException("Field $item is not saveable because it is in a specific context");
|
||||
if(!strlen($item->name)) throw new WireException("Field name is required");
|
||||
|
||||
$database = $this->wire('database');
|
||||
$database = $this->wire()->database;
|
||||
$isNew = $item->id < 1;
|
||||
$prevTable = $database->escapeTable($item->prevTable);
|
||||
$table = $database->escapeTable($item->getTable());
|
||||
@@ -356,13 +358,13 @@ class Fields extends WireSaveableItems {
|
||||
|
||||
if($item->flags & Field::flagGlobal) {
|
||||
// make sure that all template fieldgroups contain this field and add to any that don't.
|
||||
foreach($this->wire('templates') as $template) {
|
||||
foreach($this->wire()->templates as $template) {
|
||||
if($template->noGlobal) continue;
|
||||
$fieldgroup = $template->fieldgroup;
|
||||
if(!$fieldgroup->hasField($item)) {
|
||||
$fieldgroup->add($item);
|
||||
$fieldgroup->save();
|
||||
if($this->wire('config')->debug) $this->message("Added field '{$item->name}' to template/fieldgroup '{$fieldgroup->name}'");
|
||||
$this->message("Added field '{$item->name}' to template/fieldgroup '$fieldgroup->name'", Notice::debug);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -381,8 +383,7 @@ class Fields extends WireSaveableItems {
|
||||
*
|
||||
*/
|
||||
protected function checkFieldTable(Field $field) {
|
||||
// if(!$this->wire('config')->debug) return;
|
||||
$database = $this->wire('database');
|
||||
$database = $this->wire()->database;
|
||||
$table = $database->escapeTable($field->getTable());
|
||||
if(empty($table)) return;
|
||||
$exists = $database->query("SHOW TABLES LIKE '$table'")->rowCount() > 0;
|
||||
@@ -477,6 +478,7 @@ class Fields extends WireSaveableItems {
|
||||
/** @var Field $item */
|
||||
$item = parent::___clone($item, $name);
|
||||
if($item) $item->prevTable = null;
|
||||
|
||||
return $item;
|
||||
}
|
||||
|
||||
@@ -499,8 +501,13 @@ class Fields extends WireSaveableItems {
|
||||
$data = array();
|
||||
|
||||
// make sure given field and fieldgroup are valid
|
||||
if(!($field->flags & Field::flagFieldgroupContext)) throw new WireException("Field must be in fieldgroup context before its context can be saved");
|
||||
if(!$fieldgroup->has($fieldOriginal)) throw new WireException("Fieldgroup $fieldgroup does not contain field $field");
|
||||
if(!($field->flags & Field::flagFieldgroupContext)) {
|
||||
throw new WireException("Field must be in fieldgroup context before its context can be saved");
|
||||
}
|
||||
|
||||
if(!$fieldgroup->has($fieldOriginal)) {
|
||||
throw new WireException("Fieldgroup $fieldgroup does not contain field $field");
|
||||
}
|
||||
|
||||
$field_id = (int) $field->id;
|
||||
$fieldgroup_id = (int) $fieldgroup->id;
|
||||
@@ -609,7 +616,9 @@ class Fields extends WireSaveableItems {
|
||||
*/
|
||||
protected function ___changeFieldtype(Field $field1, $keepSettings = false) {
|
||||
|
||||
if(!$field1->prevFieldtype) throw new WireException("changeFieldType requires that the given field has had a type change");
|
||||
if(!$field1->prevFieldtype) {
|
||||
throw new WireException("changeFieldType requires that the given field has had a type change");
|
||||
}
|
||||
|
||||
if( ($field1->type instanceof FieldtypeMulti && !$field1->prevFieldtype instanceof FieldtypeMulti) ||
|
||||
($field1->prevFieldtype instanceof FieldtypeMulti && !$field1->type instanceof FieldtypeMulti)) {
|
||||
@@ -634,7 +643,7 @@ class Fields extends WireSaveableItems {
|
||||
$schema1 = array();
|
||||
$schema2 = array();
|
||||
|
||||
$database = $this->wire('database');
|
||||
$database = $this->wire()->database;
|
||||
$table1 = $database->escapeTable($field1->table);
|
||||
$table2 = $database->escapeTable($field2->table);
|
||||
|
||||
@@ -650,7 +659,7 @@ class Fields extends WireSaveableItems {
|
||||
|
||||
foreach($schema1 as $key => $value) {
|
||||
if(!in_array($value, $schema2)) {
|
||||
if($this->wire('config')->debug) $this->message("changeFieldType loses table field '$value'");
|
||||
$this->message("changeFieldType loses table field '$value'", Notice::debug);
|
||||
unset($schema1[$key]);
|
||||
}
|
||||
}
|
||||
@@ -851,7 +860,7 @@ class Fields extends WireSaveableItems {
|
||||
if(!$field->type) return 0;
|
||||
|
||||
$options = array_merge($defaults, $options);
|
||||
$database = $this->wire('database');
|
||||
$database = $this->wire()->database;
|
||||
$table = $database->escapeTable($field->getTable());
|
||||
$useRowCount = false;
|
||||
$schema = $field->type->getDatabaseSchema($field);
|
||||
@@ -868,7 +877,7 @@ class Fields extends WireSaveableItems {
|
||||
if($options['template'] instanceof Template) {
|
||||
$template = $options['template'];
|
||||
} else {
|
||||
$template = $this->wire('templates')->get($options['template']);
|
||||
$template = $this->wire()->templates->get($options['template']);
|
||||
}
|
||||
|
||||
if(!$template) throw new WireException("Unknown template: $options[template]");
|
||||
@@ -895,7 +904,7 @@ class Fields extends WireSaveableItems {
|
||||
if(is_int($options['page'])) {
|
||||
$pageID = $options['page'];
|
||||
} else {
|
||||
$page = $this->wire('pages')->get($options['page']);
|
||||
$page = $this->wire()->pages->get($options['page']);
|
||||
$pageID = $page->id;
|
||||
}
|
||||
|
||||
@@ -960,8 +969,7 @@ class Fields extends WireSaveableItems {
|
||||
*
|
||||
*/
|
||||
public static function isNativeName($name) {
|
||||
/** @var Fields $fields */
|
||||
$fields = wire('fields');
|
||||
$fields = wire()->fields;
|
||||
return $fields->isNative($name);
|
||||
}
|
||||
|
||||
@@ -1217,8 +1225,10 @@ class Fields extends WireSaveableItems {
|
||||
*
|
||||
*/
|
||||
public function _hasPermission(Field $field, $permission, Page $page = null, User $user = null) {
|
||||
if($permission != 'edit' && $permission != 'view') throw new WireException('Specify either "edit" or "view"');
|
||||
if(is_null($user)) $user = $this->wire('user');
|
||||
if($permission != 'edit' && $permission != 'view') {
|
||||
throw new WireException('Specify either "edit" or "view"');
|
||||
}
|
||||
if(is_null($user)) $user = $this->wire()->user;
|
||||
if($user->isSuperuser()) return true;
|
||||
if($page && $page->template && $page->template->fieldgroup->hasField($field)) {
|
||||
// make sure we have a copy of $field that is in the context of $page
|
||||
@@ -1229,7 +1239,7 @@ class Fields extends WireSaveableItems {
|
||||
// field is access controlled
|
||||
$has = false;
|
||||
$roles = $permission == 'edit' ? $field->editRoles : $field->viewRoles;
|
||||
if($permission == 'view' && in_array($this->wire('config')->guestUserRolePageID, $roles)) {
|
||||
if($permission == 'view' && in_array($this->wire()->config->guestUserRolePageID, $roles)) {
|
||||
// if guest has view permission, then all have view permission
|
||||
$has = true;
|
||||
} else {
|
||||
|
@@ -105,9 +105,9 @@ class Fieldtypes extends WireArray {
|
||||
*/
|
||||
protected function preload() {
|
||||
if($this->preloaded) return;
|
||||
$debug = $this->isAPI && $this->wire('config')->debug;
|
||||
$debug = $this->isAPI && $this->wire()->config->debug;
|
||||
if($debug) Debug::timer('Fieldtypes.preload');
|
||||
$modules = $this->wire('modules'); /** @var Modules $modules */
|
||||
$modules = $this->wire()->modules;
|
||||
foreach($this->data as $moduleName => $module) {
|
||||
if($module instanceof ModulePlaceholder) {
|
||||
$fieldtype = $modules->getModule($moduleName);
|
||||
|
@@ -359,7 +359,7 @@ function wireLangTranslations(array $values = array()) {
|
||||
*
|
||||
* This option enables you to replace text sent to translation calls
|
||||
* like `__('text')` with your own replacement text. This is similar
|
||||
* to the `wireTranslateValues()` function except that it applies
|
||||
* to the `wireLangTranslations()` function except that it applies
|
||||
* regardless of whether or not a translation is available for the
|
||||
* phrase. It overrides rather than serves as a fallback.
|
||||
*
|
||||
|
@@ -212,6 +212,7 @@ class Selectors extends WireArray {
|
||||
$not = true;
|
||||
} else {
|
||||
if(is_array($value)) $value = implode('|', $value);
|
||||
if(is_array($field)) $field = implode('|', $field);
|
||||
$debug = $this->wire('config')->debug ? "field='$field', value='$value', selector: '$this->selectorStr'" : "";
|
||||
if(empty($operator)) $operator = '[empty]';
|
||||
throw new WireException("Unknown Selector operator: '$operator' -- was your selector value properly escaped? $debug");
|
||||
|
@@ -7,7 +7,7 @@
|
||||
* #pw-body Template objects also maintain several properties which can affect the render behavior of pages using it.
|
||||
* #pw-order-groups identification,manipulation,family,URLs,access,files,cache,page-editor,behaviors,other
|
||||
*
|
||||
* ProcessWire 3.x, Copyright 2019 by Ryan Cramer
|
||||
* ProcessWire 3.x, Copyright 2022 by Ryan Cramer
|
||||
* https://processwire.com
|
||||
*
|
||||
* @todo add multi-language option for redirectLogin setting
|
||||
@@ -369,22 +369,22 @@ class Template extends WireData implements Saveable, Exportable {
|
||||
if($name !== 'view') {
|
||||
if(empty($name)) throw new WireException("Unknown roles type: $type");
|
||||
$roleIDs = $this->$propertyName;
|
||||
if(empty($roleIDs)) return $this->wire('pages')->newPageArray();
|
||||
return $this->wire('pages')->getById($roleIDs);
|
||||
if(empty($roleIDs)) return $this->wire()->pages->newPageArray();
|
||||
return $this->wire()->pages->getById($roleIDs);
|
||||
}
|
||||
}
|
||||
|
||||
// type=view assumed from this point forward
|
||||
|
||||
if(is_null($this->_roles)) {
|
||||
return $this->wire('pages')->newPageArray();
|
||||
return $this->wire()->pages->newPageArray();
|
||||
|
||||
} else if($this->_roles instanceof PageArray) {
|
||||
return $this->_roles;
|
||||
|
||||
} else if(is_array($this->_roles)) {
|
||||
$errors = array();
|
||||
$roles = $this->wire('pages')->newPageArray();
|
||||
$roles = $this->wire()->pages->newPageArray();
|
||||
if(count($this->_roles)) {
|
||||
$test = implode('0', $this->_roles); // test to see if it's all digits (IDs)
|
||||
if(ctype_digit("$test")) {
|
||||
@@ -392,7 +392,7 @@ class Template extends WireData implements Saveable, Exportable {
|
||||
} else {
|
||||
// role names
|
||||
foreach($this->_roles as $name) {
|
||||
$role = $this->wire('roles')->get($name);
|
||||
$role = $this->wire()->roles->get($name);
|
||||
if($role->id) {
|
||||
$roles->add($role);
|
||||
} else {
|
||||
@@ -405,7 +405,7 @@ class Template extends WireData implements Saveable, Exportable {
|
||||
$this->_roles = $roles;
|
||||
return $this->_roles;
|
||||
} else {
|
||||
return $this->wire('pages')->newPageArray();
|
||||
return $this->wire()->pages->newPageArray();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -440,7 +440,7 @@ class Template extends WireData implements Saveable, Exportable {
|
||||
}
|
||||
if($type === 'view') return $has;
|
||||
if(!$has) return false; // page-view is a pre-requisite
|
||||
if(!$rolePage || !$rolePage->id) $rolePage = $this->wire('roles')->get($role);
|
||||
if(!$rolePage || !$rolePage->id) $rolePage = $this->wire()->roles->get($role);
|
||||
if(!$rolePage->id) return false;
|
||||
$has = $property ? in_array($rolePage->id, $this->$property) : false;
|
||||
return $has;
|
||||
@@ -490,7 +490,7 @@ class Template extends WireData implements Saveable, Exportable {
|
||||
if(ctype_digit($v)) {
|
||||
$id = (int) $v;
|
||||
} else {
|
||||
if($roles === null) $roles = $this->wire('roles');
|
||||
if($roles === null) $roles = $this->wire()->roles;
|
||||
$id = $roles ? (int) $roles->get($v)->id : 0;
|
||||
if(!$id && $this->_importMode && $this->useRoles) {
|
||||
$this->error("Unable to load role '$v' for '$this.$type'");
|
||||
@@ -523,7 +523,7 @@ class Template extends WireData implements Saveable, Exportable {
|
||||
|
||||
if(!ctype_digit("$roleID")) {
|
||||
// convert role name to ID
|
||||
$roleID = $this->wire('roles')->get("name=$roleID")->id;
|
||||
$roleID = $this->wire()->roles->get("name=$roleID")->id;
|
||||
}
|
||||
|
||||
if(!$roleID) continue;
|
||||
@@ -534,7 +534,7 @@ class Template extends WireData implements Saveable, Exportable {
|
||||
if(!ctype_digit($test)) {
|
||||
// convert permission name to ID
|
||||
$revoke = strpos($permissionID, '-') === 0;
|
||||
$permissionID = $this->wire('permissions')->get("name=$test")->id;
|
||||
$permissionID = $this->wire()->permissions->get("name=$test")->id;
|
||||
if(!$permissionID) continue;
|
||||
if($revoke) $permissionID = "-$permissionID";
|
||||
}
|
||||
@@ -561,7 +561,7 @@ class Template extends WireData implements Saveable, Exportable {
|
||||
*
|
||||
*/
|
||||
public function addRole($role, $type = 'view') {
|
||||
if(is_int($role) || is_string($role)) $role = $this->wire('roles')->get($role);
|
||||
if(is_int($role) || is_string($role)) $role = $this->wire()->roles->get($role);
|
||||
if(!$role instanceof Role) throw new WireException("addRole requires Role instance, name or id");
|
||||
$roles = $this->getRoles($type);
|
||||
if(!$roles->has($role)) {
|
||||
@@ -584,7 +584,7 @@ class Template extends WireData implements Saveable, Exportable {
|
||||
public function removeRole($role, $type = 'view') {
|
||||
|
||||
if(is_int($role) || is_string($role)) {
|
||||
$role = $this->wire('roles')->get($role);
|
||||
$role = $this->wire()->roles->get($role);
|
||||
}
|
||||
|
||||
if(!$role instanceof Role) {
|
||||
@@ -625,7 +625,7 @@ class Template extends WireData implements Saveable, Exportable {
|
||||
*
|
||||
*/
|
||||
public function addPermissionByRole($permission, $role, $test = false) {
|
||||
return $this->wire('templates')->setTemplatePermissionByRole($this, $permission, $role, false, $test);
|
||||
return $this->wire()->templates->setTemplatePermissionByRole($this, $permission, $role, false, $test);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -640,7 +640,7 @@ class Template extends WireData implements Saveable, Exportable {
|
||||
*
|
||||
*/
|
||||
public function revokePermissionByRole($permission, $role, $test = false) {
|
||||
return $this->wire('templates')->setTemplatePermissionByRole($this, $permission, $role, true, $test);
|
||||
return $this->wire()->templates->setTemplatePermissionByRole($this, $permission, $role, true, $test);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -693,7 +693,7 @@ class Template extends WireData implements Saveable, Exportable {
|
||||
}
|
||||
|
||||
} else if($key == 'sortfield') {
|
||||
$value = $this->wire('pages')->sortfields()->decode($value, '');
|
||||
$value = $this->wire()->pages->sortfields()->decode($value, '');
|
||||
parent::set($key, $value);
|
||||
|
||||
} else if($key === 'roles' || $key === 'addRoles' || $key === 'editRoles' || $key === 'createRoles') {
|
||||
@@ -814,7 +814,7 @@ class Template extends WireData implements Saveable, Exportable {
|
||||
if(is_object($v)) {
|
||||
$v = $v->id;
|
||||
} else if(!ctype_digit("$v")) {
|
||||
$p = $this->wire('pages')->get($v);
|
||||
$p = $this->wire()->pages->get($v);
|
||||
if(!$p->id) $this->error("Unable to load page: $v");
|
||||
$v = $p->id;
|
||||
}
|
||||
@@ -992,7 +992,7 @@ class Template extends WireData implements Saveable, Exportable {
|
||||
*
|
||||
*/
|
||||
public function getNumPages() {
|
||||
return $this->wire('templates')->getNumPages($this);
|
||||
return $this->wire()->templates->getNumPages($this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1007,7 +1007,7 @@ class Template extends WireData implements Saveable, Exportable {
|
||||
*/
|
||||
public function save() {
|
||||
|
||||
$result = $this->wire('templates')->save($this);
|
||||
$result = $this->wire()->templates->save($this);
|
||||
|
||||
return $result ? $this : false;
|
||||
}
|
||||
@@ -1024,8 +1024,7 @@ class Template extends WireData implements Saveable, Exportable {
|
||||
*/
|
||||
public function filename($filename = null) {
|
||||
|
||||
/** @var Config $config */
|
||||
$config = $this->wire('config');
|
||||
$config = $this->wire()->config;
|
||||
$path = $config->paths->templates;
|
||||
|
||||
if($filename !== null) {
|
||||
@@ -1074,10 +1073,8 @@ class Template extends WireData implements Saveable, Exportable {
|
||||
}
|
||||
if($isModified || !$this->ns) {
|
||||
// determine namespace
|
||||
$files = $this->wire('files');
|
||||
/** @var WireFileTools $files */
|
||||
$templates = $this->wire('templates');
|
||||
/** @var Templates $templates */
|
||||
$files = $this->wire()->files;
|
||||
$templates = $this->wire()->templates;
|
||||
$this->ns = $files->getNamespace($filename);
|
||||
$templates->fileModified($this);
|
||||
}
|
||||
@@ -1096,7 +1093,7 @@ class Template extends WireData implements Saveable, Exportable {
|
||||
*
|
||||
*/
|
||||
public function hookFinished(HookEvent $e) {
|
||||
foreach($e->wire('templates') as $template) {
|
||||
foreach($e->wire()->templates as $template) {
|
||||
if($template->isChanged('modified') || $template->isChanged('ns')) $template->save();
|
||||
}
|
||||
}
|
||||
@@ -1149,7 +1146,9 @@ class Template extends WireData implements Saveable, Exportable {
|
||||
$tableData = $this->settings;
|
||||
$data = $this->getArray();
|
||||
// ensure sortfield is a signed integer or native name, rather than a custom fieldname
|
||||
if(!empty($data['sortfield'])) $data['sortfield'] = $this->wire('pages')->sortfields()->encode($data['sortfield'], '');
|
||||
if(!empty($data['sortfield'])) {
|
||||
$data['sortfield'] = $this->wire()->pages->sortfields()->encode($data['sortfield'], '');
|
||||
}
|
||||
$tableData['data'] = $data;
|
||||
|
||||
return $tableData;
|
||||
@@ -1162,7 +1161,7 @@ class Template extends WireData implements Saveable, Exportable {
|
||||
*
|
||||
*/
|
||||
public function getExportData() {
|
||||
return $this->wire('templates')->getExportData($this);
|
||||
return $this->wire()->templates->getExportData($this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1181,7 +1180,7 @@ class Template extends WireData implements Saveable, Exportable {
|
||||
*
|
||||
*/
|
||||
public function setImportData(array $data) {
|
||||
return $this->wire('templates')->setImportData($this, $data);
|
||||
return $this->wire()->templates->setImportData($this, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1241,9 +1240,9 @@ class Template extends WireData implements Saveable, Exportable {
|
||||
*/
|
||||
protected function familyTemplates($property, $setValue = null) {
|
||||
|
||||
/** @var Templates $templates */
|
||||
$templates = $this->wire('templates');
|
||||
$templates = $this->wire()->templates;
|
||||
$value = new TemplatesArray();
|
||||
$this->wire($value);
|
||||
|
||||
if($setValue !== null && WireArray::iterable($setValue)) {
|
||||
// set
|
||||
@@ -1279,7 +1278,7 @@ class Template extends WireData implements Saveable, Exportable {
|
||||
*
|
||||
*/
|
||||
public function allowNewPages() {
|
||||
$pages = $this->wire('pages'); /** @var Pages $pages */
|
||||
$pages = $this->wire()->pages;
|
||||
$noParents = (int) $this->noParents;
|
||||
if($noParents === 1) {
|
||||
// no new pages may be created
|
||||
@@ -1307,7 +1306,7 @@ class Template extends WireData implements Saveable, Exportable {
|
||||
*
|
||||
*/
|
||||
public function getParentPage($checkAccess = false) {
|
||||
return $this->wire('templates')->getParentPage($this, $checkAccess);
|
||||
return $this->wire()->templates->getParentPage($this, $checkAccess);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1320,7 +1319,7 @@ class Template extends WireData implements Saveable, Exportable {
|
||||
*
|
||||
*/
|
||||
public function getParentPages($checkAccess = false) {
|
||||
return $this->wire('templates')->getParentPages($this, $checkAccess);
|
||||
return $this->wire()->templates->getParentPages($this, $checkAccess);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1362,7 +1361,7 @@ class Template extends WireData implements Saveable, Exportable {
|
||||
*/
|
||||
public function getTabLabel($tab, $language = null) {
|
||||
$tab = ucfirst(strtolower($tab));
|
||||
if(is_null($language)) $language = $this->wire('languages') ? $this->wire('user')->language : null;
|
||||
if(is_null($language)) $language = $this->wire()->languages ? $this->wire()->user->language : null;
|
||||
if(!$language || $language->isDefault()) $language = '';
|
||||
$label = $this->get("tab$tab$language");
|
||||
return $label;
|
||||
@@ -1378,7 +1377,7 @@ class Template extends WireData implements Saveable, Exportable {
|
||||
*
|
||||
*/
|
||||
public function getNameLabel($language = null) {
|
||||
if(is_null($language)) $language = $this->wire('languages') ? $this->wire('user')->language : null;
|
||||
if(is_null($language)) $language = $this->wire()->languages ? $this->wire()->user->language : null;
|
||||
if(!$language || $language->isDefault()) $language = '';
|
||||
return $this->get("nameLabel$language");
|
||||
}
|
||||
@@ -1413,11 +1412,10 @@ class Template extends WireData implements Saveable, Exportable {
|
||||
*
|
||||
*/
|
||||
public function getLanguages() {
|
||||
/** @var Languages $languages */
|
||||
$languages = $this->wire('languages');
|
||||
$languages = $this->wire()->languages;
|
||||
if(!$languages) return null;
|
||||
if(!$this->noLang) return $languages;
|
||||
$langs = $this->wire('pages')->newPageArray();
|
||||
$langs = $this->wire()->pages->newPageArray();
|
||||
// if noLang set, then only default language is included
|
||||
$langs->add($languages->getDefault());
|
||||
return $langs;
|
||||
@@ -1437,7 +1435,7 @@ class Template extends WireData implements Saveable, Exportable {
|
||||
*
|
||||
*/
|
||||
public function getPageClass($withNamespace = true) {
|
||||
return $this->wire('templates')->getPageClass($this, $withNamespace);
|
||||
return $this->wire()->templates->getPageClass($this, $withNamespace);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1537,7 +1535,7 @@ class Template extends WireData implements Saveable, Exportable {
|
||||
*/
|
||||
public function setIcon($icon) {
|
||||
// This manipulates the pageLabelField property, since there isn't actually an icon property.
|
||||
$icon = $this->wire('sanitizer')->pageName($icon);
|
||||
$icon = $this->wire()->sanitizer->pageName($icon);
|
||||
$current = $this->getIcon(false);
|
||||
$label = $this->pageLabelField;
|
||||
if(strpos($icon, "icon-") === 0) $icon = str_replace("icon-", "fa-", $icon); // convert icon-str to fa-str
|
||||
@@ -1564,8 +1562,9 @@ class Template extends WireData implements Saveable, Exportable {
|
||||
*
|
||||
*/
|
||||
public function ___getConnectedField() {
|
||||
$fields = $this->wire()->fields;
|
||||
if($this->connectedFieldID) {
|
||||
$field = $this->wire('fields')->get((int) $this->connectedFieldID);
|
||||
$field = $fields->get((int) $this->connectedFieldID);
|
||||
} else {
|
||||
$field = null;
|
||||
}
|
||||
@@ -1579,7 +1578,7 @@ class Template extends WireData implements Saveable, Exportable {
|
||||
break;
|
||||
}
|
||||
if($fieldName) {
|
||||
$field = $this->wire('fields')->get($fieldName);
|
||||
$field = $fields->get($fieldName);
|
||||
}
|
||||
}
|
||||
return $field;
|
||||
|
@@ -92,7 +92,7 @@ class Templates extends WireSaveableItems {
|
||||
*
|
||||
* #pw-internal
|
||||
*
|
||||
* @return WireArray
|
||||
* @return WireArray|TemplatesArray
|
||||
* @since 3.0.194
|
||||
*
|
||||
*/
|
||||
@@ -110,7 +110,7 @@ class Templates extends WireSaveableItems {
|
||||
* #pw-internal
|
||||
*
|
||||
* @param array $a Associative array of data to populate
|
||||
* @return Saveable|Wire
|
||||
* @return Saveable|Wire|Template
|
||||
* @since 3.0.146
|
||||
*
|
||||
*/
|
||||
@@ -160,6 +160,8 @@ class Templates extends WireSaveableItems {
|
||||
/**
|
||||
* Return a new blank item
|
||||
*
|
||||
* @return Template
|
||||
*
|
||||
* #pw-internal
|
||||
*
|
||||
*/
|
||||
@@ -322,8 +324,7 @@ class Templates extends WireSaveableItems {
|
||||
$access->updateTemplate($item);
|
||||
}
|
||||
|
||||
/** @var WireCache $cache */
|
||||
$cache = $this->wire('cache');
|
||||
$cache = $this->wire()->cache;
|
||||
$cache->maintenance($item);
|
||||
|
||||
return $result;
|
||||
@@ -338,14 +339,21 @@ class Templates extends WireSaveableItems {
|
||||
*
|
||||
*/
|
||||
public function ___delete(Saveable $item) {
|
||||
if($item->flags & Template::flagSystem) throw new WireException("Can't delete template '{$item->name}' because it is a system template.");
|
||||
|
||||
if($item->flags & Template::flagSystem) {
|
||||
throw new WireException("Can't delete template '{$item->name}' because it is a system template.");
|
||||
}
|
||||
|
||||
$cnt = $item->getNumPages();
|
||||
if($cnt > 0) throw new WireException("Can't delete template '{$item->name}' because it is used by $cnt pages.");
|
||||
|
||||
if($cnt > 0) {
|
||||
throw new WireException("Can't delete template '{$item->name}' because it is used by $cnt pages.");
|
||||
}
|
||||
|
||||
$return = parent::___delete($item);
|
||||
/** @var WireCache $cache */
|
||||
$cache = $this->wire('cache');
|
||||
$cache = $this->wire()->cache;
|
||||
$cache->maintenance($item);
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
@@ -458,7 +466,7 @@ class Templates extends WireSaveableItems {
|
||||
*
|
||||
*/
|
||||
public function getNumPages(Template $tpl) {
|
||||
$database = $this->wire('database');
|
||||
$database = $this->wire()->database;
|
||||
$query = $database->prepare("SELECT COUNT(*) AS total FROM pages WHERE templates_id=:template_id"); // QA
|
||||
$query->bindValue(":template_id", $tpl->id, \PDO::PARAM_INT);
|
||||
$query->execute();
|
||||
@@ -499,7 +507,7 @@ class Templates extends WireSaveableItems {
|
||||
unset($data['data'], $data['modified']);
|
||||
|
||||
// convert fieldgroup to guid
|
||||
$fieldgroup = $this->wire('fieldgroups')->get((int) $data['fieldgroups_id']);
|
||||
$fieldgroup = $this->wire()->fieldgroups->get((int) $data['fieldgroups_id']);
|
||||
if($fieldgroup) $data['fieldgroups_id'] = $fieldgroup->name;
|
||||
|
||||
// convert family settings to guids
|
||||
@@ -520,7 +528,7 @@ class Templates extends WireSaveableItems {
|
||||
if(!isset($data[$key])) continue;
|
||||
$values = array();
|
||||
foreach($data[$key] as $id) {
|
||||
$role = $id instanceof Role ? $id : $this->wire('roles')->get((int) $id);
|
||||
$role = $id instanceof Role ? $id : $this->wire()->roles->get((int) $id);
|
||||
$values[] = $role->name;
|
||||
}
|
||||
$data[$key] = $values;
|
||||
@@ -530,9 +538,10 @@ class Templates extends WireSaveableItems {
|
||||
// convert pages to guids
|
||||
if(((int) $template->cache_time) != 0) {
|
||||
if(!empty($data['cacheExpirePages'])) {
|
||||
$pages = $this->wire()->pages;
|
||||
$values = array();
|
||||
foreach($data['cacheExpirePages'] as $id) {
|
||||
$page = $this->wire('pages')->get((int) $id);
|
||||
$page = $pages->get((int) $id);
|
||||
if(!$page->id) continue;
|
||||
$values[] = $page->path;
|
||||
}
|
||||
@@ -574,6 +583,8 @@ class Templates extends WireSaveableItems {
|
||||
*/
|
||||
public function ___setImportData(Template $template, array $data) {
|
||||
|
||||
$fieldgroups = $this->wire()->fieldgroups;
|
||||
|
||||
$template->set('_importMode', true);
|
||||
$fieldgroupData = array();
|
||||
$changes = array();
|
||||
@@ -585,7 +596,7 @@ class Templates extends WireSaveableItems {
|
||||
|
||||
foreach($data as $key => $value) {
|
||||
if($key == 'fieldgroups_id' && !ctype_digit("$value")) {
|
||||
$fieldgroup = $this->wire('fieldgroups')->get($value);
|
||||
$fieldgroup = $fieldgroups->get($value);
|
||||
if(!$fieldgroup) {
|
||||
$fieldgroup = $this->wire(new Fieldgroup());
|
||||
$fieldgroup->name = $value;
|
||||
@@ -671,8 +682,11 @@ class Templates extends WireSaveableItems {
|
||||
*/
|
||||
public function getParentPage(Template $template, $checkAccess = false, $getAll = false) {
|
||||
|
||||
$pages = $this->wire()->pages;
|
||||
$user = $this->wire()->user;
|
||||
|
||||
$foundParent = null;
|
||||
$foundParents = $getAll ? $this->wire('pages')->newPageArray() : null;
|
||||
$foundParents = $getAll ? $pages->newPageArray() : null;
|
||||
$foundParentQty = 0;
|
||||
$maxStatus = is_int($getAll) && $getAll ? ($getAll * 2) : 0;
|
||||
|
||||
@@ -686,7 +700,7 @@ class Templates extends WireSaveableItems {
|
||||
|
||||
foreach($template->parentTemplates as $parentTemplateID) {
|
||||
|
||||
$parentTemplate = $this->wire('templates')->get((int) $parentTemplateID);
|
||||
$parentTemplate = $this->get((int) $parentTemplateID);
|
||||
if(!$parentTemplate) continue;
|
||||
|
||||
// if the parent template doesn't have this as an allowed child template, exclude it
|
||||
@@ -701,7 +715,7 @@ class Templates extends WireSaveableItems {
|
||||
} else if(!$getAll) {
|
||||
$selector .= ", limit=2";
|
||||
}
|
||||
$parentPages = $this->wire('pages')->find($selector);
|
||||
$parentPages = $pages->find($selector);
|
||||
$numParentPages = count($parentPages);
|
||||
|
||||
// undetermined parent
|
||||
@@ -723,11 +737,11 @@ class Templates extends WireSaveableItems {
|
||||
if($checkAccess) {
|
||||
if($parentPage->id) {
|
||||
// single defined parent
|
||||
$p = $this->wire('pages')->newPage($template);
|
||||
$p = $pages->newPage($template);
|
||||
if(!$parentPage->addable($p)) continue;
|
||||
} else {
|
||||
// multiple possible parents
|
||||
if(!$this->wire('user')->hasPermission('page-create', $template)) continue;
|
||||
if(!$user->hasPermission('page-create', $template)) continue;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -737,14 +751,14 @@ class Templates extends WireSaveableItems {
|
||||
}
|
||||
|
||||
if($checkAccess && $getAll && $foundParents && $foundParents->count()) {
|
||||
$p = $this->wire('pages')->newPage($template);
|
||||
$p = $pages->newPage($template);
|
||||
foreach($foundParents as $parentPage) {
|
||||
if(!$parentPage->addable($p)) $foundParents->remove($parentPage);
|
||||
}
|
||||
}
|
||||
|
||||
if($getAll) return $foundParents;
|
||||
if($foundParentQty > 1) return $this->wire('pages')->newNullPage();
|
||||
if($foundParentQty > 1) return $pages->newNullPage();
|
||||
|
||||
return $foundParent;
|
||||
}
|
||||
@@ -785,6 +799,7 @@ class Templates extends WireSaveableItems {
|
||||
}
|
||||
|
||||
$corePageClass = __NAMESPACE__ . "\\Page";
|
||||
$cacheable = true;
|
||||
|
||||
// first check for class defined with Template 'pageClass' setting
|
||||
$pageClass = $template->pageClass;
|
||||
@@ -802,10 +817,12 @@ class Templates extends WireSaveableItems {
|
||||
} else {
|
||||
// class is not available for instantiation
|
||||
$pageClass = '';
|
||||
// do not cache because maybe class will be available later
|
||||
$cacheable = false;
|
||||
}
|
||||
}
|
||||
|
||||
$config = $this->wire('config');
|
||||
$config = $this->wire()->config;
|
||||
$usePageClasses = $config->usePageClasses;
|
||||
|
||||
if(empty($pageClass) || $pageClass === 'Page') {
|
||||
@@ -836,7 +853,7 @@ class Templates extends WireSaveableItems {
|
||||
}
|
||||
}
|
||||
|
||||
if($template->id) $this->pageClassNames[$template->id] = $pageClass;
|
||||
if($cacheable && $template->id) $this->pageClassNames[$template->id] = $pageClass;
|
||||
|
||||
if(!$withNamespace) $pageClass = wireClassName($pageClass, false);
|
||||
|
||||
@@ -904,7 +921,7 @@ class Templates extends WireSaveableItems {
|
||||
} else if($permission instanceof Permission) {
|
||||
$permissionName = $permission->name;
|
||||
} else {
|
||||
$permission = $this->wire('permissions')->get($permission);
|
||||
$permission = $this->wire()->permissions->get($permission);
|
||||
$permissionName = $permission ? $permission->name : '';
|
||||
}
|
||||
|
||||
|
@@ -39,6 +39,8 @@ class FieldtypeRepeater extends Fieldtype implements ConfigurableModule {
|
||||
);
|
||||
}
|
||||
|
||||
const devMode = false; // display verbose TD messages
|
||||
|
||||
const templateNamePrefix = 'repeater_';
|
||||
const fieldPageNamePrefix = 'for-field-';
|
||||
const repeaterPageNamePrefix = 'for-page-';
|
||||
@@ -167,6 +169,9 @@ class FieldtypeRepeater extends Fieldtype implements ConfigurableModule {
|
||||
$inEditor = $process == 'ProcessPageEdit' || $process == 'ProcessProfile';
|
||||
$isSuperuser = $user->isSuperuser();
|
||||
|
||||
// @todo would the following line be needed in some contexts (like ListerPro?)
|
||||
// if(!$inEditor && $process && wireInstanceOf($process, 'WirePageEditor')) $inEditor = true;
|
||||
|
||||
// make sure that all templates used by repeater pages enforce a Page type of RepeaterPage
|
||||
// this was necessary when lazy loading option was disabled
|
||||
if(!$this->useLazy) $this->initAllFields();
|
||||
@@ -307,7 +312,13 @@ class FieldtypeRepeater extends Fieldtype implements ConfigurableModule {
|
||||
|
||||
/** @var Page|RepeaterPage $page */
|
||||
$page = $event->arguments(0);
|
||||
if(!$page instanceof RepeaterPage) return;
|
||||
if(!$page instanceof RepeaterPage) {
|
||||
$t = $page->template;
|
||||
if(strpos("$t", "repeater_") === 0) {
|
||||
$this->bd("Page $page ($t) has wrong class ($page->className != $t->pageClass)", __FUNCTION__, true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
$forField = $page->getForField();
|
||||
$n = 0;
|
||||
@@ -2129,12 +2140,12 @@ class FieldtypeRepeater extends Fieldtype implements ConfigurableModule {
|
||||
$fieldPageName = self::fieldPageNamePrefix . ($field ? $field->id : '');
|
||||
|
||||
if(strpos($page->path, '/' . self::repeatersRootPageName . '/') === false) {
|
||||
$this->bd("Cannot delete $page->path because not in repeaters path", __FUNCTION__);
|
||||
$this->bd("Cannot delete $page->path because not in repeaters path", __FUNCTION__, true);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if($field && strpos($page->path, "/$fieldPageName/") === false) {
|
||||
$this->bd("Cannot delete $page->path because not within /$fieldPageName/", __FUNCTION__);
|
||||
$this->bd("Cannot delete $page->path because not within /$fieldPageName/", __FUNCTION__, true);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -2154,14 +2165,14 @@ class FieldtypeRepeater extends Fieldtype implements ConfigurableModule {
|
||||
|
||||
} else {
|
||||
// some other page, not allowed to delete
|
||||
$this->bd("Not allowed to delete $page->path", __FUNCTION__);
|
||||
$this->bd("Not allowed to delete $page->path", __FUNCTION__, true);
|
||||
return 0;
|
||||
}
|
||||
|
||||
$numChildren = $page->numChildren;
|
||||
|
||||
if($numChildren && !$recursive) {
|
||||
$this->bd("Cannot delete $page->path because has children", __FUNCTION__);
|
||||
$this->bd("Cannot delete $page->path because has children", __FUNCTION__, true);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -2187,11 +2198,14 @@ class FieldtypeRepeater extends Fieldtype implements ConfigurableModule {
|
||||
|
||||
/**
|
||||
* @param mixed $msg
|
||||
* @param string $func
|
||||
* @param string|bool $func
|
||||
* @param bool $error
|
||||
*
|
||||
*/
|
||||
protected function bd($msg, $func = '') {
|
||||
protected function bd($msg, $func = '', $error = false) {
|
||||
if(!$this->wire()->config->debug || !class_exists('\\TD')) return;
|
||||
if(is_bool($func)) list($error, $func) = array($func, '');
|
||||
if(!self::devMode && !$error) return;
|
||||
call_user_func_array('\\TD::barDump', array($msg, $this->className() . "::$func"));
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user