diff --git a/wire/core/Template.php b/wire/core/Template.php index 29c2354f..52c4326d 100644 --- a/wire/core/Template.php +++ b/wire/core/Template.php @@ -759,7 +759,7 @@ class Template extends WireData implements Saveable, Exportable { $fieldgroup = $this->wire()->fieldgroups->get($value); if($fieldgroup) { $this->setFieldgroup($fieldgroup); - } else { + } else if($this->id) { $this->error("Unable to load fieldgroup '$value' for template $this->name"); } return; diff --git a/wire/core/Templates.php b/wire/core/Templates.php index c2052cd9..443b86e6 100644 --- a/wire/core/Templates.php +++ b/wire/core/Templates.php @@ -573,6 +573,7 @@ class Templates extends WireSaveableItems { if($template->fieldgroup) $fieldgroupData = $template->fieldgroup->getExportData(); $data['fieldgroupFields'] = $fieldgroupData['fields']; $data['fieldgroupContexts'] = $fieldgroupData['contexts']; + unset($data['_lazy'], $data['_exportMode']); $template->set('_exportMode', false); return $data; diff --git a/wire/modules/Process/ProcessTemplate/ProcessTemplateExportImport.php b/wire/modules/Process/ProcessTemplate/ProcessTemplateExportImport.php index 491ac55d..10921b1d 100644 --- a/wire/modules/Process/ProcessTemplate/ProcessTemplateExportImport.php +++ b/wire/modules/Process/ProcessTemplate/ProcessTemplateExportImport.php @@ -10,11 +10,15 @@ class ProcessTemplateExportImport extends Wire { - /** @var Templates $items */ + /** + * @var Templates|Template[] $items + * + */ protected $items; - public function __construct() { - $this->items = $this->wire('templates'); + public function wired() { + parent::wired(); + $this->items = $this->wire()->templates; } protected function getItem($name) { @@ -35,7 +39,8 @@ class ProcessTemplateExportImport extends Wire { */ protected function getExportData(array $exportTemplates) { $data = array(); - foreach($this->wire('templates') as $template) { + foreach($this->items as $template) { + /** @var Template $template */ if(!in_array($template->name, $exportTemplates)) continue; $a = $template->getExportData(); $data[$template->name] = $a; @@ -46,30 +51,35 @@ class ProcessTemplateExportImport extends Wire { /** * Execute export * - * @return string + * @return InputfieldForm * */ public function ___buildExport() { - - $form = $this->wire('modules')->get('InputfieldForm'); + + $modules = $this->wire()->modules; + $input = $this->wire()->input; + + /** @var InputfieldForm $form */ + $form = $modules->get('InputfieldForm'); $form->action = './'; $form->method = 'post'; - $exportTemplates = $this->wire('input')->post('export_templates'); + $exportTemplates = $input->post('export_templates'); if(empty($exportTemplates)) { - $f = $this->wire('modules')->get('InputfieldSelectMultiple'); + /** @var InputfieldSelectMultiple $f */ + $f = $modules->get('InputfieldSelectMultiple'); $f->attr('id+name', 'export_templates'); $f->label = $this->_('Select the templates that you want to export'); $f->icon = 'copy'; - $maxName = 0; $maxLabel = 0; $numTemplates = 0; - foreach($this->wire('templates') as $template) { + foreach($this->items as $template) { + /** @var Template $template */ if(strlen($template->name) > $maxName) $maxName = strlen($template->name); $label = $template->getLabel(); if(strlen($label) > $maxLabel) $maxLabel = strlen($label); @@ -86,7 +96,7 @@ class ProcessTemplateExportImport extends Wire { $modified; $f->addOption(0, $label, array('disabled' => 'disabled')); - foreach($this->wire('templates') as $template) { + foreach($this->items as $template) { //if(!is_object($template->fieldgroup)) $this->error("Template: $template has no fieldgroup"); $templateName = $template->name . ' '; $templateLabel = $template->getLabel() . ' '; @@ -105,15 +115,16 @@ class ProcessTemplateExportImport extends Wire { $f->attr('size', $numTemplates+1); $form->add($f); - $f = $this->wire('modules')->get('InputfieldSubmit'); + /** @var InputfieldSubmit $f */ + $f = $modules->get('InputfieldSubmit'); $f->attr('name', 'submit_export'); $f->attr('value', $this->_x('Export', 'button')); $form->add($f); } else { - $form = $this->wire('modules')->get('InputfieldForm'); - $f = $this->wire('modules')->get('InputfieldTextarea'); + /** @var InputfieldTextarea $f */ + $f = $modules->get('InputfieldTextarea'); $f->attr('id+name', 'export_data'); $f->label = $this->_('Export Data'); $f->description = $this->_('Copy and paste this data into the "Import" box of another installation.'); @@ -121,7 +132,8 @@ class ProcessTemplateExportImport extends Wire { $f->attr('value', wireEncodeJSON($this->getExportData($exportTemplates), true, true)); $form->add($f); - $f = $this->wire('modules')->get('InputfieldButton'); + /** @var InputfieldButton $f */ + $f = $modules->get('InputfieldButton'); $f->href = './'; $f->value = $this->_x('Ok', 'button'); $form->add($f); @@ -173,18 +185,24 @@ class ProcessTemplateExportImport extends Wire { * */ public function ___buildImport() { + + $modules = $this->wire()->modules; + $session = $this->wire()->session; + $notices = $this->wire()->notices; + $input = $this->wire()->input; + $sanitizer = $this->wire()->sanitizer; - if($this->input->post('submit_commit')) { + if($input->post('submit_commit')) { $this->processImport(); return ''; } - $verify = (int) $this->input->get('verify'); + $verify = (int) $input->get('verify'); if($verify) { - $json = $this->session->get($this, 'importData'); + $json = $session->get($this, 'importData'); } else { - $json = $this->input->post('import_data'); + $json = $input->post('import_data'); } if(!$json) return $this->buildInputDataForm(); @@ -192,7 +210,7 @@ class ProcessTemplateExportImport extends Wire { if(!$data) throw new WireException("Invalid import data"); /** @var InputfieldForm $form */ - $form = $this->modules->get('InputfieldForm'); + $form = $modules->get('InputfieldForm'); $form->action = './'; $form->method = 'post'; $form->attr('id', 'import_form'); @@ -214,7 +232,6 @@ class ProcessTemplateExportImport extends Wire { $numErrors = 0; $numExistingTemplates = 0; $numNewTemplates = 0; - $notices = $this->wire('notices'); if(!$verify) $notices->removeAll(); @@ -224,16 +241,17 @@ class ProcessTemplateExportImport extends Wire { $postName = str_replace('-', '__', $name); unset($templateData['id']); $new = false; - $name = $this->wire('sanitizer')->name($name); - $template = $this->wire('templates')->get($name); + $name = $sanitizer->name($name); + $template = $this->items->get($name); $numChangesTemplate = 0; /** @var InputfieldFieldset $fieldset */ - $fieldset = $this->modules->get('InputfieldFieldset'); + $fieldset = $modules->get('InputfieldFieldset'); $fieldset->label = $name; $form->add($fieldset); if(!$template) { $new = true; + /** @var Template $template */ $template = $this->wire(new Template()); $template->name = $name; $fieldset->icon = 'sun-o'; @@ -243,7 +261,7 @@ class ProcessTemplateExportImport extends Wire { } /** @var InputfieldMarkup $markup */ - $markup = $this->modules->get('InputfieldMarkup'); + $markup = $modules->get('InputfieldMarkup'); $markup->addClass('InputfieldCheckboxes'); $markup->value = ""; $fieldset->add($markup); @@ -257,7 +275,8 @@ class ProcessTemplateExportImport extends Wire { $this->error($e->getMessage()); } - $f = $this->wire('modules')->get('InputfieldCheckboxes'); + /** @var InputfieldCheckboxes $f */ + $f = $modules->get('InputfieldCheckboxes'); $f->attr('name', "item_$postName"); $f->label = $this->_('Changes'); $f->table = true; @@ -266,6 +285,7 @@ class ProcessTemplateExportImport extends Wire { $f->thead .= $this->_('New Value'); foreach($changes as $property => $info) { + if($property === '_lazy' || $property === '_exportMode') continue; $oldValue = str_replace('|', ' ', $info['old']); $newValue = str_replace('|', ' ', $info['new']); @@ -289,12 +309,12 @@ class ProcessTemplateExportImport extends Wire { $errors = array(); foreach($notices as $notice) { if(!$notice instanceof NoticeError) continue; - $errors[] = $this->wire('sanitizer')->entities1($notice->text); + $errors[] = $sanitizer->entities1($notice->text); $notices->remove($notice); } if(count($errors)) { - $icon = ""; + $icon = wireIconMarkup('exclamation-triangle'); $markup->value .= "