1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-12 17:54:44 +02:00

Minor updates to ProcessTemplate, with the most noticable addition being that when you add one (1) new template, it now goes straight to edit the template, rather than back to the template list.

This commit is contained in:
Ryan Cramer
2022-11-18 15:21:30 -05:00
parent b0d5f14a27
commit c36adc9397

View File

@@ -121,7 +121,7 @@ class ProcessTemplate extends Process implements ConfigurableModule {
$jQueryUI = $modules->get('JqueryUI'); $jQueryUI = $modules->get('JqueryUI');
$jQueryUI->use('modal'); $jQueryUI->use('modal');
return parent::init(); parent::init();
} }
/** /**
@@ -261,6 +261,7 @@ class ProcessTemplate extends Process implements ConfigurableModule {
$button->showInHeader(); $button->showInHeader();
$out .= $button->render(); $out .= $button->render();
/** @var InputfieldButton $button */
$button = $modules->get('InputfieldButton'); $button = $modules->get('InputfieldButton');
$button->id = 'tags_button'; $button->id = 'tags_button';
$button->href = './tags/'; $button->href = './tags/';
@@ -268,6 +269,7 @@ class ProcessTemplate extends Process implements ConfigurableModule {
$button->value = $this->labels['manageTags']; $button->value = $this->labels['manageTags'];
$out .= $button->render(); $out .= $button->render();
/** @var InputfieldButton $button */
$button = $modules->get('InputfieldButton'); $button = $modules->get('InputfieldButton');
$button->id = 'import_button'; $button->id = 'import_button';
$button->href = "./import/"; $button->href = "./import/";
@@ -276,6 +278,7 @@ class ProcessTemplate extends Process implements ConfigurableModule {
$button->setSecondary(); $button->setSecondary();
$out .= $button->render(); $out .= $button->render();
/** @var InputfieldButton $button */
$button = $modules->get('InputfieldButton'); $button = $modules->get('InputfieldButton');
$button->id = 'export_button'; $button->id = 'export_button';
$button->href = "./export/"; $button->href = "./export/";
@@ -397,6 +400,7 @@ class ProcessTemplate extends Process implements ConfigurableModule {
$rows = array(); $rows = array();
foreach($templates as $template) { foreach($templates as $template) {
/** @var Template $template */
$label = $template->getLabel(); $label = $template->getLabel();
if($label && $label != $template->name) { if($label && $label != $template->name) {
$useLabels = true; $useLabels = true;
@@ -622,6 +626,8 @@ class ProcessTemplate extends Process implements ConfigurableModule {
} }
} }
$addedTemplates = array();
foreach($postTemplates as $basename) { foreach($postTemplates as $basename) {
$basename = $sanitizer->name($basename); $basename = $sanitizer->name($basename);
@@ -641,6 +647,7 @@ class ProcessTemplate extends Process implements ConfigurableModule {
$template->save(); $template->save();
$this->message(sprintf($this->_('Added template and fieldgroup: %s'), $basename)); $this->message(sprintf($this->_('Added template and fieldgroup: %s'), $basename));
$addedTemplates[] = $template;
} catch(\Exception $e) { } catch(\Exception $e) {
$this->error($e->getMessage()); $this->error($e->getMessage());
@@ -660,7 +667,14 @@ class ProcessTemplate extends Process implements ConfigurableModule {
} }
} }
if(count($addedTemplates) === 1) {
// redirect to edit template when only one has been added
/** @var Template $template */
$template = reset($addedTemplates);
$session->redirect($template->editUrl());
} else {
$session->redirect('./'); $session->redirect('./');
}
return ''; // never reached return ''; // never reached
} }
@@ -747,7 +761,7 @@ class ProcessTemplate extends Process implements ConfigurableModule {
} }
$min = $config->debug ? '' : '.min'; $min = $config->debug ? '' : '.min';
$config->scripts->add($config->urls->ProcessTemplate . "ProcessTemplateFieldCreator$min.js?v=1"); $config->scripts->add($config->urls('ProcessTemplate') . "ProcessTemplateFieldCreator$min.js?v=1");
$label = $this->template->getLabel(); $label = $this->template->getLabel();
if(!$label) $label = $this->template->name; if(!$label) $label = $this->template->name;
@@ -796,6 +810,7 @@ class ProcessTemplate extends Process implements ConfigurableModule {
$this->buildEditFormBasics($template, $t); $this->buildEditFormBasics($template, $t);
$form->add($t); $form->add($t);
/** @var InputfieldWrapper $t */
$t = $this->wire(new InputfieldWrapper()); $t = $this->wire(new InputfieldWrapper());
$t->attr('title', $this->_x('Access', 'tab')); $t->attr('title', $this->_x('Access', 'tab'));
$t->attr('id', 'tab_access'); $t->attr('id', 'tab_access');
@@ -806,6 +821,7 @@ class ProcessTemplate extends Process implements ConfigurableModule {
$t->add($this->buildEditFormAccessFiles($template)); $t->add($this->buildEditFormAccessFiles($template));
$form->add($t); $form->add($t);
/** @var InputfieldWrapper $t */
$t = $this->wire(new InputfieldWrapper()); $t = $this->wire(new InputfieldWrapper());
$t->attr('title', $this->_x('Family', 'tab')); $t->attr('title', $this->_x('Family', 'tab'));
$t->attr('class', 'WireTab'); $t->attr('class', 'WireTab');
@@ -813,6 +829,7 @@ class ProcessTemplate extends Process implements ConfigurableModule {
$t->add($this->buildEditFormFamily($template)); $t->add($this->buildEditFormFamily($template));
$form->add($t); $form->add($t);
/** @var InputfieldWrapper $t */
$t = $this->wire(new InputfieldWrapper()); $t = $this->wire(new InputfieldWrapper());
$t->attr('title', $this->_x('URLs', 'tab')); $t->attr('title', $this->_x('URLs', 'tab'));
$t->attr('class', 'WireTab'); $t->attr('class', 'WireTab');
@@ -820,6 +837,7 @@ class ProcessTemplate extends Process implements ConfigurableModule {
$t->add($this->buildEditFormURLs($template)); $t->add($this->buildEditFormURLs($template));
$form->add($t); $form->add($t);
/** @var InputfieldWrapper $t */
$t = $this->wire(new InputfieldWrapper()); $t = $this->wire(new InputfieldWrapper());
$t->attr('title', $this->_x('Files', 'tab')); $t->attr('title', $this->_x('Files', 'tab'));
$t->attr('class', 'WireTab'); $t->attr('class', 'WireTab');
@@ -827,6 +845,7 @@ class ProcessTemplate extends Process implements ConfigurableModule {
$t->add($this->buildEditFormFile($template)); $t->add($this->buildEditFormFile($template));
$form->add($t); $form->add($t);
/** @var InputfieldWrapper $t */
$t = $this->wire(new InputfieldWrapper()); $t = $this->wire(new InputfieldWrapper());
$t->attr('title', $this->_x('Cache', 'tab')); $t->attr('title', $this->_x('Cache', 'tab'));
$t->attr('class', 'WireTab'); $t->attr('class', 'WireTab');
@@ -834,6 +853,7 @@ class ProcessTemplate extends Process implements ConfigurableModule {
$t->add($this->buildEditFormCache($template)); $t->add($this->buildEditFormCache($template));
$form->add($t); $form->add($t);
/** @var InputfieldWrapper $t */
$t = $this->wire(new InputfieldWrapper()); $t = $this->wire(new InputfieldWrapper());
$t->attr('title', $this->_x('Advanced', 'tab')); $t->attr('title', $this->_x('Advanced', 'tab'));
$t->attr('class', 'WireTab'); $t->attr('class', 'WireTab');
@@ -842,6 +862,7 @@ class ProcessTemplate extends Process implements ConfigurableModule {
$form->add($t); $form->add($t);
if($config->advanced) { if($config->advanced) {
/** @var InputfieldWrapper $t */
$t = $this->wire(new InputfieldWrapper()); $t = $this->wire(new InputfieldWrapper());
$t->attr('title', $this->_x('System', 'tab')); $t->attr('title', $this->_x('System', 'tab'));
$t->attr('class', 'WireTab'); $t->attr('class', 'WireTab');
@@ -850,6 +871,7 @@ class ProcessTemplate extends Process implements ConfigurableModule {
$form->add($t); $form->add($t);
} }
/** @var InputfieldWrapper $t */
$t = $this->wire(new InputfieldWrapper()); $t = $this->wire(new InputfieldWrapper());
$t->attr('class', 'WireTab'); $t->attr('class', 'WireTab');
$t->attr('title', $this->_x('Actions', 'tab')); $t->attr('title', $this->_x('Actions', 'tab'));
@@ -1072,6 +1094,7 @@ class ProcessTemplate extends Process implements ConfigurableModule {
$field->description = $this->_("By default, each template manages it's own group of fields. If you want to have this template use the fields from another template, select it here."); // Fieldgroup description $field->description = $this->_("By default, each template manages it's own group of fields. If you want to have this template use the fields from another template, select it here."); // Fieldgroup description
foreach($fieldgroups->getAll()->sort('name') as $fieldgroup) { foreach($fieldgroups->getAll()->sort('name') as $fieldgroup) {
/** @var Fieldgroup $fieldgroup */
$name = $fieldgroup->name; $name = $fieldgroup->name;
if($name === $template->name) { if($name === $template->name) {
$name .= ' ' . $this->_('(default)'); // Label appended to default fieldgroup name in select box $name .= ' ' . $this->_('(default)'); // Label appended to default fieldgroup name in select box
@@ -1327,6 +1350,7 @@ class ProcessTemplate extends Process implements ConfigurableModule {
$field->collapsed = Inputfield::collapsedYes; $field->collapsed = Inputfield::collapsedYes;
foreach($this->wire()->fieldgroups->find('sort=name') as $fieldgroup) { foreach($this->wire()->fieldgroups->find('sort=name') as $fieldgroup) {
/** @var Fieldgroup $fieldgroup */
$template = $this->templates->get($fieldgroup->name); $template = $this->templates->get($fieldgroup->name);
if($template && ($template->flags & Template::flagSystem) && !$config->advanced) continue; if($template && ($template->flags & Template::flagSystem) && !$config->advanced) continue;
if($this->template && $fieldgroup->name == $this->template->name) continue; if($this->template && $fieldgroup->name == $this->template->name) continue;
@@ -1431,6 +1455,7 @@ class ProcessTemplate extends Process implements ConfigurableModule {
$field->description= $this->_('Selector to find the other pages that should have their cache cleared.'); $field->description= $this->_('Selector to find the other pages that should have their cache cleared.');
$field->attr('value', $template->cacheExpireSelector); $field->attr('value', $template->cacheExpireSelector);
} else { } else {
/** @var InputfieldMarkup $field */
$field = $modules->get('InputfieldMarkup'); $field = $modules->get('InputfieldMarkup');
$field->value = $this->_('Save this template and then come back here to configure your selector.'); $field->value = $this->_('Save this template and then come back here to configure your selector.');
} }
@@ -1473,6 +1498,7 @@ class ProcessTemplate extends Process implements ConfigurableModule {
// -------------------- // --------------------
/** @var InputfieldText $field */
$field = $modules->get('InputfieldText'); $field = $modules->get('InputfieldText');
$field->attr('name', 'noCachePostVars'); $field->attr('name', 'noCachePostVars');
$field->label = $labelPOST; $field->label = $labelPOST;
@@ -1794,7 +1820,7 @@ class ProcessTemplate extends Process implements ConfigurableModule {
$field->attr('name', 'noTrash'); $field->attr('name', 'noTrash');
$field->label = $this->_("Disable Trash Option?"); $field->label = $this->_("Disable Trash Option?");
$field->description = $this->_("When checked, pages using this template will not have the option of being sent to the trash."); // noTrash option, description $field->description = $this->_("When checked, pages using this template will not have the option of being sent to the trash."); // noTrash option, description
if($this->wire('config')->advanced) $field->notes = $this->_('API: $template->noTrash = 1; // or 0 to disable'); // noTrash option, API notes if($this->wire()->config->advanced) $field->notes = $this->_('API: $template->noTrash = 1; // or 0 to disable'); // noTrash option, API notes
$field->attr('value', 1); $field->attr('value', 1);
if($template->noTrash) { if($template->noTrash) {
@@ -3126,6 +3152,7 @@ class ProcessTemplate extends Process implements ConfigurableModule {
protected function importFieldgroup(Fieldgroup $fieldgroup, Template $template) { protected function importFieldgroup(Fieldgroup $fieldgroup, Template $template) {
$total = 0; $total = 0;
foreach($fieldgroup as $field) { foreach($fieldgroup as $field) {
/** @var Field $field */
// if template already has the field, leave it, unless it's a closing fieldset. // if template already has the field, leave it, unless it's a closing fieldset.
// necessary because the fieldAdded hook may automatically add a closing fieldset, // necessary because the fieldAdded hook may automatically add a closing fieldset,
// so this prevents things from getting out of order. // so this prevents things from getting out of order.
@@ -3147,7 +3174,6 @@ class ProcessTemplate extends Process implements ConfigurableModule {
*/ */
protected function saveFields() { protected function saveFields() {
$fieldtypes = $this->wire()->fieldtypes;
$sanitizer = $this->wire()->sanitizer; $sanitizer = $this->wire()->sanitizer;
$fields = $this->wire()->fields; $fields = $this->wire()->fields;
$input = $this->wire()->input; $input = $this->wire()->input;
@@ -3205,9 +3231,8 @@ class ProcessTemplate extends Process implements ConfigurableModule {
foreach($badFieldsets as $field) { foreach($badFieldsets as $field) {
$this->error(sprintf($this->_('Error with placement of fieldset/tab "%s" - please fix and save again'), $field->name)); $this->error(sprintf($this->_('Error with placement of fieldset/tab "%s" - please fix and save again'), $field->name));
} }
/** @var FieldtypeFieldsetOpen $fieldset */ // $fieldset = $fieldtypes->get('FieldtypeFieldsetOpen');
$fieldset = $fieldtypes->get('FieldtypeFieldsetOpen'); // if($fieldset->checkFieldgroupFieldsets($this->template->fieldgroup)) $saveFieldgroup = true;
if($fieldset->checkFieldgroupFieldsets($this->template->fieldgroup)) $saveFieldgroup = true;
} }
} }
@@ -3225,6 +3250,7 @@ class ProcessTemplate extends Process implements ConfigurableModule {
if(count($removedFields)) { if(count($removedFields)) {
$url = "removeFields?id={$this->template->id}&fields="; $url = "removeFields?id={$this->template->id}&fields=";
foreach($removedFields as $field) { foreach($removedFields as $field) {
/** @var Field $field */
$url .= $field->id . ','; $url .= $field->id . ',';
} }
return rtrim($url, ','); return rtrim($url, ',');
@@ -3297,7 +3323,7 @@ class ProcessTemplate extends Process implements ConfigurableModule {
$f->attr('value', $this->template->id); $f->attr('value', $this->template->id);
$form->append($f); $form->append($f);
/** @var InputfieldSubmit $field */ /** @var InputfieldSubmit $f */
$f = $modules->get('InputfieldSubmit'); $f = $modules->get('InputfieldSubmit');
$f->attr('name', 'submit_change_fieldgroup'); $f->attr('name', 'submit_change_fieldgroup');
$f->attr('value', $this->_x('Continue', 'submit-fieldgroup')); $f->attr('value', $this->_x('Continue', 'submit-fieldgroup'));
@@ -3764,7 +3790,7 @@ class ProcessTemplate extends Process implements ConfigurableModule {
$table->setEncodeEntities(false); $table->setEncodeEntities(false);
$table->headerRow(array($labels['name'], $labels['templates'])); $table->headerRow(array($labels['name'], $labels['templates']));
foreach($tags as $key => $tag) { foreach($tags as $tag) {
$table->row(array( $table->row(array(
$tag => "./?edit_tag=$tag", $tag => "./?edit_tag=$tag",
implode(', ', $templateNamesByTag[$tag]) implode(', ', $templateNamesByTag[$tag])