diff --git a/wire/core/Fields.php b/wire/core/Fields.php index 484b64d8..951a29df 100644 --- a/wire/core/Fields.php +++ b/wire/core/Fields.php @@ -16,6 +16,7 @@ * @method bool deleteFieldDataByTemplate(Field $field, Template $template) #pw-hooker * @method void changedType(Saveable $item, Fieldtype $fromType, Fieldtype $toType) #pw-hooker * @method void changeTypeReady(Saveable $item, Fieldtype $fromType, Fieldtype $toType) #pw-hooker + * @method bool|Field clone(Field $item, $name = '') Clone a field and return it or return false on fail. * */ @@ -282,7 +283,7 @@ class Fields extends WireSaveableItems { /** * Create and return a cloned copy of the given Field - * + * * @param Field|Saveable $item Field to clone * @param string $name Optionally specify name for new cloned item * @return bool|Saveable $item Returns the new clone on success, or false on failure @@ -623,14 +624,14 @@ class Fields extends WireSaveableItems { if($success) { $this->message( - sprintf($this->_('Deleted field "%1$s" data in %2$d row(s) from %3$d page(s).'), - $field->name, $numRows, $numPages) . " [$deleteType]", + sprintf($this->_('Deleted field "%1$s" data in %2$d row(s) from %3$d page(s) using template "%4$s".'), + $field->name, $numRows, $numPages, $template->name) . " [$deleteType]", Notice::log ); } else { $this->error( - sprintf($this->_('Error deleting field "%1$s" data, %2$d row(s), %3$d page(s).'), - $field->name, $numRows, $numPages) . " [$deleteType]", + sprintf($this->_('Error deleting field "%1$s" data, %2$d row(s), %3$d page(s) using template "%4$s".'), + $field->name, $numRows, $numPages, $template->name) . " [$deleteType]", Notice::log ); } diff --git a/wire/core/PageAccess.php b/wire/core/PageAccess.php index 7da9e15e..cfe210ac 100644 --- a/wire/core/PageAccess.php +++ b/wire/core/PageAccess.php @@ -11,7 +11,13 @@ */ class PageAccess { - + + /** + * @var ProcessWire + * + */ + protected $wire; + /** * Allowed types for page access * @@ -43,7 +49,7 @@ class PageAccess { $permission = $this->wire('permissions')->get($name); $name = $permission ? $permission->name : 'edit'; } else if($name instanceof Permission) { - $name = $permission->name; + $name = $name->name; } if(strpos($name, 'page-') === 0) $name = str_replace('page-', '', $name); @@ -56,12 +62,13 @@ class PageAccess { * Returns the parent page that has the template from which we get our role/access settings from * * @param Page $page - * @param string Type, one of 'view', 'edit', 'create' or 'add' (default='view') + * @param string $type Type, one of 'view', 'edit', 'create' or 'add' (default='view') * @param int $level Recursion level for internal use only * @return Page|NullPage Returns NullPage if none found * */ public function getAccessParent(Page $page, $type = 'view', $level = 0) { + if(!$page->id) return $page->wire('pages')->newNullPage(); if(!in_array($type, $this->types)) $type = $this->getType($type); if($page->template->useRoles || $page->id === 1) { // found an access parent @@ -80,7 +87,7 @@ class PageAccess { * Returns the template from which we get our role/access settings from * * @param Page $page - * @param string Type, one of 'view', 'edit', 'create' or 'add' (default='view') + * @param string $type Type, one of 'view', 'edit', 'create' or 'add' (default='view') * @return Template|null Returns null if none * */ @@ -114,7 +121,7 @@ class PageAccess { * * @param Page $page * @param string|int|Role $role - * @param string Default is 'view', but you may specify 'create' or 'add' as well + * @param string $type Default is 'view', but you may specify 'create' or 'add' as well * @return bool * */ @@ -125,4 +132,43 @@ class PageAccess { if(is_int($role)) return $roles->has("id=$role"); return false; } + + /** + * Get or inject a ProcessWire API variable or fuel a new object instance + * + * See Wire::wire() for explanation of all options. + * + * @param string|WireFuelable $name Name of API variable to retrieve, set, or omit to retrieve entire Fuel object. + * @param null|mixed $value Value to set if using this as a setter, otherwise omit. + * @param bool $lock When using as a setter, specify true if you want to lock the value from future changes (default=false) + * @return mixed|Fuel + * @throws WireException + * + */ + public function wire($name = '', $value = null, $lock = false) { + if(!is_null($value)) return $this->wire->wire($name, $value, $lock); + else if($name instanceof WireFuelable && $this->wire) $name->setWire($this->wire); + else if($name) return $this->wire->wire($name); + return $this->wire; + } + + /** + * Set the ProcessWire instance + * + * @param ProcessWire $wire + * + */ + public function setWire(ProcessWire $wire) { + $this->wire = $wire; + } + + /** + * Get the ProcessWire instance + * + * @return ProcessWire + * + */ + public function getWire() { + return $this->wire; + } } diff --git a/wire/core/PageFinder.php b/wire/core/PageFinder.php index 3e869f09..f91fbbf1 100644 --- a/wire/core/PageFinder.php +++ b/wire/core/PageFinder.php @@ -2230,7 +2230,7 @@ class PageFinder extends Wire { * */ protected function isRepeaterFieldtype(Fieldtype $fieldtype) { - return strpos($fieldtype->className(), 'FieldtypeRepeater') !== false; + return wireInstanceOf($fieldtype, 'FieldtypeRepeater'); } } diff --git a/wire/core/PagesAccess.php b/wire/core/PagesAccess.php index c67e839a..363de11e 100644 --- a/wire/core/PagesAccess.php +++ b/wire/core/PagesAccess.php @@ -53,19 +53,25 @@ class PagesAccess extends Wire { */ public function __construct($item = null) { if(!$item) return; - if($item instanceof Page) $this->updatePage($item); - else if($item instanceof Template) $this->updateTemplate($template); + if($item instanceof Page) { + $this->updatePage($item); + } else if($item instanceof Template) { + $this->updateTemplate($item); + } } /** * Rebuild the entire pages_access table (or a part of it) starting from the given parent_id + * + * @param int $parent_id + * @param int $accessTemplateID + * @param bool $doDeletions * */ protected function rebuild($parent_id = 1, $accessTemplateID = 0, $doDeletions = true) { $insertions = array(); $deletions = array(); - $templates = $this->getTemplates(); $accessTemplates = $this->getAccessTemplates(); $parent_id = (int) $parent_id; $accessTemplateID = (int) $accessTemplateID; @@ -153,6 +159,8 @@ class PagesAccess extends Wire { * Update the pages_access table for the given Template * * To be called when a template's 'useRoles' property has changed. + * + * @param Template $template * */ public function updateTemplate(Template $template) { @@ -218,6 +226,8 @@ class PagesAccess extends Wire { /** * Delete a page from the pages_access table + * + * @param Page $page * */ public function deletePage(Page $page) { diff --git a/wire/modules/Fieldtype/FieldtypeFieldsetOpen.module b/wire/modules/Fieldtype/FieldtypeFieldsetOpen.module index b674a0e6..b6d75a86 100644 --- a/wire/modules/Fieldtype/FieldtypeFieldsetOpen.module +++ b/wire/modules/Fieldtype/FieldtypeFieldsetOpen.module @@ -108,6 +108,8 @@ class FieldtypeFieldsetOpen extends Fieldtype { } /** + * Is given field a fieldset opener? + * * For hooks to share in determining if this is a field they want to operate on * * @param Field $field diff --git a/wire/modules/Process/ProcessField/ProcessField.module b/wire/modules/Process/ProcessField/ProcessField.module index 2aefe08b..e706d33c 100644 --- a/wire/modules/Process/ProcessField/ProcessField.module +++ b/wire/modules/Process/ProcessField/ProcessField.module @@ -12,7 +12,33 @@ * https://processwire.com * * @property bool $listAfterSave - * @method bool allowFieldInTemplate(FIeld $field, Template $template) + * + * @method string execute() + * @method string executeAdd() + * @method string executeEdit() + * @method void executeSave() + * @method string executeChangeType() + * @method void executeSaveChangeType() + * @method void saveContext() + * @method bool allowFieldInTemplate(Field $field, Template $template) + * @method InputfieldForm getListFilterForm() + * @method MarkupAdminDataTable getListTable(array|Fields $fields) + * @method array getListTableRow(Field $field) + * @method InputfieldForm buildEditForm() + * @method buildEditFormContext(InputfieldForm $form) + * @method buildEditFormCustom(InputfieldForm $form) + * @method InputfieldWrapper buildEditFormDelete() + * @method InputfieldWrapper buildEditFormBasics() + * @method InputfieldWrapper buildEditFormInfo() + * @method InputfieldWrapper buildEditFormAdvanced() + * + * @method void fieldAdded(Field $field) + * @method void fieldSaved(Field $field) + * @method void fieldDeleted(Field $field) + * @method void fieldChangedType(Field $field) + * @method void fieldChangedContext(Field $field, Fieldgroup $fieldgroup, array $diffContextArray); + * + * @todo Update/improve tags entry * */ @@ -146,6 +172,9 @@ class ProcessField extends Process implements ConfigurableModule { * Output JSON list of navigation items for this (intended to for ajax use) * * For 2.5+ admin theme navigation + * + * @param array $options + * @return string|array * */ public function ___executeNavJSON(array $options = array()) { @@ -170,11 +199,13 @@ class ProcessField extends Process implements ConfigurableModule { $showAllLabel = $this->_('Show All'); + /** @var InputfieldForm $form */ $form = $this->modules->get("InputfieldForm"); $form->attr('id', 'field_filter_form'); $form->attr('method', 'get'); $form->attr('action', './'); + /** @var InputfieldFieldset $fieldset */ $fieldset = $this->modules->get("InputfieldFieldset"); $fieldset->attr('id', 'template_filters'); $fieldset->entityEncodeLabel = false; @@ -183,6 +214,7 @@ class ProcessField extends Process implements ConfigurableModule { $fieldset->collapsed = Inputfield::collapsedYes; $form->add($fieldset); + /** @var InputfieldSelect $field */ $field = $this->modules->get("InputfieldSelect"); $field->attr('id+name', 'templates_id'); $field->addOption('', $showAllLabel); @@ -208,6 +240,7 @@ class ProcessField extends Process implements ConfigurableModule { // ---------------------------------------------------------------- + /** @var InputfieldSelect $field */ $field = $this->modules->get("InputfieldSelect"); $field->attr('id+name', 'fieldtype'); $field->addOption('', $showAllLabel); @@ -230,6 +263,7 @@ class ProcessField extends Process implements ConfigurableModule { // ---------------------------------------------------------------- if(is_null($template) && !$this->session->ProcessFieldListFieldtype) { + /** @var InputfieldCheckbox $field */ $field = $this->modules->get("InputfieldCheckbox"); $field->attr('id+name', 'show_system'); $field->label = $this->_('Show built-in fields?'); @@ -348,10 +382,18 @@ class ProcessField extends Process implements ConfigurableModule { } return $out; - } + } + /** + * Get the table that lists fields + * + * @param array|Fields $fields + * @return MarkupAdminDataTable + * + */ protected function ___getListTable($fields) { + /** @var MarkupAdminDataTable $table */ $table = $this->modules->get("MarkupAdminDataTable"); $headerRow = array( @@ -378,6 +420,13 @@ class ProcessField extends Process implements ConfigurableModule { return $table; } + /** + * Get a table row (array) for placement in getListTable() + * + * @param Field $field + * @return array + * + */ protected function ___getListTableRow(Field $field) { $flagDefs = array( @@ -665,7 +714,7 @@ class ProcessField extends Process implements ConfigurableModule { $inputfield = $this->form->getChildByName($key); if(!$inputfield) continue; - if($key == 'field_label') $key == 'label'; // convert back + if($key == 'field_label') $key = 'label'; // convert back if($languageID) $key .= $languageID; if($value == $fieldOriginal->$key) continue; @@ -714,6 +763,9 @@ class ProcessField extends Process implements ConfigurableModule { /** * Build the Field Edit form + * + * @return InputfieldForm + * @throws WireException * */ protected function ___buildEditForm() { @@ -746,6 +798,7 @@ class ProcessField extends Process implements ConfigurableModule { foreach($this->wire('fields') as $field) $field->trackGets(true); } + /** @var InputfieldForm $form */ $form = $this->modules->get('InputfieldForm'); $form->attr('id+name', 'ProcessFieldEdit'); $form->attr('action', 'save'); @@ -767,7 +820,7 @@ class ProcessField extends Process implements ConfigurableModule { if($this->field->type) { $this->buildEditFormCustom($form); if(!$this->fieldgroup) { - $form->add($accessTab); + if($accessTab) $form->add($accessTab); $form->add($this->buildEditFormAdvanced()); } } @@ -777,12 +830,13 @@ class ProcessField extends Process implements ConfigurableModule { $this->buildEditFormContext($form); $form->add($this->buildEditFormDelete()); } else { - $form->add($accessTab); + if($accessTab) $form->add($accessTab); $this->buildEditFormContext($form); // $this->buildEditFormContextFieldgroup($form); } } + /** @var InputfieldHidden $field */ $field = $this->modules->get('InputfieldHidden'); $field->attr('name', 'id'); $field->attr('value', $this->field->id); @@ -806,7 +860,8 @@ class ProcessField extends Process implements ConfigurableModule { $form->add($field); } } - + + /** @var InputfieldSubmit $field */ $field = $this->modules->get('InputfieldSubmit'); $field->attr('value', $this->labels['save']); $field->attr('name', 'submit_save_field'); @@ -816,6 +871,7 @@ class ProcessField extends Process implements ConfigurableModule { if($this->wire('input')->get('process_template')) { // ProcessTemplate has loaded the field editor in a modal window // so we add a cancel button that asmSelect will recognize for it's modal + /** @var InputfieldButton $field */ $field = $this->modules->get('InputfieldButton'); $field->attr('id+name', 'modal_cancel_button'); $field->attr('value', $this->_x('Cancel', 'button')); @@ -823,6 +879,7 @@ class ProcessField extends Process implements ConfigurableModule { $form->append($field); // contains the asm list item status, populated by JS + /** @var InputfieldHidden $field */ $field = $this->modules->get('InputfieldHidden'); $field->attr('id+name', 'asmListItemStatus'); $field->attr('class', 'asmListItemStatus'); @@ -834,7 +891,13 @@ class ProcessField extends Process implements ConfigurableModule { return $form; } - + + /** + * Build field/template context edit + * + * @param InputfieldForm $form + * + */ protected function ___buildEditFormContext($form) { $allChanges = array(); @@ -937,6 +1000,8 @@ class ProcessField extends Process implements ConfigurableModule { /** * Add Fieldtype and Inputfield custom fields to the form + * + * @param InputfieldForm $form * */ protected function ___buildEditFormCustom($form) { @@ -967,7 +1032,7 @@ class ProcessField extends Process implements ConfigurableModule { if(!$this->field) return; $cls = __NAMESPACE__ . "\\FieldtypeFieldsetOpen"; - if($this->field instanceof $cls) return; + if($this->field->type instanceof $cls) return; $fieldset = $this->wire('modules')->get('InputfieldFieldset'); $fieldset->label = $this->_('Front-end editing'); @@ -989,6 +1054,7 @@ class ProcessField extends Process implements ConfigurableModule { } $file = $this->wire('config')->paths->PageFrontEdit . 'PageFrontEditConfig.php'; + /** @noinspection PhpIncludeInspection */ include_once($file); $moduleConfig = $this->wire(new PageFrontEditConfig()); $moduleConfig->fieldHelpInputfields($fieldset, $this->field); @@ -996,18 +1062,22 @@ class ProcessField extends Process implements ConfigurableModule { /** * Add a delete tab to the form + * + * @return InputfieldWrapper * */ protected function ___buildEditFormDelete() { $deleteLabel = $this->_('Delete field'); + /** @var InputfieldWrapper $form */ $form = $this->wire(new InputfieldWrapper()); $form->attr('id', 'delete'); $form->attr('class', 'WireTab'); //$form->head = $deleteLabel; $form->attr('title', $this->_x('Delete', 'tab')); + /** @var InputfieldCheckbox $field */ $field = $this->modules->get('InputfieldCheckbox'); $field->label = $deleteLabel; $field->icon = 'times-circle'; @@ -1028,25 +1098,29 @@ class ProcessField extends Process implements ConfigurableModule { /** * Basic field configuration options: name, type, label, description + * + * @return InputfieldWrapper * */ protected function ___buildEditFormBasics() { + /** @var InputfieldWrapper $form */ $form = $this->wire(new InputfieldWrapper()); $form->attr('id', 'basics'); $form->attr('class', 'WireTab'); $form->attr('title', $this->_x('Basics', 'tab')); - if($this->fieldgroup) { + // ok } else { - //$form->head = $this->_('Basic field settings'); + /** @var InputfieldName $field */ $field = $this->modules->get('InputfieldName'); $field->attr('value', $this->field->name); $field->description = $this->_("Use only ASCII letters (a-z A-Z), numbers (0-9) or underscores."); $form->add($field); + /** @var InputfieldSelect $field */ $field = $this->modules->get('InputfieldSelect'); $field->label = $this->_x('Type', 'select label'); // Label for field type select $field->attr('name', 'type'); @@ -1062,6 +1136,7 @@ class ProcessField extends Process implements ConfigurableModule { if($fieldtypes && count($fieldtypes)) { $fieldtypeLabels = array(); foreach($fieldtypes as $fieldtype) { + /** @var Fieldtype $fieldtype */ $label = $fieldtype->longName; if(isset($fieldtypeLabels[$label])) $label .= " ($fieldtype->name)"; $fieldtypeLabels[$label] = $fieldtype; @@ -1090,9 +1165,11 @@ class ProcessField extends Process implements ConfigurableModule { $form->add($field); } + /** @var Languages|null $languages */ $languages = $this->wire('languages'); $languageFields = array(); - + + /** @var InputfieldText $field */ $field = $this->modules->get('InputfieldText'); $field->attr('id+name', 'field_label'); $field->label = $this->_x('Label', 'text input'); // Label for 'field label' text input @@ -1102,6 +1179,7 @@ class ProcessField extends Process implements ConfigurableModule { $form->add($field); $languageFields[] = $field; + /** @var InputfieldTextarea $field */ $field = $this->modules->get('InputfieldTextarea'); $field->label = $this->_x('Description', 'textarea input'); // Label for the 'field description' textarea input $field->attr('name', 'description'); @@ -1138,15 +1216,19 @@ class ProcessField extends Process implements ConfigurableModule { /** * Build the 'Info' field shown in the Field Edit form + * + * @return InputfieldWrapper * */ protected function ___buildEditFormInfo() { + /** @var InputfieldWrapper $form */ $form = $this->wire(new InputfieldWrapper()); $form->attr('class', 'WireTab'); $form->attr('id', 'info'); $form->attr('title', $this->_x('Actions', 'tab')); - + + /** @var Templates $allTemplates */ $allTemplates = $this->wire('templates'); $inTemplates = array(); @@ -1154,6 +1236,7 @@ class ProcessField extends Process implements ConfigurableModule { if($template->fieldgroup->hasField($this->field)) $inTemplates[$template->id] = $template; } + /** @var InputfieldCheckboxes $field */ $field = $this->modules->get('InputfieldCheckboxes'); $field->attr('name', 'send_templates'); $field->label = $this->_('Add or remove field from templates'); @@ -1203,7 +1286,8 @@ class ProcessField extends Process implements ConfigurableModule { $form->add($field); // -------------------------- - + + /** @var InputfieldText $field */ $field = $this->modules->get("InputfieldText"); $field->attr('id+name', 'clone_field'); $field->attr('value', ''); @@ -1215,7 +1299,8 @@ class ProcessField extends Process implements ConfigurableModule { $form->append($field); // -------------------------- - + + /** @var InputfieldCheckbox $field */ $field = $this->modules->get('InputfieldCheckbox'); $field->attr('name', '_optimize'); $field->label = $this->_('Check field data'); @@ -1224,19 +1309,29 @@ class ProcessField extends Process implements ConfigurableModule { $field->collapsed = Inputfield::collapsedBlank; $form->add($field); - return $form; } - - protected function buildEditFormAccess() { + /** + * Build the "Access" tab for the field edit form, or null if not supported for Field + * + * @return InputfieldWrapper|null + * + */ + protected function buildEditFormAccess() { + + if($this->field->type instanceof FieldtypeFieldsetOpen) return null; + + /** @var Config $config */ $config = $this->wire('config'); + /** @var InputfieldWrapper $tab */ $tab = $this->wire(new InputfieldWrapper()); $tab->attr('class', 'WireTab'); $tab->attr('id', 'access'); $tab->attr('title', $this->_x('Access', 'tab')); + /** @var InputfieldRadios $f */ $f = $this->wire('modules')->get('InputfieldRadios'); $f->attr('name', 'useRoles'); $f->label = $this->_('Do you want to manage access control for this field?'); @@ -1248,6 +1343,7 @@ class ProcessField extends Process implements ConfigurableModule { $f->optionColumns = 1; $tab->add($f); + /** @var InputfieldMarkup $f */ $f = $this->modules->get("InputfieldMarkup"); $f->attr('id', '_roles_editor'); $f->showIf = 'useRoles=1'; @@ -1255,6 +1351,7 @@ class ProcessField extends Process implements ConfigurableModule { $f->description = $this->_('Users must also have page view or edit access on the page where the field exists before these permissions are applicable.'); // Access control description $f->notes = $this->_('When no boxes are checked, only superuser can view/edit the contents of the field.'); + /** @var MarkupAdminDataTable $table */ $table = $this->modules->get("MarkupAdminDataTable"); $table->setEncodeEntities(false); $table->headerRow(array( @@ -1270,6 +1367,7 @@ class ProcessField extends Process implements ConfigurableModule { $guestHasView = in_array($guestRole->id, $viewRoles); foreach($this->wire('roles') as $role) { + /** @var Role $role */ if($role->id == $config->superUserRolePageID) continue; $label = $role->name; $editable = $role->hasPermission('page-edit'); @@ -1286,6 +1384,7 @@ class ProcessField extends Process implements ConfigurableModule { $f->value = $table->render(); $tab->add($f); + /** @var InputfieldCheckboxes $f */ $f = $this->wire('modules')->get('InputfieldCheckboxes'); $f->attr('name', '_accessFlags'); $f->label = $this->_('Access toggles'); @@ -1309,6 +1408,8 @@ class ProcessField extends Process implements ConfigurableModule { /** * Build the 'Advanced' field shown in the Field Edit form + * + * @return InputfieldWrapper * */ protected function ___buildEditFormAdvanced() { @@ -1318,12 +1419,14 @@ class ProcessField extends Process implements ConfigurableModule { } else { $form = $this->wire(new InputfieldWrapper()); } - + + /** @var InputfieldWrapper $form */ $form->attr('id', 'advanced'); $form->attr('class', 'WireTab'); //$form->head = $this->_('Advanced options'); // Section header for 'Advanced' $form->attr('title', $this->_x('Advanced', 'tab')); + /** @var InputfieldIcon $field */ $field = $this->modules->get("InputfieldIcon"); $field->attr('name', 'icon'); $field->attr('value', $this->field->icon); @@ -1333,6 +1436,7 @@ class ProcessField extends Process implements ConfigurableModule { //$field->collapsed = Inputfield::collapsedBlank; $form->prepend($field); + /** @var InputfieldText $field */ $field = $this->modules->get("InputfieldText"); $field->attr('name', 'tags'); $field->attr('value', $this->field->tags); @@ -1359,7 +1463,11 @@ class ProcessField extends Process implements ConfigurableModule { $this->session->redirect("./"); } - if($this->fieldgroup) return $this->saveContext(); + if($this->fieldgroup) { + $this->saveContext(); + return ''; + } + $isNew = !$this->field->id; if($this->input->post->delete && $this->input->post->delete == $this->field->id && $this->field->numFieldgroups() == 0) { @@ -1368,7 +1476,7 @@ class ProcessField extends Process implements ConfigurableModule { $this->fields->delete($this->field); $this->fieldDeleted($this->field); $this->session->redirect("./"); - return; + return ''; } if($isNew) { @@ -1423,8 +1531,6 @@ class ProcessField extends Process implements ConfigurableModule { } else { - $optimized = false; - $removeKeys = $this->wire('input')->post('_remove_keys'); if($removeKeys && count($removeKeys)) { $_removeKeys = $this->wire('session')->get($this, '_remove_keys'); @@ -1433,7 +1539,6 @@ class ProcessField extends Process implements ConfigurableModule { $this->field->remove($xkey); $this->message(sprintf($this->_('Removed unused property: %s'), $xkey)); } - $optimized = true; } if($this->input->post('_remove_rows') == $this->field->id) { @@ -1447,7 +1552,6 @@ class ProcessField extends Process implements ConfigurableModule { $query->execute(); $cnt = $query->rowCount(); if($cnt) $this->message($this->field->name . ": " . sprintf($this->_('Deleted %d orphaned rows'), $cnt)); - $optimized = true; } $this->session->remove($this, 'optimize'); @@ -1526,6 +1630,8 @@ class ProcessField extends Process implements ConfigurableModule { if($this->wire('input')->post("_optimize")) $url .= '#alert'; $this->session->redirect($url); } + + return ''; } /** @@ -1726,6 +1832,8 @@ class ProcessField extends Process implements ConfigurableModule { /** * Executed when a field type change is requested and provides an informative confirmation form + * + * @return string * */ public function ___executeChangeType() { @@ -1740,12 +1848,14 @@ class ProcessField extends Process implements ConfigurableModule { $newType = $this->wire('fieldtypes')->get($newType); if(!$newType) $this->session->redirect('./'); + /** @var InputfieldForm $form */ $form = $this->modules->get("InputfieldForm"); $form->attr('method', 'post'); $form->attr('action', 'saveChangeType'); $form->head = sprintf($this->_('Change field type from "%1$s" to "%2$s"'), $this->field->type->longName, $newType->longName); $form->description = $this->_("Please note that changing the field type alters the database schema. If the new fieldtype is not compatible with the old, or if it contains a significantly different schema, it is possible for data loss to occur. As a result, you are advised to backup the database before completing a field type change."); // Change field type description + /** @var InputfieldCheckbox $f */ $f = $this->modules->get("InputfieldCheckbox"); $f->attr('name', 'confirm_type'); $f->attr('value', $newType->className()); @@ -1760,12 +1870,14 @@ class ProcessField extends Process implements ConfigurableModule { $f->attr('checked', 'checked'); $f->showIf = 'confirm_type=' . $newType->className(); $form->append($f); - + + /** @var InputfieldHidden $f */ $f = $this->modules->get("InputfieldHidden"); $f->attr('name', 'id'); $f->attr('value', $this->field->id); $form->append($f); + /** @var InputfieldSubmit $field */ $field = $this->modules->get('InputfieldSubmit'); $field->attr('name', 'submit_change_field_type'); $form->append($field); @@ -1819,8 +1931,12 @@ class ProcessField extends Process implements ConfigurableModule { $this->wire('breadcrumbs')->add(new Breadcrumb('../', $this->moduleInfo['title'])); require(dirname(__FILE__) . '/ProcessFieldExportImport.php'); + + /** @var ProcessFieldExportImport $o */ $o = $this->wire(new ProcessFieldExportImport()); + /** @var InputfieldForm $form */ $form = $o->buildImport(); + return $form->render(); } @@ -1836,8 +1952,11 @@ class ProcessField extends Process implements ConfigurableModule { $this->wire('breadcrumbs')->add(new Breadcrumb('../', $this->moduleInfo['title'])); require(dirname(__FILE__) . '/ProcessFieldExportImport.php'); + /** @var ProcessFieldExportImport $o */ $o = $this->wire(new ProcessFieldExportImport()); + /** @var InputfieldForm $form */ $form = $o->buildExport(); + return $form->render(); } @@ -2166,6 +2285,9 @@ class ProcessField extends Process implements ConfigurableModule { /** * Build a form allowing configuration of this Module + * + * @param array $data + * @return InputfieldWrapper * */ public function getModuleConfigInputfields(array $data) { @@ -2198,24 +2320,32 @@ class ProcessField extends Process implements ConfigurableModule { /** * For hooks to listen to when a new field is added + * + * @param Field $field * */ public function ___fieldAdded(Field $field) { } /** * For hooks to listen to when any field is saved + * + * @param Field $field * */ public function ___fieldSaved(Field $field) { } /** * For hooks to listen to when a field is deleted + * + * @param Field $field * */ public function ___fieldDeleted(Field $field) { } /** * For hooks to listen to when a field type changes + * + * @param Field $field * */ public function ___fieldChangedType(Field $field) { } @@ -2232,9 +2362,14 @@ class ProcessField extends Process implements ConfigurableModule { /** * For hooks to modify if they want to specific prevent a field from being added to a template from here + * + * @param Field $field + * @param Template $template + * @return bool * */ public function ___allowFieldInTemplate(Field $field, Template $template) { + if($field && $template) {} return true; } diff --git a/wire/modules/Process/ProcessField/ProcessFieldExportImport.php b/wire/modules/Process/ProcessField/ProcessFieldExportImport.php index 96523053..7b1d57b6 100644 --- a/wire/modules/Process/ProcessField/ProcessFieldExportImport.php +++ b/wire/modules/Process/ProcessField/ProcessFieldExportImport.php @@ -1,5 +1,18 @@ wire('modules')->get('InputfieldForm'); $form->action = './'; $form->method = 'post'; @@ -103,18 +117,20 @@ class ProcessFieldExportImport extends Wire { } /** - * Build Textarea input form to past JSON data into + * Build Textarea input form to pass JSON data into * * @return InputfieldForm * */ protected function ___buildInputDataForm() { - + + /** @var InputfieldForm $form */ $form = $this->modules->get('InputfieldForm'); $form->action = './'; $form->method = 'post'; $form->attr('id', 'import_form'); - + + /** @var InputfieldTextarea $f */ $f = $this->modules->get('InputfieldTextarea'); $f->attr('name', 'import_data'); $f->label = $this->_x('Import', 'button'); @@ -124,6 +140,7 @@ class ProcessFieldExportImport extends Wire { $f->notes = $this->_('Copy the export data from another installation and then paste into the box above with CTRL-V or CMD-V.'); $form->add($f); + /** @var InputfieldSubmit $f */ $f = $this->wire('modules')->get('InputfieldSubmit') ; $f->attr('name', 'submit_import'); $f->attr('value', $this->_('Preview')); @@ -135,13 +152,22 @@ class ProcessFieldExportImport extends Wire { /** * Execute import * - * @return string + * @return InputfieldForm * @throws WireException if given invalid import data * */ public function ___buildImport() { - - if($this->input->post('submit_commit')) return $this->processImport(); + + /** @var InputfieldForm $form */ + $form = $this->modules->get('InputfieldForm'); + $form->action = './'; + $form->method = 'post'; + $form->attr('id', 'import_form'); + + if($this->input->post('submit_commit')) { + $this->processImport(); + return $form; + } $verify = (int) $this->input->get('verify'); if($verify) { @@ -154,11 +180,6 @@ class ProcessFieldExportImport extends Wire { $data = is_array($json) ? $json : wireDecodeJSON($json); if(!$data) throw new WireException("Invalid import data"); - $form = $this->modules->get('InputfieldForm'); - $form->action = './'; - $form->method = 'post'; - $form->attr('id', 'import_form'); - $numChangesTotal = 0; $numErrors = 0; $numExistingFields = 0; @@ -175,6 +196,7 @@ class ProcessFieldExportImport extends Wire { $name = $this->wire('sanitizer')->fieldName($name); $field = $this->wire('fields')->get($name); $numChangesField = 0; + /** @var InputfieldFieldset $fieldset */ $fieldset = $this->modules->get('InputfieldFieldset'); $fieldset->label = $name; $form->add($fieldset); @@ -182,6 +204,7 @@ class ProcessFieldExportImport extends Wire { if(!$field) { $new = true; $field = new Field(); + $this->wire($field); $field->name = $name; $fieldset->icon = 'sun-o'; $fieldset->label .= " [" . $this->_('new') . "]"; @@ -189,6 +212,7 @@ class ProcessFieldExportImport extends Wire { $fieldset->icon = 'moon-o'; } + /** @var InputfieldMarkup $markup */ $markup = $this->modules->get('InputfieldMarkup'); $markup->addClass('InputfieldCheckboxes'); $markup->value = ""; @@ -199,9 +223,11 @@ class ProcessFieldExportImport extends Wire { $changes = $field->setImportData($fieldData); } catch(\Exception $e) { $this->error($e->getMessage()); + $changes = array(); } $field->setImportData($savedFieldData); // restore + /** @var InputfieldCheckboxes $f */ $f = $this->wire('modules')->get('InputfieldCheckboxes'); $f->attr('name', "field_$name"); $f->label = $this->_('Changes'); @@ -287,7 +313,8 @@ class ProcessFieldExportImport extends Wire { } else { $form->description = $this->_('Please review the changes below and commit them when ready. If there are any changes that you do not want applied, uncheck the boxes where appropriate.'); } - + + /** @var InputfieldSubmit $f */ $f = $this->modules->get('InputfieldSubmit'); $f->attr('name', 'submit_commit'); $f->attr('value', $this->_('Commit Changes')); diff --git a/wire/modules/Process/ProcessPageEditImageSelect/ProcessPageEditImageSelect.module b/wire/modules/Process/ProcessPageEditImageSelect/ProcessPageEditImageSelect.module index 81febd75..96ba1bf6 100644 --- a/wire/modules/Process/ProcessPageEditImageSelect/ProcessPageEditImageSelect.module +++ b/wire/modules/Process/ProcessPageEditImageSelect/ProcessPageEditImageSelect.module @@ -16,6 +16,9 @@ * @property string $alignRightClass Align right class (align_right recommended) * @property string $alignCenterClass Align center class (align_center recommended) * + * @method string execute() + * @method string executeEdit() + * */ class ProcessPageEditImageSelect extends Process implements ConfigurableModule { @@ -178,10 +181,10 @@ class ProcessPageEditImageSelect extends Process implements ConfigurableModule { // if $this->page is a repeater item (for example), $this->masterPage is page it lives on $p = null; - if(strpos($this->page->className(), 'Repeater') !== false) { + if(wireInstanceOf($this->page, 'RepeaterPage')) { /** @var RepeaterPage $p */ $p = $this->page; - while(strpos($p->className(), 'Repeater') !== false) { + while(wireInstanceOf($p, 'RepeaterPage')) { $p = $p->getForPage(); } } @@ -194,7 +197,7 @@ class ProcessPageEditImageSelect extends Process implements ConfigurableModule { if($this->page->id === $user->id && $fieldName && $this->wire('modules')->get('PagePermissions')->userFieldEditable($fieldName)) { // user editing allowed images field in their profile - } else if(strpos($this->page->className(), 'Repeater') !== false) { + } else if(wireInstanceOf($this->page, 'RepeaterPage')) { if(!$this->masterPage->editable()) { throw new WireException($this->labels['noAccess']); } @@ -318,9 +321,10 @@ class ProcessPageEditImageSelect extends Process implements ConfigurableModule { if(in_array($field->name, $skipFields)) continue; - if($field->type instanceof FieldtypeRepeater) { + if(wireInstanceOf($field->type, 'FieldtypeRepeater')) { // get images that are possibly in a repeater $repeaterValue = $page->get($field->name); + if($repeaterValue instanceof Page) $repeaterValue = array($repeaterValue); if($repeaterValue) foreach($repeaterValue as $p) { $images = $this->getImages($p, $p->fields, $level+1); if(!count($images)) continue; @@ -422,10 +426,12 @@ class ProcessPageEditImageSelect extends Process implements ConfigurableModule { } + /** @var InputfieldForm $form */ $form = $this->modules->get("InputfieldForm"); $form->action = "./"; $form->method = "get"; + /** @var InputfieldPageListSelect $field */ $field = $this->modules->get("InputfieldPageListSelect"); $field->label = $this->_("Images on Page:") . ' ' . $this->page->get("title") . " (" . $this->page->path . ")"; // Headline for page selection, precedes current page title/url $field->description = $this->_("If you would like to select images from another page, select the page below."); // Instruction on how to select another page diff --git a/wire/modules/Process/ProcessPageEditLink/ProcessPageEditLink.module b/wire/modules/Process/ProcessPageEditLink/ProcessPageEditLink.module index ffec62dd..00a89623 100644 --- a/wire/modules/Process/ProcessPageEditLink/ProcessPageEditLink.module +++ b/wire/modules/Process/ProcessPageEditLink/ProcessPageEditLink.module @@ -342,7 +342,7 @@ class ProcessPageEditLink extends Process implements ConfigurableModule { $page = $this->page; // As the link generator might be called in a repeater, we need to find the containing page $n = 0; - while(strpos($page->className(), 'Repeater') !== false && ++$n < 10) { + while(wireInstanceOf($page, 'RepeaterPage') && ++$n < 10) { /** @var RepeaterPage $page */ $page = $page->getForPage(); } @@ -371,7 +371,7 @@ class ProcessPageEditLink extends Process implements ConfigurableModule { if($value) foreach($page->get($field->name) as $file) { $files[$file->url] = $prefix . $field->getLabel() . ': ' . $file->basename; } - } else if(strpos($type->className(), 'FieldtypeRepeater') !== false) { + } else if(wireInstanceOf($type, 'FieldtypeRepeater')) { $value = $page->get($field->name); if($value) foreach($page->get($field->name) as $repeaterPage){ $files = array_merge($this->getFilesPage($repeaterPage, $field->getLabel() . ': '), $files);