Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix form label in next major #6718

Merged
merged 1 commit into from
Dec 31, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions src/Form/FormMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,7 @@ public function add($name, $type = null, array $options = [], array $fieldDescri
$type = CollectionType::class;
}

$label = $fieldName;

$group = $this->addFieldToCurrentGroup($label);
$group = $this->addFieldToCurrentGroup($fieldName);

// Try to autodetect type
if ($name instanceof FormBuilderInterface && null === $type) {
Expand Down Expand Up @@ -124,10 +122,11 @@ public function add($name, $type = null, array $options = [], array $fieldDescri
}

if ($name instanceof FormBuilderInterface) {
$child = $name;
$type = null;
$options = [];
} else {
$name = $fieldDescription->getName();
$child = $fieldDescription->getName();

// Note that the builder var is actually the formContractor:
$options = array_replace_recursive(
Expand All @@ -142,7 +141,17 @@ public function add($name, $type = null, array $options = [], array $fieldDescri
}

if (!isset($options['label'])) {
$options['label'] = $this->admin->getLabelTranslatorStrategy()->getLabel($name, 'form', 'label');
/*
* NEXT_MAJOR: Replace $child by $name in the next line.
* And add the following BC-break in the upgrade note:
*
* The form label are now correctly using the label translator strategy
* for field with `.` (which won't be replaced by `__`). For instance,
* with the underscore label strategy, the label `foo.barBaz` was
* previously `form.label_foo__bar_baz` and now is `form.label_foo_bar_baz`
* to be consistent with others labels like `show.label_foo_bar_baz`.
*/
$options['label'] = $this->admin->getLabelTranslatorStrategy()->getLabel($child, 'form', 'label');
}

// NEXT_MAJOR: Remove this block.
Expand All @@ -162,7 +171,7 @@ public function add($name, $type = null, array $options = [], array $fieldDescri
}

$this->admin->addFormFieldDescription($fieldName, $fieldDescription);
$this->formBuilder->add($name, $type, $options);
$this->formBuilder->add($child, $type, $options);

return $this;
}
Expand Down