From f6558c25acde0fca06ba882a9941654f1e65acf3 Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Mon, 12 Sep 2022 11:15:53 -0400 Subject: [PATCH] Minor code improvements in various classes, mostly phpdoc related --- wire/core/Field.php | 20 +++-- wire/core/Fieldgroup.php | 50 ++++++----- wire/core/Fieldgroups.php | 21 +++-- wire/core/PageFinder.php | 83 +++++++++---------- wire/core/Selector.php | 34 ++++---- wire/core/Selectors.php | 27 +++--- wire/core/WireHttp.php | 10 ++- wire/modules/Process/ProcessPageClone.module | 70 +++++++++------- .../Process/ProcessPageEdit/PageBookmarks.php | 75 ++++++++++------- .../ProcessPageLister.module | 46 ++++++---- wire/modules/Process/ProcessPageSort.module | 36 ++++---- wire/modules/Process/ProcessPageTrash.module | 40 ++++----- 12 files changed, 296 insertions(+), 216 deletions(-) diff --git a/wire/core/Field.php b/wire/core/Field.php index 95c95efd..790fef82 100644 --- a/wire/core/Field.php +++ b/wire/core/Field.php @@ -532,7 +532,7 @@ class Field extends WireData implements Saveable, Exportable { foreach(array('viewRoles', 'editRoles') as $roleType) { if(!is_array($data[$roleType])) $data[$roleType] = array(); $roleNames = array(); - foreach($data[$roleType] as $key => $roleID) { + foreach($data[$roleType] as $roleID) { $role = $roles->get($roleID); if(!$role || !$role->id) continue; $roleNames[] = $role->name; @@ -675,7 +675,7 @@ class Field extends WireData implements Saveable, Exportable { */ public function setFieldtype($type) { - if(is_object($type) && $type instanceof Fieldtype) { + if($type instanceof Fieldtype) { // good for you } else if(is_string($type)) { @@ -997,7 +997,7 @@ class Field extends WireData implements Saveable, Exportable { } } - if($locked && $locked === 'hidden') { + if($locked === 'hidden') { // Inputfield should not be shown $inputfield->collapsed = Inputfield::collapsedHidden; } else if($locked) { @@ -1098,7 +1098,8 @@ class Field extends WireData implements Saveable, Exportable { } if(!$fieldgroupContext || count($allowContext)) { - + + /** @var InputfieldWrapper $inputfields */ $inputfields = $this->wire(new InputfieldWrapper()); if(!$fieldgroupContext) $inputfields->head = $this->_('Field type details'); $inputfields->attr('title', $this->_('Details')); @@ -1111,12 +1112,14 @@ class Field extends WireData implements Saveable, Exportable { if(!$fieldtypeInputfields) $fieldtypeInputfields = $this->wire(new InputfieldWrapper()); $configArray = $this->type->getConfigArray($this); if(count($configArray)) { + /** @var InputfieldWrapper $w */ $w = $this->wire(new InputfieldWrapper()); $w->importArray($configArray); $w->populateValues($this); $fieldtypeInputfields->import($w); } foreach($fieldtypeInputfields as $inputfield) { + /** @var Inputfield $inputfield */ if($fieldgroupContext && !in_array($inputfield->name, $allowContext)) continue; $inputfields->append($inputfield); unset($remainingNames[$inputfield->name]); @@ -1139,6 +1142,7 @@ class Field extends WireData implements Saveable, Exportable { if(count($inputfields)) $wrapper->append($inputfields); } + /** @var InputfieldWrapper $inputfields */ $inputfields = $this->wire(new InputfieldWrapper()); $dummyPage = $this->wire()->pages->get('/'); // only using this to satisfy param requirement @@ -1157,17 +1161,21 @@ class Field extends WireData implements Saveable, Exportable { } $inputfields->attr('title', $this->_('Input')); $inputfields->attr('id+name', 'inputfieldConfig'); - /** @var InputfieldWrapper $inputfieldInputfields */ $inputfieldInputfields = $inputfield->getConfigInputfields(); - if(!$inputfieldInputfields) $inputfieldInputfields = $this->wire(new InputfieldWrapper()); + if(!$inputfieldInputfields) { + /** @var InputfieldWrapper $inputfieldInputfields */ + $inputfieldInputfields = $this->wire(new InputfieldWrapper()); + } $configArray = $inputfield->getConfigArray(); if(count($configArray)) { + /** @var InputfieldWrapper $w */ $w = $this->wire(new InputfieldWrapper()); $w->importArray($configArray); $w->populateValues($this); $inputfieldInputfields->import($w); } foreach($inputfieldInputfields as $i) { + /** @var Inputfield $i */ if($fieldgroupContext && !in_array($i->name, $allowContext)) continue; $inputfields->append($i); unset($remainingNames[$i->name]); diff --git a/wire/core/Fieldgroup.php b/wire/core/Fieldgroup.php index 7a8b1da9..97199517 100644 --- a/wire/core/Fieldgroup.php +++ b/wire/core/Fieldgroup.php @@ -65,7 +65,7 @@ class Fieldgroup extends WireArray implements Saveable, Exportable, HasLookupIte * */ public function isValidItem($item) { - return is_object($item) && $item instanceof Field; + return $item instanceof Field; } /** @@ -87,10 +87,11 @@ class Fieldgroup extends WireArray implements Saveable, Exportable, HasLookupIte * #pw-internal * * @param $item - * @return int|string + * @return int * */ public function getItemKey($item) { + /** @var Field $item */ return $item->id; } @@ -116,15 +117,16 @@ class Fieldgroup extends WireArray implements Saveable, Exportable, HasLookupIte * * #pw-group-manipulation * - * @param Field|string $field Field object, field name or id. + * @param Field|string $item Field object, field name or id. * @return $this * @throws WireException * */ - public function add($field) { + public function add($item) { + $field = $item; if(!is_object($field)) $field = $this->wire()->fields->get($field); - if($field && $field instanceof Field) { + if($field instanceof Field) { if(!$field->id) { throw new WireException("You must save field '$field' before adding to Fieldgroup '$this->name'"); } @@ -149,13 +151,14 @@ class Fieldgroup extends WireArray implements Saveable, Exportable, HasLookupIte * * #pw-group-manipulation * - * @param Field|string $field Field object or field name, or id. + * @param Field|string $key Field object or field name, or id. * @return bool True on success, false on failure. * */ - public function remove($field) { - - if(!is_object($field)) $field = $this->wire('fields')->get($field); + public function remove($key) { + + $field = $key; + if(!is_object($field)) $field = $this->wire()->fields->get($field); if(!$this->getField($field->id)) return false; if(!$field) return true; @@ -205,7 +208,7 @@ class Fieldgroup extends WireArray implements Saveable, Exportable, HasLookupIte */ public function softRemove($field) { - if(!is_object($field)) $field = $this->wire('fields')->get($field); + if(!is_object($field)) $field = $this->wire()->fields->get($field); if(!$this->getField($field->id)) return false; if(!$field) return true; @@ -238,7 +241,7 @@ class Fieldgroup extends WireArray implements Saveable, Exportable, HasLookupIte * */ public function getField($key, $useFieldgroupContext = false) { - if(is_object($key) && $key instanceof Field) $key = $key->id; + if($key instanceof Field) $key = $key->id; if(is_string($key) && ctype_digit("$key")) $key = (int) $key; if($this->isValidKey($key)) { @@ -248,6 +251,7 @@ class Fieldgroup extends WireArray implements Saveable, Exportable, HasLookupIte $value = null; foreach($this as $field) { + /** @var Field $field */ if($field->name == $key) { $value = $field; break; @@ -291,9 +295,9 @@ class Fieldgroup extends WireArray implements Saveable, Exportable, HasLookupIte * */ public function hasFieldContext($field, $namespace = '') { - if(is_object($field) && $field instanceof Field) $field = $field->id; + if($field instanceof Field) $field = $field->id; if(is_string($field) && !ctype_digit($field)) { - $field = $this->wire('fields')->get($field); + $field = $this->wire()->fields->get($field); $field = $field && $field->id ? $field->id : 0; } if(isset($this->fieldContexts[(int) $field])) { @@ -349,7 +353,10 @@ class Fieldgroup extends WireArray implements Saveable, Exportable, HasLookupIte if($key == 'fields') return $this; if($key == 'fields_id') { $values = array(); - foreach($this as $field) $values[] = $field->id; + foreach($this as $field) { + /** @var Field $field */ + $values[] = $field->id; + } return $values; } if($key == 'removedFields') return $this->removedFields; @@ -429,7 +436,7 @@ class Fieldgroup extends WireArray implements Saveable, Exportable, HasLookupIte * */ public function save() { - $this->wire('fieldgroups')->save($this); + $this->wire()->fieldgroups->save($this); return $this; } @@ -460,8 +467,7 @@ class Fieldgroup extends WireArray implements Saveable, Exportable, HasLookupIte * */ public function getExportData() { - /** @var Fieldgroups $fieldgroups */ - $fieldgroups = $this->wire('fieldgroups'); + $fieldgroups = $this->wire()->fieldgroups; return $fieldgroups->getExportData($this); } @@ -562,6 +568,7 @@ class Fieldgroup extends WireArray implements Saveable, Exportable, HasLookupIte } foreach($this as $field) { + /** @var Field $field */ // for named multi-field retrieval if($multiMode && !isset($fieldInputfields[$field->id])) continue; @@ -612,7 +619,7 @@ class Fieldgroup extends WireArray implements Saveable, Exportable, HasLookupIte continue; } - } else if($field->modal && $field->type instanceof FieldtypeFieldsetOpen) { + } else if($field->get('modal') && $field->type instanceof FieldtypeFieldsetOpen) { // field requires modal $inModalGroup = $field->name; @@ -629,6 +636,7 @@ class Fieldgroup extends WireArray implements Saveable, Exportable, HasLookupIte // start a new container $inputfield = $field->getInputfield($page, $contextStr); if(!$inputfield) $inputfield = $this->wire(new InputfieldWrapper()); + /** @var Inputfield|InputfieldWrapper $inputfield */ if($inputfield->collapsed == Inputfield::collapsedHidden) continue; $container->add($inputfield); $containers[] = $container; @@ -655,7 +663,7 @@ class Fieldgroup extends WireArray implements Saveable, Exportable, HasLookupIte if($multiMode) { // add to container in requested order - foreach($fieldInputfields as $fieldID => $inputfield) { + foreach($fieldInputfields as /* $fieldID => */ $inputfield) { if($inputfield) $container->add($inputfield); } } @@ -686,7 +694,7 @@ class Fieldgroup extends WireArray implements Saveable, Exportable, HasLookupIte * */ public function getNumTemplates() { - return $this->wire('fieldgroups')->getNumTemplates($this); + return $this->wire()->fieldgroups->getNumTemplates($this); } /** @@ -756,7 +764,7 @@ class Fieldgroup extends WireArray implements Saveable, Exportable, HasLookupIte * */ public function saveContext() { - return $this->wire('fieldgroups')->saveContext($this); + return $this->wire()->fieldgroups->saveContext($this); } } diff --git a/wire/core/Fieldgroups.php b/wire/core/Fieldgroups.php index f37872d6..89c885cf 100644 --- a/wire/core/Fieldgroups.php +++ b/wire/core/Fieldgroups.php @@ -136,7 +136,7 @@ class Fieldgroups extends WireSaveableItemsLookup { $templates = $this->wire()->templates; $num = 0; - foreach($templates->getAllValues('fieldgroups_id', 'id') as $templateId => $fieldgroupId) { + foreach($templates->getAllValues('fieldgroups_id', 'id') as /* $templateId => */ $fieldgroupId) { if($fieldgroupId == $fieldgroup->id) $num++; } @@ -180,6 +180,7 @@ class Fieldgroups extends WireSaveableItemsLookup { if(!$useLazy && !is_object($fieldgroup)) $fieldgroup = $this->get($fieldgroup); if($fieldgroup instanceof Fieldgroup) { foreach($fieldgroup as $field) { + /** @var Field $field */ $fieldNames[$field->id] = $field->name; } return $fieldNames; @@ -231,10 +232,13 @@ class Fieldgroups extends WireSaveableItemsLookup { foreach($this->wire()->templates as $template) { if($template->fieldgroup->id !== $fieldgroup->id) continue; foreach($fieldgroup->removedFields as $field) { + /** @var Field $field */ // make sure the field is valid to delete from this template $error = $this->isFieldNotRemoveable($field, $fieldgroup, $template); if($error !== false) throw new WireException("$error Save of fieldgroup changes aborted."); - if($field->type) $field->type->deleteTemplateField($template, $field); + /** @var Fieldtype $fieldtype */ + $fieldtype = $field->type; + if($fieldtype) $fieldtype->deleteTemplateField($template, $field); $fieldgroup->finishRemove($field); $fieldsRemoved[] = $field; } @@ -308,7 +312,8 @@ class Fieldgroups extends WireSaveableItemsLookup { public function ___delete(Saveable $item) { $templates = array(); - foreach($this->wire('templates') as $template) { + foreach($this->wire()->templates as $template) { + /** @var Template $template */ if($template->fieldgroup->id == $item->id) $templates[] = $template->name; } @@ -330,7 +335,7 @@ class Fieldgroups extends WireSaveableItemsLookup { * */ public function deleteField(Field $field) { - $database = $this->wire('database'); + $database = $this->wire()->database; $query = $database->prepare("DELETE FROM fieldgroups_fields WHERE fields_id=:fields_id"); // QA $query->bindValue(":fields_id", $field->id, \PDO::PARAM_INT); $result = $query->execute(); @@ -389,6 +394,7 @@ class Fieldgroups extends WireSaveableItemsLookup { $fields = array(); $contexts = array(); foreach($fieldgroup as $field) { + /** @var Field $field */ $fields[] = $field->name; $fieldContexts = $fieldgroup->getFieldContextArray(); if(isset($fieldContexts[$field->id])) { @@ -450,18 +456,19 @@ class Fieldgroups extends WireSaveableItemsLookup { // figure out which fields should be removed foreach($fieldgroup as $field) { + /** @var Field $field */ $fieldNames[$field->name] = $field->name; if(!in_array($field->name, $data['fields'])) { $fieldgroup->remove($field); $label = "-$field->name"; - $return['fields']['new'] .= $label . "\n";; + $return['fields']['new'] .= $label . "\n"; $rmFields[] = $field->name; } } // figure out which fields should be added foreach($data['fields'] as $name) { - $field = $this->wire('fields')->get($name); + $field = $this->wire()->fields->get($name); if(in_array($name, $rmFields)) continue; if(!$field) { $error = sprintf($this->_('Unable to find field: %s'), $name); @@ -566,7 +573,7 @@ class Fieldgroups extends WireSaveableItemsLookup { */ public function isFieldNotRemoveable(Field $field, Fieldgroup $fieldgroup, Template $template = null) { - if(is_null($template)) $template = $this->wire('templates')->get($fieldgroup->name); + if(is_null($template)) $template = $this->wire()->templates->get($fieldgroup->name); if(($field->flags & Field::flagGlobal) && (!$template || !$template->noGlobal)) { if($template && $template->getConnectedField()) { diff --git a/wire/core/PageFinder.php b/wire/core/PageFinder.php index a1fe5f94..023e28fe 100644 --- a/wire/core/PageFinder.php +++ b/wire/core/PageFinder.php @@ -402,10 +402,10 @@ class PageFinder extends Wire { // protected $extraJoins = array(); // protected $nativeWheres = array(); // where statements for native fields, to be reused in subselects where appropriate. - public function __get($key) { - if($key === 'includeMode') return $this->includeMode; - if($key === 'checkAccess') return $this->checkAccess; - return parent::__get($key); + public function __get($name) { + if($name === 'includeMode') return $this->includeMode; + if($name === 'checkAccess') return $this->checkAccess; + return parent::__get($name); } /** @@ -455,7 +455,6 @@ class PageFinder extends Wire { */ protected function initSelectors(Selectors $selectors, array $options) { - $maxStatus = null; $limit = 0; // for getTotal auto detection $start = 0; $limitSelector = null; @@ -485,7 +484,6 @@ class PageFinder extends Wire { ); foreach($selectors as $key => $selector) { - /** @var Selector $selector */ $fieldName = $selector->field; $operator = $selector->operator; @@ -690,6 +688,7 @@ class PageFinder extends Wire { if(($operator === '!=' && !$selector->not) || ($selector->not && $operator === '=')) { // NOT MATCH condition: replace with bitwise AND NOT selector + /** @var Selector $s */ $s = $this->wire(new SelectorBitwiseAnd('status', $qty > 1 ? $values : reset($values))); $s->not = true; $not = true; @@ -790,6 +789,7 @@ class PageFinder extends Wire { if(is_string($selectors) || is_array($selectors)) { list($s, $selectors) = array($selectors, $this->wire(new Selectors())); + /** @var Selectors $selectors */ $selectors->init($s); } else if(!$selectors instanceof Selectors) { throw new PageFinderException("find() requires Selectors object, string or array"); @@ -1162,7 +1162,6 @@ class PageFinder extends Wire { $o['getTotal'] = true; $o['loadPages'] = false; $o['returnVerbose'] = false; - /** @var Selectors $sel */ $sel = clone $selectors; foreach($sel as $s) { if($s->field == 'limit' || $s->field == 'start') $sel->remove($s); @@ -1242,7 +1241,7 @@ class PageFinder extends Wire { $fieldtypeLang = $languages ? $fieldtypes->get("{$fieldName}Language") : null; foreach($this->fields as $f) { - + /** @var Field $f */ if($findExtends) { // allow any Fieldtype that is an instance of given one, or extends it if(!wireInstanceOf($f->type, $fieldtype) @@ -1431,6 +1430,7 @@ class PageFinder extends Wire { } else { $s = ''; } + /** @var Selectors $_selectors */ $_selectors = $this->wire(new Selectors($s)); $_selector = $_selectors->create(implode('.', $parts), $selector->operator, $selector->values); $_selectors->add($_selector); @@ -1679,7 +1679,7 @@ class PageFinder extends Wire { $this->pageArrayData['joinFields'] = array(); // identify whether each field supported autojoin foreach($opts['joinFields'] as $joinField) { $joinField = $this->fields->get($joinField); - if(!$joinField || !$joinField instanceof Field) continue; + if(!$joinField instanceof Field) continue; $joinTable = $database->escapeTable($joinField->getTable()); if(!$joinTable || !$joinField->type) continue; if($joinField->type->getLoadQueryAutojoin($joinField, $query)) { @@ -1829,7 +1829,7 @@ class PageFinder extends Wire { // without this section the query would still work, but a blank value must actually be present in the field $isEmptyValue = $fieldtype->isEmptyValue($field, $value); $useEmpty = $isEmptyValue || $operator[0] === '<' || ((int) $value < 0 && $operator[0] === '>'); - if($useEmpty && $fieldtype && strpos($subfield, 'data') === 0) { // && !$fieldtype instanceof FieldtypeMulti) { + if($useEmpty && strpos($subfield, 'data') === 0) { // && !$fieldtype instanceof FieldtypeMulti) { if($isEmptyValue) $numEmptyValues++; if(in_array($operator, array('=', '!=', '<', '<=', '>', '>='))) { // we only accommodate this optimization for single-value selectors... @@ -1990,7 +1990,7 @@ class PageFinder extends Wire { // what groups should be OR'd together $sqls = array(); - foreach($this->extraOrSelectors as $groupName => $selectorGroup) { + foreach($this->extraOrSelectors as /* $groupName => */ $selectorGroup) { $n = 0; $sql = "\tpages.id IN (\n"; foreach($selectorGroup as $selectors) { @@ -2243,6 +2243,7 @@ class PageFinder extends Wire { if($user->isGuest()) { // guest foreach($this->templates as $template) { + /** @var Template $template */ if($template->guestSearchable || !$template->useRoles) { $yesTemplates[$template->id] = $template; continue; @@ -2262,6 +2263,7 @@ class PageFinder extends Wire { } foreach($this->templates as $template) { + /** @var Template $template */ if($template->guestSearchable || !$template->useRoles) { $yesTemplates[$template->id] = $template; continue; @@ -2276,6 +2278,7 @@ class PageFinder extends Wire { // determine which templates the user is not allowed to access foreach($this->templates as $template) { + /** @var Template $template */ if(!isset($yesTemplates[$template->id])) $noTemplates[$template->id] = $template; } @@ -2338,7 +2341,6 @@ class PageFinder extends Wire { * @return string */ protected function ___getQueryAllowedTemplatesWhere(DatabaseQuerySelect $query, $where) { - if($query) {} return $where; } @@ -2460,7 +2462,7 @@ class PageFinder extends Wire { $value = "COUNT($tableAlias.data)"; } - } else if(is_object($blankValue) && ($blankValue instanceof PageArray || $blankValue instanceof Page)) { + } else if($blankValue instanceof PageArray || $blankValue instanceof Page) { // If it's a FieldtypePage, then data isn't worth sorting on because it just contains an ID to the page // so we also join the page and sort on it's name instead of the field's "data" field. if(!$subValue) $subValue = 'name'; @@ -2498,7 +2500,7 @@ class PageFinder extends Wire { } else { // regular field, just sort by data column - $value = "$tableAlias." . ($subValue ? $subValue : "data"); ; + $value = "$tableAlias." . ($subValue ? $subValue : "data"); } } @@ -2560,6 +2562,7 @@ class PageFinder extends Wire { if($this->supportsLanguagePageNames()) { $langNames = array(); foreach($this->languages as $language) { + /** @var Language $language */ if(!$language->isDefault()) $langNames[$language->id] = "name" . (int) $language->id; } if(!count($langNames)) $langNames = null; @@ -2622,7 +2625,7 @@ class PageFinder extends Wire { //$query->join("pages AS $alias ON ($lastAlias.parent_id=$alias.id AND $alias.name='$part')"); $bindKey = $query->bindValueGetKey($part); $sql = "pages AS $alias ON ($lastAlias.parent_id=$alias.id AND ($alias.name=$bindKey"; - if($langNames) foreach($langNames as $id => $name) { + if($langNames) foreach($langNames as /* $id => */ $name) { // $status = "status" . (int) $id; // $sql .= " OR ($alias.$name='$part' AND $alias.$status>0) "; $bindKey = $query->bindValueGetKey($part); @@ -2848,16 +2851,16 @@ class PageFinder extends Wire { } } else if(!$database->isOperator($operator)) { - $this->syntaxError("Operator '$operator' is not supported for '$field'."); $s = ''; + $this->syntaxError("Operator '$operator' is not supported for '$field'."); } else if($this->isModifierField($field)) { - $this->syntaxError("Modifier '$field' is not allowed here"); $s = ''; + $this->syntaxError("Modifier '$field' is not allowed here"); } else if(!$this->pagesColumnExists($field)) { - $this->syntaxError("Field '$field' is not a known field, column or selector modifier"); $s = ''; + $this->syntaxError("Field '$field' is not a known field, column or selector modifier"); } else { $not = false; @@ -3181,7 +3184,7 @@ class PageFinder extends Wire { /** * Returns the templates ID, if it was part of the selector * - * @return int + * @return int|null * */ public function getTemplatesID() { @@ -3223,12 +3226,11 @@ class PageFinder extends Wire { protected function isPageField($fieldName, $literal = false) { $is = false; - $field = null; if($fieldName === 'parent' || $fieldName === 'children') { return $fieldName; // early exit - } else if(is_object($fieldName) && $fieldName instanceof Field) { + } else if($fieldName instanceof Field) { $field = $fieldName; } else if(is_string($fieldName) && strpos($fieldName, '.')) { @@ -3261,7 +3263,7 @@ class PageFinder extends Wire { $is = $literal ? false : true; } else { $test = $field->type->getBlankValue(new NullPage(), $field); - if(is_object($test) && ($test instanceof Page || $test instanceof PageArray)) { + if($test instanceof Page || $test instanceof PageArray) { $is = $literal ? false : true; } } @@ -3333,6 +3335,7 @@ class PageFinder extends Wire { self::$pagesColumns[$instanceID] = array(); if($this->supportsLanguagePageNames()) { foreach($this->languages as $language) { + /** @var Language $language */ if($language->isDefault()) continue; self::$pagesColumns[$instanceID]["name$language->id"] = true; self::$pagesColumns[$instanceID]["status$language->id"] = true; @@ -3420,16 +3423,11 @@ class PageFinder extends Wire { ); $data = array_merge($_data, $data); - /** @var array $fields */ - $fields = $data['fields']; - /** @var string $subfields */ - $subfields = $data['subfields']; - /** @var Selector $selector */ - $selector = $data['selector']; - /** @var DatabaseQuerySelect $query */ - $query = $data['query']; - /** @var Wire|null $value */ - $value = $this->wire($fieldName); + $fields = $data['fields']; /** @var array $fields */ + $subfields = $data['subfields']; /** @var string $subfields */ + $selector = $data['selector']; /** @var Selector $selector */ + $query = $data['query']; /** @var DatabaseQuerySelect $query */ + $value = $this->wire($fieldName); /** @var Wire|null $value */ if($value) { // found an API var @@ -3450,7 +3448,10 @@ class PageFinder extends Wire { if($this->getQueryOwnerField($fieldName, $data)) return true; - return false; + /** @var bool|int|Field $value Hooks can modify return value to be Field */ + $value = false; + + return $value; } /** @@ -3466,16 +3467,11 @@ class PageFinder extends Wire { if(substr($fieldName, -7) !== '__owner') return false; - /** @var array $fields */ - $fields = $data['fields']; - /** @var string $subfields */ - $subfields = $data['subfields']; - /** @var Selectors $selectors */ - $selectors = $data['selectors']; - /** @var Selector $selector */ - $selector = $data['selector']; - /** @var DatabaseQuerySelect $query */ - $query = $data['query']; + $fields = $data['fields']; /** @var array $fields */ + $subfields = $data['subfields']; /** @var string $subfields */ + $selectors = $data['selectors']; /** @var Selectors $selectors */ + $selector = $data['selector']; /** @var Selector $selector */ + $query = $data['query']; /** @var DatabaseQuerySelect $query */ if(empty($subfields)) $this->syntaxError("When using owner a subfield is required"); @@ -3493,6 +3489,7 @@ class PageFinder extends Wire { // determine which templates are using $ownerFieldName $templateIDs = array(); foreach($this->templates as $template) { + /** @var Template $template */ if($template->hasField($ownerFieldName)) { $templateIDs[$template->id] = $template->id; } diff --git a/wire/core/Selector.php b/wire/core/Selector.php index 28c1139f..263abf33 100644 --- a/wire/core/Selector.php +++ b/wire/core/Selector.php @@ -187,6 +187,7 @@ abstract class Selector extends WireData { * */ public function __construct($field, $value) { + parent::__construct(); $this->set('not', false); $this->set('group', null); // group name identified with 'group_name@' before a field name $this->set('quote', ''); // if $value in quotes, this contains either: ', ", [, {, or (, indicating quote type (set by Selectors class) @@ -268,7 +269,7 @@ abstract class Selector extends WireData { if($forceString === 1) { $value = reset($value); } else { - $value = $this->wire('sanitizer')->selectorValue($value); + $value = $this->wire()->sanitizer->selectorValue($value); } } return $value; @@ -373,7 +374,7 @@ abstract class Selector extends WireData { public function getValue($type = '') { $value = $this->value; if($type == 'string') { - if(is_array($value)) $value = $this->wire('sanitizer')->selectorValue($value); + if(is_array($value)) $value = $this->wire()->sanitizer->selectorValue($value); } else if($type == 'array') { if(!is_array($value)) $value = array($value); } else if($this->quote == '[') { @@ -533,10 +534,15 @@ abstract class Selector extends WireData { // prepare the value we are comparing if(is_object($value)) { - if($this->wire('languages') && $value instanceof LanguagesValueInterface) $value = (string) $value; - else if($value instanceof WireData) $value = $value->get($field); - else if($value instanceof WireArray && is_string($field) && !strpos($field, '.')) $value = (string) $value; // 123|456|789, etc. - else if($value instanceof Wire) $value = $value->$field; + if($this->wire()->languages && $value instanceof LanguagesValueInterface) { + $value = (string) $value; + } else if($value instanceof WireData) { + $value = $value->get($field); + } else if($value instanceof WireArray && is_string($field) && !strpos($field, '.')) { + $value = (string) $value; // 123|456|789, etc. + } else if($value instanceof Wire) { + $value = $value->$field; + } $value = (string) $value; } @@ -928,7 +934,7 @@ class SelectorContainsWords extends Selector { protected function match($value1, $value2) { $hasAll = true; $words = $this->wire()->sanitizer->wordsArray($value2); - foreach($words as $key => $word) if(!preg_match('/\b' . preg_quote($word) . '\b/i', $value1)) { + foreach($words as $word) if(!preg_match('/\b' . preg_quote($word) . '\b/i', $value1)) { $hasAll = false; break; } @@ -955,7 +961,7 @@ class SelectorContainsWordsPartial extends Selector { protected function match($value1, $value2) { $hasAll = true; $words = $this->wire()->sanitizer->wordsArray($value2); - foreach($words as $key => $word) { + foreach($words as $word) { if(!preg_match('/\b' . preg_quote($word) . '/i', $value1)) { $hasAll = false; break; @@ -984,7 +990,7 @@ class SelectorContainsWordsLike extends Selector { protected function match($value1, $value2) { $hasAll = true; $words = $this->wire()->sanitizer->wordsArray($value2); - foreach($words as $key => $word) { + foreach($words as $word) { if(stripos($value1, $word) === false) { $hasAll = false; break; @@ -1016,7 +1022,7 @@ class SelectorContainsWordsLive extends Selector { $hasAll = true; $words = $this->wire()->sanitizer->wordsArray($value2); $lastWord = array_pop($words); - foreach($words as $key => $word) { + foreach($words as $word) { if(!preg_match('/\b' . preg_quote($word) . '\b/i', $value1)) { // full-word match $hasAll = false; @@ -1065,7 +1071,7 @@ class SelectorContainsAnyWords extends Selector { protected function match($value1, $value2) { $hasAny = false; $words = $this->wire()->sanitizer->wordsArray($value2); - foreach($words as $key => $word) { + foreach($words as $word) { if(stripos($value1, $word) !== false) { if(preg_match('!\b' . preg_quote($word) . '\b!i', $value1)) { $hasAny = true; @@ -1096,7 +1102,7 @@ class SelectorContainsAnyWordsPartial extends Selector { protected function match($value1, $value2) { $hasAny = false; $words = $this->wire()->sanitizer->wordsArray($value2); - foreach($words as $key => $word) { + foreach($words as $word) { if(stripos($value1, $word) !== false) { if(preg_match('!\b' . preg_quote($word) . '!i', $value1)) { $hasAny = true; @@ -1127,7 +1133,7 @@ class SelectorContainsAnyWordsLike extends Selector { protected function match($value1, $value2) { $hasAny = false; $words = $this->wire()->sanitizer->wordsArray($value2); - foreach($words as $key => $word) { + foreach($words as $word) { if(stripos($value1, $word) !== false) { $hasAny = true; break; @@ -1285,7 +1291,7 @@ class SelectorContainsAdvanced extends SelectorContains { $words = $this->wire()->sanitizer->wordsArray($value, array( 'keepChars' => array('+', '-', '*') )); - foreach($words as $key => $word) { + foreach($words as $word) { $type = substr($word, 0, 1); $partial = substr($word, -1) === '*'; if($type !== '+' && $type !== '-') $type = ''; diff --git a/wire/core/Selectors.php b/wire/core/Selectors.php index 78cb9690..c7542fdb 100644 --- a/wire/core/Selectors.php +++ b/wire/core/Selectors.php @@ -125,7 +125,7 @@ class Selectors extends WireArray { public function init($selector) { if(is_array($selector)) { $this->setSelectorArray($selector); - } else if(is_object($selector) && $selector instanceof Selector) { + } else if($selector instanceof Selector) { $this->add($selector); } else { $this->setSelectorString($selector); @@ -174,13 +174,15 @@ class Selectors extends WireArray { * */ public function isValidItem($item) { - return is_object($item) && $item instanceof Selector; + return $item instanceof Selector; } /** * Per WireArray interface, return a blank Selector * * #pw-internal + * + * @return Selector * */ public function makeBlankItem() { @@ -213,12 +215,13 @@ class Selectors extends WireArray { } 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'" : ""; + $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"); } } $class = wireClassName(self::$selectorTypes[$operator], true); + /** @var Selector $selector */ $selector = $this->wire(new $class($field, $value)); if($not) $selector->not = true; return $selector; @@ -279,7 +282,7 @@ class Selectors extends WireArray { protected function extractGroup(&$str) { $group = null; $pos = strpos($str, '@'); - if($pos === false) return $group; + if($pos === false) return null; if($pos === 0) { $group = ''; $str = substr($str, 1); @@ -421,7 +424,7 @@ class Selectors extends WireArray { * @param string $str String to extract value from, $str will be modified if extraction successful * @param string $openingQuote Opening quote character, if string has them, blank string otherwise * @param string $closingQuote Closing quote character, if string has them, blank string otherwise - * @return mixed Returns found value if successful, boolean false if not + * @return false|string|string[] Returns found value if successful, boolean false if not * */ protected function extractValueQuick(&$str, $openingQuote, $closingQuote) { @@ -507,6 +510,8 @@ class Selectors extends WireArray { * */ protected function extractValue(&$str, &$quote) { + + $sanitizer = $this->wire()->sanitizer; $str = trim($str); if(!strlen($str)) return ''; @@ -577,7 +582,7 @@ class Selectors extends WireArray { $op = self::$operatorChars[$str[$on]] . $op; } // if something valid does prefix the operator, cancel the operator - if(!$on || !$this->wire('sanitizer')->fieldName($str[$on])) $op = ''; + if(!$on || !$sanitizer->fieldName($str[$on])) $op = ''; // if an operator came before the quote, and it closes somewhere, // we will allow the embedded double quote if(strlen($op) && self::isOperator($op) && strrpos($str, '"') > $n) { @@ -713,7 +718,7 @@ class Selectors extends WireArray { $subname = ''; } if(!in_array($name, $this->allowedParseVars)) return false; - if(strlen($subname) && $this->wire('sanitizer')->fieldName($subname) !== $subname) return false; + if(strlen($subname) && $this->wire()->sanitizer->fieldName($subname) !== $subname) return false; return true; } @@ -924,7 +929,7 @@ class Selectors extends WireArray { */ protected function makeSelectorArrayItem($key, $data, $dataType = '') { - $sanitizer = $this->wire('sanitizer'); + $sanitizer = $this->wire()->sanitizer; $sanitize = 'selectorValue'; $fields = array(); $values = array(); @@ -982,9 +987,9 @@ class Selectors extends WireArray { $data['value'] = array(); } - if(isset($data['whitelist']) && $data['whitelist'] !== null) { + if(isset($data['whitelist'])) { $whitelist = $data['whitelist']; - if(is_object($whitelist) && $whitelist instanceof WireArray) $whitelist = explode('|', (string) $whitelist); + if($whitelist instanceof WireArray) $whitelist = explode('|', (string) $whitelist); if(!is_array($whitelist)) $whitelist = array($whitelist); } @@ -1071,7 +1076,7 @@ class Selectors extends WireArray { // convert WireArray types to an array of $_values if(count($_values) === 1) { $value = reset($_values); - if(is_object($value) && $value instanceof WireArray) { + if($value instanceof WireArray) { $_values = explode('|', (string) $value); } } diff --git a/wire/core/WireHttp.php b/wire/core/WireHttp.php index d68d6271..f09c79a6 100644 --- a/wire/core/WireHttp.php +++ b/wire/core/WireHttp.php @@ -1811,13 +1811,19 @@ class WireHttp extends Wire { } /** - * Set http response code and text + * Set http response code and text (internal use) + * + * This is public only in case a hook wants to modify an http response value, + * for instance translating one http code to another for some purpose. If used + * by a hook, it should be called after the WireHttp::send() method. + * + * #pw-internal * * @param int $code * @param string $text * */ - protected function setHttpCode($code, $text = '') { + public function setHttpCode($code, $text = '') { if(empty($text)) $text = isset($this->httpCodes[$code]) ? $this->httpCodes[$code] : '?'; $this->httpCode = $code; $this->httpCodeText = $text; diff --git a/wire/modules/Process/ProcessPageClone.module b/wire/modules/Process/ProcessPageClone.module index 3c354671..cd8a05ff 100644 --- a/wire/modules/Process/ProcessPageClone.module +++ b/wire/modules/Process/ProcessPageClone.module @@ -6,7 +6,7 @@ * For more details about how Process modules work, please see: * /wire/core/Process.php * - * ProcessWire 3.x, Copyright 2018 by Ryan Cramer + * ProcessWire 3.x, Copyright 2022 by Ryan Cramer * https://processwire.com * * Optional GET variables: @@ -36,8 +36,8 @@ class ProcessPageClone extends Process { 'title' => 'Clone', 'parent' => 'page', 'status' => Page::statusHidden, - ) - ); + ) + ); } /** @@ -70,7 +70,7 @@ class ProcessPageClone extends Process { * */ public function ready() { - $this->adminUrl = $this->wire('config')->urls->admin; + $this->adminUrl = $this->wire()->config->urls->admin; $this->pageListActionLabel = $this->_('Copy'); // Action label that appears in PageList $this->addHookAfter("ProcessPageListActions::getExtraActions", $this, 'hookPageListActions'); $this->addHookAfter("ProcessPageListActions::processAction", $this, 'hookProcessExtraAction'); @@ -119,14 +119,15 @@ class ProcessPageClone extends Process { * */ public function ___execute() { + $input = $this->wire()->input; $this->headline($this->_('Copy Page')); // Headline $error = $this->_("Unable to load page"); - $id = (int) $this->wire('input')->get('id'); - if(!$id) throw new WireException($error); - $this->page = $this->wire('pages')->get($id); + $id = (int) $input->get('id'); + if($id < 2) throw new WireException($error); + $this->page = $this->wire()->pages->get($id); if($this->page->id < 2) throw new WireException($error); if(!$this->hasPermission($this->page)) throw new WirePermissionException($error); - if($this->wire('input')->post('submit_clone')) $this->process(); + if($input->post('submit_clone')) $this->process(); return $this->render(); } @@ -165,8 +166,7 @@ class ProcessPageClone extends Process { */ protected function getSuggestedNameAndTitle(Page $page) { - /** @var Pages $pages */ - $pages = $this->wire('pages'); + $pages = $this->wire()->pages; $name = $pages->names()->uniquePageName(array( 'name' => $page->name, @@ -194,6 +194,7 @@ class ProcessPageClone extends Process { $languages = $this->wire()->languages; if($languages && $languages->hasPageNames()) { foreach($languages as $language) { + /** @var Language $language */ if($language->isDefault()) continue; $value = $page->get("name$language"); if(!strlen($value)) continue; @@ -212,11 +213,11 @@ class ProcessPageClone extends Process { */ protected function ___buildForm() { - /** @var Page $page */ $page = $this->page; + $modules = $this->wire()->modules; /** @var InputfieldForm $form */ - $form = $this->modules->get("InputfieldForm"); + $form = $modules->get("InputfieldForm"); $form->attr('action', './?id=' . $page->id); $form->attr('method', 'post'); $form->description = sprintf($this->_("This will make a copy of %s"), $page->path); // Form description/headline @@ -225,23 +226,22 @@ class ProcessPageClone extends Process { $suggested = $this->getSuggestedNameAndTitle($page); /** @var InputfieldPageTitle $titleField */ - $titleField = $this->modules->get("InputfieldPageTitle"); + $titleField = $modules->get("InputfieldPageTitle"); $titleField->attr('name', 'clone_page_title'); $titleField->attr('value', $suggested['title']); $titleField->label = $this->_("Title of new page"); // Label for title field /** @var InputfieldPageName $nameField */ - $nameField = $this->modules->get("InputfieldPageName"); + $nameField = $modules->get("InputfieldPageName"); $nameField->attr('name', 'clone_page_name'); $nameField->attr('value', $suggested['name']); $nameField->parentPage = $page->parent; - /** @var Languages $languages */ - $languages = $this->wire('languages'); + $languages = $this->wire()->languages; $useLanguages = $languages; if($useLanguages) { /** @var Field $title */ - $title = $this->wire('fields')->get('title'); + $title = $this->wire()->fields->get('title'); $titleUseLanguages = $title && $page->template->fieldgroup->hasField($title) && $title->getInputfield($page)->getSetting('useLanguages'); @@ -249,6 +249,7 @@ class ProcessPageClone extends Process { if($titleUseLanguages) $titleField->useLanguages = true; if($nameUseLanguages) $nameField->useLanguages = true; foreach($languages as $language) { + /** @var Language $language */ if($language->isDefault()) continue; if($titleUseLanguages) { /** @var LanguagesPageFieldValue $pageTitle */ @@ -274,7 +275,7 @@ class ProcessPageClone extends Process { $form->add($nameField); /** @var InputfieldCheckbox $field */ - $field = $this->modules->get("InputfieldCheckbox"); + $field = $modules->get("InputfieldCheckbox"); $field->attr('name', 'clone_page_unpublished'); $field->attr('value', 1); $field->label = $this->_("Make the new page unpublished?"); @@ -284,7 +285,7 @@ class ProcessPageClone extends Process { if($page->numChildren && $this->user->hasPermission('page-clone-tree', $page)) { /** @var InputfieldCheckbox $field */ - $field = $this->modules->get("InputfieldCheckbox"); + $field = $modules->get("InputfieldCheckbox"); $field->attr('name', 'clone_page_tree'); $field->attr('value', 1); $field->label = $this->_("Copy children too?"); @@ -295,14 +296,14 @@ class ProcessPageClone extends Process { } /** @var InputfieldSubmit $field */ - $field = $this->modules->get("InputfieldSubmit"); + $field = $modules->get("InputfieldSubmit"); $field->attr('name', 'submit_clone'); $form->add($field); - $redirectPageID = (int) $this->wire('input')->get('redirect_page'); + $redirectPageID = (int) $this->wire()->input->get('redirect_page'); if($redirectPageID) { /** @var InputfieldHidden $field */ - $field = $this->wire('modules')->get('InputfieldHidden'); + $field = $modules->get('InputfieldHidden'); $field->attr('name', 'redirect_page'); $field->attr('value', $redirectPageID); $form->add($field); @@ -330,6 +331,7 @@ class ProcessPageClone extends Process { $page = clone $this->page; $input = $this->input; + $languages = $this->wire()->languages; $originalName = $page->name; $this->session->CSRF->validate(); @@ -344,8 +346,9 @@ class ProcessPageClone extends Process { $page->addStatus(Page::statusUnpublished); } - if($nameField->useLanguages) { - foreach($this->wire('languages') as $language) { + if($nameField->useLanguages && $languages) { + foreach($languages as $language) { + /** @var Language $language */ $valueAttr = $language->isDefault() ? "value" : "value$language->id"; $nameAttr = $language->isDefault() ? "name" : "name$language->id"; $value = $nameField->get($valueAttr); @@ -363,8 +366,9 @@ class ProcessPageClone extends Process { throw new WireException(sprintf($this->_("Unable to clone page %s"), $page->path)); } - if($titleField->getSetting('useLanguages') && is_object($clone->title)) { - foreach($this->wire('languages') as $language) { + if($titleField->getSetting('useLanguages') && is_object($clone->title) && $languages) { + foreach($languages as $language) { + /** @var Language $language */ $valueAttr = $language->isDefault() ? "value" : "value$language->id"; $value = $titleField->get($valueAttr); /** @var LanguagesPageFieldValue $cloneTitle */ @@ -375,7 +379,7 @@ class ProcessPageClone extends Process { $clone->title = $titleField->value; } - $this->wire('pages')->save($clone, array('adjustName' => true)); + $this->wire()->pages->save($clone, array('adjustName' => true)); $this->message(sprintf($this->_('Cloned page "%1$s" to "%2$s"'), $originalName, $clone->name)); @@ -383,7 +387,7 @@ class ProcessPageClone extends Process { $redirectID = (int) $input->post('redirect_page'); if($redirectID) { - $redirectPage = $this->wire('pages')->get($redirectID); + $redirectPage = $this->wire()->pages->get($redirectID); if($redirectPage->viewable()) { $redirectURL = $redirectPage->url(); } @@ -427,7 +431,7 @@ class ProcessPageClone extends Process { ); if($clone->id) { - $result['message'] = $this->wire('sanitizer')->unentities( + $result['message'] = $this->wire()->sanitizer->unentities( sprintf($this->_('Cloned to: %s'), $clone->path) ); } else { @@ -468,8 +472,10 @@ class ProcessPageClone extends Process { ) ); - if($this->wire('languages')) { - foreach($this->wire('languages') as $language) { + $languages = $this->wire()->languages; + if($languages) { + foreach($languages as $language) { + /** @var Language $language */ if($language->isDefault()) continue; if(!empty($suggested["name$language"])) { $cloneOptions['set']["name$language"] = $suggested["name$language"]; @@ -480,7 +486,7 @@ class ProcessPageClone extends Process { $cloneTree = false; // clone tree mode not allowed in ajax mode try { - $clone = $this->wire('pages')->clone($page, $page->parent, $cloneTree, $cloneOptions); + $clone = $this->wire()->pages->clone($page, $page->parent, $cloneTree, $cloneOptions); } catch(\Exception $e) { $error = $e->getMessage(); $clone = new NullPage(); diff --git a/wire/modules/Process/ProcessPageEdit/PageBookmarks.php b/wire/modules/Process/ProcessPageEdit/PageBookmarks.php index 76f82d39..0bc00630 100644 --- a/wire/modules/Process/ProcessPageEdit/PageBookmarks.php +++ b/wire/modules/Process/ProcessPageEdit/PageBookmarks.php @@ -22,10 +22,11 @@ class PageBookmarks extends Wire { protected $labels = array(); /** - * @param Process $process + * @param Process|ProcessPageEdit $process * */ public function __construct(Process $process) { + parent::__construct(); $this->process = $process; $this->labels = array( 'bookmarks' => $this->_('Bookmarks'), @@ -42,19 +43,23 @@ class PageBookmarks extends Wire { * */ public function initNavJSON(array $options = array()) { + + $pages = $this->wire()->pages; + $user = $this->wire()->user; + $modules = $this->wire()->modules; $bookmarkFields = array(); $bookmarksArray = array(); $rolesArray = array(); - $data = $this->wire('modules')->getModuleConfigData($this->process); + $data = $modules->getModuleConfigData($this->process); $iconKey = isset($options['iconKey']) ? $options['iconKey'] : '_icon'; $classKey = isset($options['classKey']) ? $options['classKey'] : '_class'; $options['classKey'] = $classKey; $options['iconKey'] = $iconKey; if(!isset($options['defaultIcon'])) $options['defaultIcon'] = 'arrow-circle-right'; - foreach($this->wire('user')->roles as $role) { - if($role->name == 'guest') continue; + foreach($this->wire()->user->roles as $role) { + if($role->name === 'guest') continue; $value = isset($data["bookmarks"]["_$role->id"]) ? $data["bookmarks"]["_$role->id"] : array(); if(empty($value)) continue; $bookmarkFields[$role->name] = $value; @@ -64,7 +69,7 @@ class PageBookmarks extends Wire { $n = 0; foreach($bookmarkFields as $name => $bookmarkIDs) { - $bookmarks = count($bookmarkIDs) ? $this->wire('pages')->getById($bookmarkIDs) : array(); + $bookmarks = count($bookmarkIDs) ? $pages->getById($bookmarkIDs) : array(); $role = isset($rolesArray[$name]) ? $rolesArray[$name] : null; foreach($bookmarks as $page) { if($this->process == 'ProcessPageEdit' && !$page->editable()) continue; @@ -81,14 +86,14 @@ class PageBookmarks extends Wire { } if(empty($options['add'])) { - if($this->wire('user')->isSuperuser()) { + if($user->isSuperuser()) { $options['add'] = 'bookmarks/?role=0'; $options['addLabel'] = $this->labels['bookmarks']; $options['addIcon'] = 'bookmark-o'; } else { $options['add'] = null; } - } else if($this->wire('user')->isSuperuser()) { + } else if($user->isSuperuser()) { $add = $this->wire(new WireData()); $add->set('_icon', 'bookmark-o'); $add->set('title', $this->labels['bookmarks']); @@ -108,7 +113,7 @@ class PageBookmarks extends Wire { if(!isset($options['iconKey'])) $options['iconKey'] = '_icon'; if(empty($options['edit'])) { - $options['edit'] = $this->wire('config')->urls->admin . 'page/edit/?id={id}'; + $options['edit'] = $this->wire()->config->urls->admin . 'page/edit/?id={id}'; } return $options; @@ -121,10 +126,11 @@ class PageBookmarks extends Wire { * */ public function listBookmarks() { - - $config = $this->wire('config'); - $config->styles->add($config->urls->ProcessPageEdit . 'PageBookmarks.css'); - $superuser = $this->wire('user')->isSuperuser(); + + $sanitizer = $this->wire()->sanitizer; + $config = $this->wire()->config; + $config->styles->add($config->urls('ProcessPageEdit') . 'PageBookmarks.css'); + $superuser = $this->wire()->user->isSuperuser(); $out = ''; $options = $this->initNavJSON(); $noneHeadline = $this->_('There are currently no bookmarks defined'); @@ -136,7 +142,7 @@ class PageBookmarks extends Wire { $icon = $item->_icon ? " " : ""; $out .= "
  • " . - "$icon" . $this->wire('sanitizer')->entities1($item->get('title|name')) . "" . + "$icon" . $sanitizer->entities1($item->get('title|name')) . "" . "
  • "; } @@ -148,7 +154,8 @@ class PageBookmarks extends Wire { } if($superuser) { - $button = $this->wire('modules')->get('InputfieldButton'); + /** @var InputfieldButton $button */ + $button = $this->wire()->modules->get('InputfieldButton'); $button->href = "./?role=0"; $button->value = $this->labels['edit-bookmarks']; $button->icon = 'edit'; @@ -168,17 +175,20 @@ class PageBookmarks extends Wire { */ public function editBookmarksForm() { - $modules = $this->wire('modules'); - $roleID = $this->wire('input')->get('role'); - if(is_null($roleID) && $this->wire('input')->get('id') == 'bookmarks') $roleID = 0; + $modules = $this->wire()->modules; + $input = $this->wire()->input; + $roles = $this->wire()->roles; + + $roleID = $input->get('role'); + if(is_null($roleID) && $input->get('id') === 'bookmarks') $roleID = 0; $roleID = (int) $roleID; - if(!$this->wire('user')->isSuperuser()) throw new WirePermissionException("Superuser required to define bookmarks"); + if(!$this->wire()->user->isSuperuser()) throw new WirePermissionException("Superuser required to define bookmarks"); $moduleInfo = $modules->getModuleInfo($this->process); $this->process->breadcrumb('../', $this->_($moduleInfo['title'])); $this->process->breadcrumb('./', $this->labels['bookmarks']); - $role = $roleID ? $this->wire('roles')->get($roleID) : $this->wire('pages')->newNullPage(); + $role = $roleID ? $roles->get($roleID) : $this->wire()->pages->newNullPage(); if($roleID && !$role->id) throw new WireException("Unknown role"); $allLabel = $this->_('everyone'); // All roles $data = $modules->getModuleConfigData($this->process); @@ -188,6 +198,7 @@ class PageBookmarks extends Wire { $this->process->headline($headline); $this->process->browserTitle($title); + /** @var InputfieldForm $form */ $form = $modules->get('InputfieldForm'); $form->action = "./?role=$role->id"; $form->addClass('InputfieldFormConfirm'); @@ -195,6 +206,7 @@ class PageBookmarks extends Wire { $form->appendMarkup = "


    " . $this->_('Note that only superusers are able to see this editor.') . "

    "; + /** @var InputfieldPageListSelectMultiple $field */ $field = $modules->get('InputfieldPageListSelectMultiple'); $field->attr('name', 'bookmarks'); $field->label = $title; @@ -205,8 +217,8 @@ class PageBookmarks extends Wire { $class = $role->id ? '' : 'ui-state-disabled'; $out = "