mirror of
https://github.com/processwire/processwire.git
synced 2025-08-11 01:04:16 +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:
@@ -121,7 +121,7 @@ class ProcessTemplate extends Process implements ConfigurableModule {
|
||||
$jQueryUI = $modules->get('JqueryUI');
|
||||
$jQueryUI->use('modal');
|
||||
|
||||
return parent::init();
|
||||
parent::init();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -260,7 +260,8 @@ class ProcessTemplate extends Process implements ConfigurableModule {
|
||||
$button->addClass('add_template_button');
|
||||
$button->showInHeader();
|
||||
$out .= $button->render();
|
||||
|
||||
|
||||
/** @var InputfieldButton $button */
|
||||
$button = $modules->get('InputfieldButton');
|
||||
$button->id = 'tags_button';
|
||||
$button->href = './tags/';
|
||||
@@ -268,6 +269,7 @@ class ProcessTemplate extends Process implements ConfigurableModule {
|
||||
$button->value = $this->labels['manageTags'];
|
||||
$out .= $button->render();
|
||||
|
||||
/** @var InputfieldButton $button */
|
||||
$button = $modules->get('InputfieldButton');
|
||||
$button->id = 'import_button';
|
||||
$button->href = "./import/";
|
||||
@@ -276,6 +278,7 @@ class ProcessTemplate extends Process implements ConfigurableModule {
|
||||
$button->setSecondary();
|
||||
$out .= $button->render();
|
||||
|
||||
/** @var InputfieldButton $button */
|
||||
$button = $modules->get('InputfieldButton');
|
||||
$button->id = 'export_button';
|
||||
$button->href = "./export/";
|
||||
@@ -397,6 +400,7 @@ class ProcessTemplate extends Process implements ConfigurableModule {
|
||||
$rows = array();
|
||||
|
||||
foreach($templates as $template) {
|
||||
/** @var Template $template */
|
||||
$label = $template->getLabel();
|
||||
if($label && $label != $template->name) {
|
||||
$useLabels = true;
|
||||
@@ -621,6 +625,8 @@ class ProcessTemplate extends Process implements ConfigurableModule {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$addedTemplates = array();
|
||||
|
||||
foreach($postTemplates as $basename) {
|
||||
|
||||
@@ -641,6 +647,7 @@ class ProcessTemplate extends Process implements ConfigurableModule {
|
||||
$template->save();
|
||||
|
||||
$this->message(sprintf($this->_('Added template and fieldgroup: %s'), $basename));
|
||||
$addedTemplates[] = $template;
|
||||
|
||||
} catch(\Exception $e) {
|
||||
$this->error($e->getMessage());
|
||||
@@ -659,8 +666,15 @@ class ProcessTemplate extends Process implements ConfigurableModule {
|
||||
$template->fieldgroup->save();
|
||||
}
|
||||
}
|
||||
|
||||
$session->redirect('./');
|
||||
|
||||
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('./');
|
||||
}
|
||||
|
||||
return ''; // never reached
|
||||
}
|
||||
@@ -747,7 +761,7 @@ class ProcessTemplate extends Process implements ConfigurableModule {
|
||||
}
|
||||
|
||||
$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();
|
||||
if(!$label) $label = $this->template->name;
|
||||
@@ -795,7 +809,8 @@ class ProcessTemplate extends Process implements ConfigurableModule {
|
||||
$t->attr('class', 'WireTab');
|
||||
$this->buildEditFormBasics($template, $t);
|
||||
$form->add($t);
|
||||
|
||||
|
||||
/** @var InputfieldWrapper $t */
|
||||
$t = $this->wire(new InputfieldWrapper());
|
||||
$t->attr('title', $this->_x('Access', 'tab'));
|
||||
$t->attr('id', 'tab_access');
|
||||
@@ -804,36 +819,41 @@ class ProcessTemplate extends Process implements ConfigurableModule {
|
||||
$overrides = $this->buildEditFormAccessOverrides($template);
|
||||
if($overrides) $t->add($overrides);
|
||||
$t->add($this->buildEditFormAccessFiles($template));
|
||||
$form->add($t);
|
||||
$form->add($t);
|
||||
|
||||
/** @var InputfieldWrapper $t */
|
||||
$t = $this->wire(new InputfieldWrapper());
|
||||
$t->attr('title', $this->_x('Family', 'tab'));
|
||||
$t->attr('class', 'WireTab');
|
||||
$t->attr('id', 'tab_family');
|
||||
$t->add($this->buildEditFormFamily($template));
|
||||
$form->add($t);
|
||||
$form->add($t);
|
||||
|
||||
/** @var InputfieldWrapper $t */
|
||||
$t = $this->wire(new InputfieldWrapper());
|
||||
$t->attr('title', $this->_x('URLs', 'tab'));
|
||||
$t->attr('class', 'WireTab');
|
||||
$t->attr('id', 'tab_urls');
|
||||
$t->add($this->buildEditFormURLs($template));
|
||||
$form->add($t);
|
||||
|
||||
|
||||
/** @var InputfieldWrapper $t */
|
||||
$t = $this->wire(new InputfieldWrapper());
|
||||
$t->attr('title', $this->_x('Files', 'tab'));
|
||||
$t->attr('class', 'WireTab');
|
||||
$t->attr('id', 'tab_files');
|
||||
$t->add($this->buildEditFormFile($template));
|
||||
$form->add($t);
|
||||
$form->add($t);
|
||||
|
||||
/** @var InputfieldWrapper $t */
|
||||
$t = $this->wire(new InputfieldWrapper());
|
||||
$t->attr('title', $this->_x('Cache', 'tab'));
|
||||
$t->attr('class', 'WireTab');
|
||||
$t->attr('id', 'tab_cache');
|
||||
$t->add($this->buildEditFormCache($template));
|
||||
$form->add($t);
|
||||
$form->add($t);
|
||||
|
||||
/** @var InputfieldWrapper $t */
|
||||
$t = $this->wire(new InputfieldWrapper());
|
||||
$t->attr('title', $this->_x('Advanced', 'tab'));
|
||||
$t->attr('class', 'WireTab');
|
||||
@@ -842,6 +862,7 @@ class ProcessTemplate extends Process implements ConfigurableModule {
|
||||
$form->add($t);
|
||||
|
||||
if($config->advanced) {
|
||||
/** @var InputfieldWrapper $t */
|
||||
$t = $this->wire(new InputfieldWrapper());
|
||||
$t->attr('title', $this->_x('System', 'tab'));
|
||||
$t->attr('class', 'WireTab');
|
||||
@@ -850,6 +871,7 @@ class ProcessTemplate extends Process implements ConfigurableModule {
|
||||
$form->add($t);
|
||||
}
|
||||
|
||||
/** @var InputfieldWrapper $t */
|
||||
$t = $this->wire(new InputfieldWrapper());
|
||||
$t->attr('class', 'WireTab');
|
||||
$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
|
||||
|
||||
foreach($fieldgroups->getAll()->sort('name') as $fieldgroup) {
|
||||
/** @var Fieldgroup $fieldgroup */
|
||||
$name = $fieldgroup->name;
|
||||
if($name === $template->name) {
|
||||
$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;
|
||||
|
||||
foreach($this->wire()->fieldgroups->find('sort=name') as $fieldgroup) {
|
||||
/** @var Fieldgroup $fieldgroup */
|
||||
$template = $this->templates->get($fieldgroup->name);
|
||||
if($template && ($template->flags & Template::flagSystem) && !$config->advanced) 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->attr('value', $template->cacheExpireSelector);
|
||||
} else {
|
||||
/** @var InputfieldMarkup $field */
|
||||
$field = $modules->get('InputfieldMarkup');
|
||||
$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->attr('name', 'noCachePostVars');
|
||||
$field->label = $labelPOST;
|
||||
@@ -1794,7 +1820,7 @@ class ProcessTemplate extends Process implements ConfigurableModule {
|
||||
$field->attr('name', 'noTrash');
|
||||
$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
|
||||
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);
|
||||
if($template->noTrash) {
|
||||
@@ -3126,6 +3152,7 @@ class ProcessTemplate extends Process implements ConfigurableModule {
|
||||
protected function importFieldgroup(Fieldgroup $fieldgroup, Template $template) {
|
||||
$total = 0;
|
||||
foreach($fieldgroup as $field) {
|
||||
/** @var Field $field */
|
||||
// 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,
|
||||
// so this prevents things from getting out of order.
|
||||
@@ -3147,7 +3174,6 @@ class ProcessTemplate extends Process implements ConfigurableModule {
|
||||
*/
|
||||
protected function saveFields() {
|
||||
|
||||
$fieldtypes = $this->wire()->fieldtypes;
|
||||
$sanitizer = $this->wire()->sanitizer;
|
||||
$fields = $this->wire()->fields;
|
||||
$input = $this->wire()->input;
|
||||
@@ -3205,9 +3231,8 @@ class ProcessTemplate extends Process implements ConfigurableModule {
|
||||
foreach($badFieldsets as $field) {
|
||||
$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');
|
||||
if($fieldset->checkFieldgroupFieldsets($this->template->fieldgroup)) $saveFieldgroup = true;
|
||||
// $fieldset = $fieldtypes->get('FieldtypeFieldsetOpen');
|
||||
// if($fieldset->checkFieldgroupFieldsets($this->template->fieldgroup)) $saveFieldgroup = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3225,6 +3250,7 @@ class ProcessTemplate extends Process implements ConfigurableModule {
|
||||
if(count($removedFields)) {
|
||||
$url = "removeFields?id={$this->template->id}&fields=";
|
||||
foreach($removedFields as $field) {
|
||||
/** @var Field $field */
|
||||
$url .= $field->id . ',';
|
||||
}
|
||||
return rtrim($url, ',');
|
||||
@@ -3297,7 +3323,7 @@ class ProcessTemplate extends Process implements ConfigurableModule {
|
||||
$f->attr('value', $this->template->id);
|
||||
$form->append($f);
|
||||
|
||||
/** @var InputfieldSubmit $field */
|
||||
/** @var InputfieldSubmit $f */
|
||||
$f = $modules->get('InputfieldSubmit');
|
||||
$f->attr('name', 'submit_change_fieldgroup');
|
||||
$f->attr('value', $this->_x('Continue', 'submit-fieldgroup'));
|
||||
@@ -3764,7 +3790,7 @@ class ProcessTemplate extends Process implements ConfigurableModule {
|
||||
$table->setEncodeEntities(false);
|
||||
$table->headerRow(array($labels['name'], $labels['templates']));
|
||||
|
||||
foreach($tags as $key => $tag) {
|
||||
foreach($tags as $tag) {
|
||||
$table->row(array(
|
||||
$tag => "./?edit_tag=$tag",
|
||||
implode(', ', $templateNamesByTag[$tag])
|
||||
|
Reference in New Issue
Block a user