1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-14 10:45:54 +02:00
This commit is contained in:
Ryan Cramer
2021-11-30 11:25:05 -05:00
parent 73422a9649
commit bf3c442f38

View File

@@ -2644,6 +2644,7 @@ class ProcessField extends Process implements ConfigurableModule {
$session = $this->wire('session'); $session = $this->wire('session');
$session->CSRF->validate(); $session->CSRF->validate();
$changedTemplates = array();
$isFieldset = false; $isFieldset = false;
$fields = array($this->field); $fields = array($this->field);
if($this->field->type instanceof FieldtypeFieldsetOpen) { if($this->field->type instanceof FieldtypeFieldsetOpen) {
@@ -2656,6 +2657,7 @@ class ProcessField extends Process implements ConfigurableModule {
// first handle additions, since it's possible for removals to take a long time or remote chance of timeout // first handle additions, since it's possible for removals to take a long time or remote chance of timeout
foreach($this->wire('templates') as $template) { foreach($this->wire('templates') as $template) {
$templateChanged = false;
foreach($fields as $key => $field) { foreach($fields as $key => $field) {
@@ -2696,17 +2698,24 @@ class ProcessField extends Process implements ConfigurableModule {
$field->name, $template->name, $f->name)); $field->name, $template->name, $f->name));
} else { } else {
$template->fieldgroup->insertAfter($field, $f); $template->fieldgroup->insertAfter($field, $f);
$changedTemplates[$template->id] = $template;
$this->message(sprintf($this->_('Added field "%1$s" to template "%2$s" after "%3$s"'), $this->message(sprintf($this->_('Added field "%1$s" to template "%2$s" after "%3$s"'),
$field->name, $template->name, $f->name)); $field->name, $template->name, $f->name));
} }
$templateChanged = true;
} }
} }
$template->fieldgroup->save();
if($templateChanged) {
$template->fieldgroup->save();
$template->save();
}
} }
// next handle removals // next handle removals
foreach($this->wire('templates') as $template) { foreach($this->wire('templates') as $template) {
$removeFieldID = (int) $this->wire('input')->post("remove_{$this->field->id}_template_$template->id"); $removeFieldID = (int) $this->wire('input')->post("remove_{$this->field->id}_template_$template->id");
$templateChanged = false;
if($removeFieldID && $removeFieldID === (int) $this->field->id) { if($removeFieldID && $removeFieldID === (int) $this->field->id) {
$template->fieldgroup->remove($this->field); $template->fieldgroup->remove($this->field);
if($this->field->type instanceof FieldtypeFieldsetOpen) { if($this->field->type instanceof FieldtypeFieldsetOpen) {
@@ -2715,6 +2724,7 @@ class ProcessField extends Process implements ConfigurableModule {
} }
try { try {
$template->fieldgroup->save(); $template->fieldgroup->save();
$templateChanged = true;
$this->message(sprintf($this->_('Removed field "%1$s" from template "%2$s"'), $this->field->name, $template->name)); $this->message(sprintf($this->_('Removed field "%1$s" from template "%2$s"'), $this->field->name, $template->name));
} catch(\Exception $e) { } catch(\Exception $e) {
$this->error( $this->error(
@@ -2724,6 +2734,7 @@ class ProcessField extends Process implements ConfigurableModule {
); );
} }
} }
if($templateChanged) $template->save();
} }
$this->wire('session')->redirect("./edit?id={$this->field->id}"); $this->wire('session')->redirect("./edit?id={$this->field->id}");