diff --git a/app/bundles/FormBundle/Entity/Field.php b/app/bundles/FormBundle/Entity/Field.php index 76bd4954e22..b45e8e002e3 100644 --- a/app/bundles/FormBundle/Entity/Field.php +++ b/app/bundles/FormBundle/Entity/Field.php @@ -987,6 +987,7 @@ public function getMappedObject(): ?string public function setMappedObject(?string $mappedObject): void { $this->mappedObject = $mappedObject; + $this->resetLeadFieldIfValueIsEmpty($mappedObject); } public function getMappedField(): ?string @@ -997,5 +998,15 @@ public function getMappedField(): ?string public function setMappedField(?string $mappedField): void { $this->mappedField = $mappedField; + $this->resetLeadFieldIfValueIsEmpty($mappedField); + } + + private function resetLeadFieldIfValueIsEmpty(?string $value): void + { + if ($value) { + return; + } + + $this->leadField = null; } } diff --git a/app/bundles/FormBundle/Form/Type/FieldType.php b/app/bundles/FormBundle/Form/Type/FieldType.php index 48c59b1baca..0067c0fecc0 100644 --- a/app/bundles/FormBundle/Form/Type/FieldType.php +++ b/app/bundles/FormBundle/Form/Type/FieldType.php @@ -437,7 +437,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'tooltip' => 'mautic.form.field.help.mapped.field', ], 'required' => false, - 'data' => $mappedField ?? $this->getDefaultMappedField((string) $type), + 'data' => $mappedField ?? (empty($options['data']['id']) ? $this->getDefaultMappedField((string) $type) : ''), ] ); diff --git a/app/bundles/FormBundle/Resources/views/Builder/_field_wrapper.html.twig b/app/bundles/FormBundle/Resources/views/Builder/_field_wrapper.html.twig index 42885c2af92..87a0d83658c 100644 --- a/app/bundles/FormBundle/Resources/views/Builder/_field_wrapper.html.twig +++ b/app/bundles/FormBundle/Resources/views/Builder/_field_wrapper.html.twig @@ -36,10 +36,10 @@ - {% if ((field.showWhenValueExists is defined and false is same as field.showWhenValueExists) or field.showAfterXSubmissions) is not empty - or (field.alwaysDisplay is defined and true is same as field.alwaysDisplay) - or (field.leadField is defined and field.leadField is not empty) - or (field.conditions is defined and field.conditions is not empty) + {% if ((field.showWhenValueExists is defined and false is same as field.showWhenValueExists) or field.showAfterXSubmissions is not empty) + or (true is same as field.alwaysDisplay|default(null)) + or (field.mappedField|default(null) is not empty) + or (field.conditions|default(null) is not empty) %}