From 03de771b531bd606d160ffcf9a9db040b5072f91 Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Fri, 12 Aug 2022 13:34:42 -0400 Subject: [PATCH] Various minor updates, mostly phpdoc related --- wire/core/InputfieldWrapper.php | 31 +++++--- .../InputfieldCommentsAdmin.module | 1 + .../Fieldtype/FieldtypeFieldsetOpen.module | 25 +++++-- .../Fieldtype/FieldtypeFieldsetTabOpen.module | 6 +- .../ProcessPageEdit/ProcessPageEdit.module | 73 +++++++++++-------- 5 files changed, 84 insertions(+), 52 deletions(-) diff --git a/wire/core/InputfieldWrapper.php b/wire/core/InputfieldWrapper.php index 9ed1b808..bfeda1b0 100644 --- a/wire/core/InputfieldWrapper.php +++ b/wire/core/InputfieldWrapper.php @@ -184,7 +184,6 @@ class InputfieldWrapper extends Inputfield implements \Countable, \IteratorAggre $columnWidthSpacing = is_null($columnWidthSpacing) ? 1 : (int) $columnWidthSpacing; if($columnWidthSpacing > 0) $this->set('columnWidthSpacing', $columnWidthSpacing); - $columnWidthSpacing = null; $settings = $config->InputfieldWrapper; if(is_array($settings)) { @@ -245,7 +244,7 @@ class InputfieldWrapper extends Inputfield implements \Countable, \IteratorAggre if(strpos($key, 'Inputfield') === 0 && strlen($key) > 10) { if($key === 'InputfieldWrapper') return $this->wire(new InputfieldWrapper()); $value = $this->wire()->modules->get($key); - if($value && $value instanceof Inputfield) return $value; + if($value instanceof Inputfield) return $value; if(wireClassExists($key)) return $this->wire(new $key()); $value = null; } @@ -318,7 +317,7 @@ class InputfieldWrapper extends Inputfield implements \Countable, \IteratorAggre $inputfield = $this->wire(new $typeName()); } - if(!$inputfield || !$inputfield instanceof Inputfield) { + if(!$inputfield instanceof Inputfield) { throw new WireException("Unknown Inputfield type: $typeName"); } @@ -535,11 +534,12 @@ class InputfieldWrapper extends Inputfield implements \Countable, \IteratorAggre * * #pw-group-manipulation * - * @param Inputfield|string $item Inputfield object or name + * @param Inputfield|string $key Inputfield object or name * @return $this * */ - public function remove($item) { + public function remove($key) { + $item = $key; if(!$item) return $this; if(!$item instanceof Inputfield) { if(!is_string($item)) return $this; @@ -716,6 +716,7 @@ class InputfieldWrapper extends Inputfield implements \Countable, \IteratorAggre } foreach($children as $inputfield) { + /** @var Inputfield $inputfield */ if($renderAjaxInputfield && $inputfield->attr('id') !== $renderAjaxInputfield && !$inputfield instanceof InputfieldWrapper) { @@ -1105,6 +1106,7 @@ class InputfieldWrapper extends Inputfield implements \Countable, \IteratorAggre if($inputfield instanceof InputfieldWrapper) { // load assets they will need foreach($inputfield->getAll() as $in) { + /** @var Inputfield $in */ $in->renderReady($inputfield, $renderValueMode); } } @@ -1130,7 +1132,7 @@ class InputfieldWrapper extends Inputfield implements \Countable, \IteratorAggre if(!$this->children) return $this; - foreach($this->children() as $key => $child) { + foreach($this->children() as $child) { /** @var Inputfield $child */ // skip over the field if it is not processable @@ -1238,6 +1240,7 @@ class InputfieldWrapper extends Inputfield implements \Countable, \IteratorAggre public function isEmpty() { $empty = true; foreach($this->children() as $child) { + /** @var Inputfield $child */ if(!$child->isEmpty()) { $empty = false; break; @@ -1261,6 +1264,7 @@ class InputfieldWrapper extends Inputfield implements \Countable, \IteratorAggre $a = array(); static $n = 0; foreach($this->children() as $child) { + /** @var Inputfield $child */ if($child instanceof InputfieldWrapper) { $a = array_merge($a, $child->getEmpty($required)); } else { @@ -1288,7 +1292,8 @@ class InputfieldWrapper extends Inputfield implements \Countable, \IteratorAggre */ public function getErrors($clear = false) { $errors = parent::getErrors($clear); - foreach($this->children() as $key => $child) { + foreach($this->children() as $child) { + /** @var Inputfield $child */ foreach($child->getErrors($clear) as $e) { $label = $child->getSetting('label'); $msg = $label ? $label : $child->attr('name'); @@ -1349,6 +1354,7 @@ class InputfieldWrapper extends Inputfield implements \Countable, \IteratorAggre // child by name $wrappers = array(); foreach($children as $f) { + /** @var Inputfield $f */ if($f->getAttribute('name') === $name) { $child = $f; break; @@ -1444,7 +1450,7 @@ class InputfieldWrapper extends Inputfield implements \Countable, \IteratorAggre * #pw-group-retrieval-and-traversal * * @param string $name - * @return Inputfield|null + * @return Inputfield|InputfieldWrapper|null * @since 3.0.172 * */ @@ -1461,13 +1467,14 @@ class InputfieldWrapper extends Inputfield implements \Countable, \IteratorAggre * * @param string $attrName Attribute to match, such as 'id', 'name', 'value', etc. * @param string $attrValue Attribute value to match - * @return Inputfield|null + * @return Inputfield|InputfieldWrapper|null * @since 3.0.196 * */ public function getByAttr($attrName, $attrValue) { $inputfield = null; foreach($this->children() as $child) { + /** @var Inputfield $child */ if($child->getAttribute($attrName) === $attrValue) { $inputfield = $child; } else if($child instanceof InputfieldWrapper) { @@ -1486,7 +1493,7 @@ class InputfieldWrapper extends Inputfield implements \Countable, \IteratorAggre * Inputfield cannot be found. * * @param string $name - * @return string|int|float|bool|array|object|null + * @return array|float|int|object|Wire|WireArray|WireData|string|null * @since 3.0.172 * */ @@ -1532,7 +1539,7 @@ class InputfieldWrapper extends Inputfield implements \Countable, \IteratorAggre * * @param array $options Options to modify behavior (3.0.169+) * - `withWrappers` (bool): Also include InputfieldWrapper objects? (default=false) 3.0.169+ - * @return InputfieldWrapper|InputfieldsArray + * @return InputfieldsArray * */ public function getAll(array $options = array()) { @@ -1803,6 +1810,7 @@ class InputfieldWrapper extends Inputfield implements \Countable, \IteratorAggre public function populateValues($data) { $populated = array(); foreach($this->getAll() as $inputfield) { + /** @var Inputfield $inputfield */ if($inputfield instanceof InputfieldWrapper) continue; $name = $inputfield->attr('name'); if(!$name) continue; @@ -1836,6 +1844,7 @@ class InputfieldWrapper extends Inputfield implements \Countable, \IteratorAggre public function debugMap() { $a = array(); foreach($this as $in) { + /** @var Inputfield $in */ $info = array( 'id' => $in->id, 'name' => $in->name, diff --git a/wire/modules/Fieldtype/FieldtypeComments/InputfieldCommentsAdmin.module b/wire/modules/Fieldtype/FieldtypeComments/InputfieldCommentsAdmin.module index 35a07c7f..19169a4e 100644 --- a/wire/modules/Fieldtype/FieldtypeComments/InputfieldCommentsAdmin.module +++ b/wire/modules/Fieldtype/FieldtypeComments/InputfieldCommentsAdmin.module @@ -38,6 +38,7 @@ class InputfieldCommentsAdmin extends Inputfield implements InputfieldItemList { public function init() { parent::init(); + require_once(__DIR__ . '/FieldtypeComments.module'); if($this->wire()->modules->isInstalled('ProcessCommentsManager')) { $this->commentsManagerUrl = $this->wire()->config->urls->admin . 'setup/comments/'; } diff --git a/wire/modules/Fieldtype/FieldtypeFieldsetOpen.module b/wire/modules/Fieldtype/FieldtypeFieldsetOpen.module index c819cd37..f5ed2493 100644 --- a/wire/modules/Fieldtype/FieldtypeFieldsetOpen.module +++ b/wire/modules/Fieldtype/FieldtypeFieldsetOpen.module @@ -62,6 +62,7 @@ class FieldtypeFieldsetOpen extends Fieldtype { } public function getInputfield(Page $page, Field $field) { + /** @var InputfieldFieldsetOpen $inputfield */ $inputfield = $this->wire(new InputfieldFieldsetOpen()); $inputfield->class = $this->className() . ' InputfieldFieldset'; return $inputfield; @@ -86,7 +87,7 @@ class FieldtypeFieldsetOpen extends Fieldtype { public function ___getCompatibleFieldtypes(Field $field) { $fieldtypes = $this->wire(new Fieldtypes()); - foreach($this->wire('fieldtypes') as $fieldtype) { + foreach($this->wire()->fieldtypes as $fieldtype) { if($fieldtype instanceof FieldtypeFieldsetOpen) $fieldtypes->add($fieldtype); } return $fieldtypes; @@ -126,9 +127,11 @@ class FieldtypeFieldsetOpen extends Fieldtype { list($openers, $closers, $isChanged) = array(array(), array(), false); foreach($fieldgroup as $field) { + /** @var Field $field */ /** @var Fieldtype $fieldtype */ - if(!$field->type instanceof FieldtypeFieldsetOpen) continue; - if($field->type instanceof FieldtypeFieldsetClose) { + $fieldtype = $field->type; + if(!$fieldtype instanceof FieldtypeFieldsetOpen) continue; + if($fieldtype instanceof FieldtypeFieldsetClose) { if(!strpos($field->name, self::fieldsetCloseIdentifier)) continue; $name = substr($field->name, 0, -1 * strlen(self::fieldsetCloseIdentifier)); $closers[$name] = $field; @@ -178,18 +181,21 @@ class FieldtypeFieldsetOpen extends Fieldtype { public function getFieldsetCloseField(Field $field, $createIfNotExists = false) { if(!$this->isFieldset($field)) return null; - + + $fields = $this->wire()->fields; + $name = $field->name . self::fieldsetCloseIdentifier; - $closer = $this->wire('fields')->get($name); + $closer = $fields->get($name); if(!$closer) { $closeFieldID = (int) $field->get('closeFieldID'); if($closeFieldID) { - $closer = $this->wire('fields')->get($closeFieldID); + $closer = $fields->get($closeFieldID); } } if(!$closer && $createIfNotExists) { + /** @var Field $closer */ $closer = $this->wire(new Field()); $closer->type = $this->wire(new FieldtypeFieldsetClose()); $closer->name = $name; @@ -221,13 +227,16 @@ class FieldtypeFieldsetOpen extends Fieldtype { if(!$field->type instanceof FieldtypeFieldsetClose) return null; if(!strpos($field->name, self::fieldsetCloseIdentifier)) return null; + + $fields = $this->wire()->fields; $name = substr($field->name, 0, -1 * strlen(self::fieldsetCloseIdentifier)); - $opener = $this->wire()->fields->get($name); + $opener = $fields->get($name); if($opener) return $opener; - foreach($this->wire()->fields as $f) { + foreach($fields as $f) { + /** @var Field $f */ if(!$f->type instanceof FieldtypeFieldsetOpen) continue; $closeFieldID = (int) $f->get('closeFieldID'); if($closeFieldID != $field->id) continue; diff --git a/wire/modules/Fieldtype/FieldtypeFieldsetTabOpen.module b/wire/modules/Fieldtype/FieldtypeFieldsetTabOpen.module index d156011c..37426a08 100644 --- a/wire/modules/Fieldtype/FieldtypeFieldsetTabOpen.module +++ b/wire/modules/Fieldtype/FieldtypeFieldsetTabOpen.module @@ -28,7 +28,8 @@ class InputfieldFieldsetTabOpen extends InputfieldFieldsetOpen { $in = $inputfields->getChildByName('columnWidth'); if($in) $inputfields->remove($in); - + + /** @var InputfieldSelect $in */ $in = $inputfields->getChildByName('collapsed'); //if($in->parent) $in->parent->set('collapsed', Inputfield::collapsedYes); if($in) { @@ -73,7 +74,8 @@ class FieldtypeFieldsetTabOpen extends FieldtypeFieldsetOpen { public function ___getConfigInputfields(Field $field) { $inputfields = parent::___getConfigInputfields($field); - $in = $this->wire('modules')->get('InputfieldCheckbox'); + /** @var InputfieldCheckbox $in */ + $in = $this->wire()->modules->get('InputfieldCheckbox'); $in->attr('name', 'modal'); $in->label = $this->_('Open in modal window?'); $in->description = $this->_('Check the box to make this tab open in its own modal window. This can improve performance with large forms.'); diff --git a/wire/modules/Process/ProcessPageEdit/ProcessPageEdit.module b/wire/modules/Process/ProcessPageEdit/ProcessPageEdit.module index 01ff4a63..ba84f3a1 100644 --- a/wire/modules/Process/ProcessPageEdit/ProcessPageEdit.module +++ b/wire/modules/Process/ProcessPageEdit/ProcessPageEdit.module @@ -549,7 +549,7 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod $this->page->name = ''; } - $adminTheme = $this->wire('adminTheme'); + $adminTheme = $this->wire()->adminTheme; if($adminTheme) { $className = $this->className(); $adminTheme->addBodyClass("$className-id-{$this->page->id}"); @@ -848,7 +848,7 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod ); if($this->field) { $numFields = count($this->fields); - if($numFields == 1 && $this->field) { + if($numFields === 1) { $defaults['field'] = $this->field->name; } else if($numFields > 1) { $defaults['fields'] = implode(',', array_keys($this->fields)); @@ -908,6 +908,7 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod 'flat' => true, ); foreach($this->page->getInputfields($options) as $inputfield) { + /** @var Inputfield $inputfield */ if(!$this->page->editable($field->name, false)) continue; $skipCollapsed = array( Inputfield::collapsedHidden, @@ -963,7 +964,6 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod } } $contentTab->insertBefore($tab, $inputfield); - /** @var InputfieldFieldsetClose $tabClose */ $tabClose = new InputfieldFieldsetClose(); $this->wire($tabClose); $tabClose->attr('id+name', $tab->attr('name') . '_END'); @@ -971,6 +971,7 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod } foreach($contentTab as $inputfield) { + /** @var Inputfield $inputfield */ if(!$tabOpen && $inputfield->className() === 'InputfieldFieldsetTabOpen') { // open new tab $showable = $this->isTrash ? 'editable' : 'viewable'; @@ -993,7 +994,7 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod $contentTab->remove($inputfield); if(!$tabViewable) continue; - if($inputfield->modal) { + if($inputfield->getSetting('modal')) { $href = $this->getEditUrl(array('field' => $inputfield->name, 'modal' => 1)); $this->addTab($tabOpen->id, "masterPage ? $this->masterPage : $this->page; - $wrapper = $this->wire(new InputfieldWrapper()); + $wrapper = $this->wire(new InputfieldWrapper()); /** @var InputfieldWrapper $wrapper */ $id = $this->className() . 'Children'; $wrapper->attr('id+name', $id); if(!empty($this->configSettings['ajaxChildren'])) $wrapper->collapsed = Inputfield::collapsedYesAjax; @@ -1202,10 +1203,14 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod */ public static function buildFormSortfield($sortfield, Process $caller) { - $fieldset = $caller->wire('modules')->get("InputfieldFieldset"); + $modules = $caller->wire()->modules; + + /** @var InputfieldFieldset $fieldset */ + $fieldset = $modules->get("InputfieldFieldset"); if(!$sortfield) $fieldset->collapsed = Inputfield::collapsedYes; - $field = $caller->wire('modules')->get('InputfieldSelect'); + /** @var InputfieldSelect $field */ + $field = $modules->get('InputfieldSelect'); $field->name = 'sortfield'; $field->value = ltrim($sortfield, '-'); $field->columnWidth = 60; @@ -1222,7 +1227,7 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod 'modified' => 'modified', 'created' => 'created', 'published' => 'published', - ); + ); $field->addOption(__('Native Fields', __FILE__), $options); // Optgroup label for sorting by fields native to ProcessWire @@ -1241,7 +1246,8 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod $field->addOption(__('Custom Fields', __FILE__), $customOptions); // Optgroup label for sorting by custom fields $fieldset->append($field); - $f = $caller->wire('modules')->get('InputfieldCheckbox'); + /** @var InputfieldCheckbox $f */ + $f = $modules->get('InputfieldCheckbox'); $f->value = 1; $f->attr('id+name', 'sortfield_reverse'); $f->label = __('Reverse sort direction?', __FILE__); // Checkbox labe to reverse the sort direction @@ -1251,6 +1257,7 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod $f->columnWidth = 40; $fieldset->append($f); + return $fieldset; } @@ -1444,6 +1451,7 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod $f->parent_id = $this->config->usersPageID; $f->showPath = false; } else { + /** @var InputfieldInteger $f */ $f = $modules->get('InputfieldInteger'); $f->description = $this->_('Enter the created user’s ID.'); $f->notes = "{$this->page->created_users_id} = {$this->page->createdUser->name}"; @@ -1527,6 +1535,7 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod $modules = $this->modules; $sanitizer = $this->sanitizer; $languages = $this->wire()->languages; + $pages = $this->wire()->pages; if($this->isPost && $input->post('_prevpath_add') === null) return null; if(!$modules->isInstalled('PagePathHistory')) return null; @@ -1601,7 +1610,7 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod $table->headerRow($header); - foreach($data as $n => $item) { + foreach($data as /*$n =>*/ $item) { $id = md5($item['path'] . $item['date']); $path = $item['path']; @@ -1638,7 +1647,7 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod $row[] = "
" . $delete->render() . "
"; } else { $parentLabel = $this->_x('Parent', 'prev-path-parent'); - $parent = $this->wire('pages')->get((int) $item['virtual']); + $parent = $pages->get((int) $item['virtual']); if($parent->id) $parentLabel = "
$parentLabel"; $row[] = $parentLabel; } @@ -1789,9 +1798,11 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod */ protected function ___buildFormDelete() { + /** @var InputfieldWrapper $wrapper */ $wrapper = $this->wire(new InputfieldWrapper()); $deleteable = $this->page->deleteable(); $trashable = $deleteable || $this->page->trashable(); + if(!$trashable) return $wrapper; $id = $this->className() . 'Delete'; @@ -1800,26 +1811,24 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod $wrapper->attr('title', $deleteLabel); $this->addTab($id, $deleteLabel, $wrapper); - if($trashable) { + /** @var InputfieldCheckbox $field */ + $field = $this->modules->get('InputfieldCheckbox'); + $field->attr('id+name', 'delete_page'); + $field->attr('value', $this->page->id); - /** @var InputfieldCheckbox $field */ - $field = $this->modules->get('InputfieldCheckbox'); - $field->attr('id+name', 'delete_page'); - $field->attr('value', $this->page->id); - - if($deleteable && ($this->isTrash || $this->page->template->noTrash)) { - $deleteLabel = $this->_('Delete Permanently'); // Delete permanently checkbox label - } else { - $deleteLabel = $this->_('Move to Trash'); // Move to trash checkbox label - } - $field->icon = 'trash-o'; - $field->label = $deleteLabel; - $field->description = $this->_('Check the box to confirm that you want to do this.'); // Delete page confirmation instruction - $field->label2 = $this->_('Confirm'); - $wrapper->append($field); + if($deleteable && ($this->isTrash || $this->page->template->noTrash)) { + $deleteLabel = $this->_('Delete Permanently'); // Delete permanently checkbox label + } else { + $deleteLabel = $this->_('Move to Trash'); // Move to trash checkbox label } + $field->icon = 'trash-o'; + $field->label = $deleteLabel; + $field->description = $this->_('Check the box to confirm that you want to do this.'); // Delete page confirmation instruction + $field->label2 = $this->_('Confirm'); + $wrapper->append($field); if(count($wrapper->children())) { + /** @var InputfieldButton $field */ $field = $this->modules->get('InputfieldButton'); $field->attr('id+name', 'submit_delete'); $field->value = $deleteLabel; @@ -1942,9 +1951,10 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod if(count($roles)) { - $hasPublishPermission = $this->wire('permissions')->has('page-publish'); + $hasPublishPermission = $this->wire()->permissions->has('page-publish'); foreach($roles as $role) { + /** @var Role $role */ $permissions = array(); $roleName = $role->name; @@ -2588,6 +2598,7 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod $changes = array(); foreach($form->children() as $inputfield) { + /** @var Inputfield $inputfield */ $name = $inputfield->attr('name'); if($languages && $inputfield->getSetting('useLanguages')) { $v = $page->get($name); @@ -2719,6 +2730,7 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod $f->label = $labelConfirm; $list = array(); foreach($this->page->template->fieldgroup as $field) { + /** @var Field $field */ if(!$template->fieldgroup->has($field)) { $list[] = $this->sanitizer->entities($field->getLabel()) . " ($field->name)"; } @@ -2879,7 +2891,7 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod protected function isAllowedTemplate($id) { // if $id is a template, then convert it to it's numeric ID - if(is_object($id) && $id instanceof Template) $id = $id->id; + if($id instanceof Template) $id = $id->id; $id = (int) $id; @@ -3273,7 +3285,7 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod * URL to redirect to after non-authenticated user is logged-in, or false if module does not support * * @param Page $page - * @return bool|string + * @return string * @sine 3.0.167 * */ @@ -3334,7 +3346,6 @@ class ProcessPageEdit extends Process implements WirePageEditor, ConfigurableMod $f->addOption($name, $label); } - /** @var array $configData */ $configData = $config->pageEdit; if(isset($data['viewAction'])) { $f->attr('value', $data['viewAction']);