Skip to content

Commit

Permalink
Fixed the logic to get the field name
Browse files Browse the repository at this point in the history
  • Loading branch information
zepich committed Apr 28, 2024
1 parent 8527364 commit 555fcd6
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/Serializer/FormNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,7 @@ private function parseFormData(FormInterface $form, array &$data, array $ignored
return;
}

$key = '';
$parent = $form;
do {
$key = ((string) $parent->getPropertyPath()) . $key;
$parent = $parent->getParent();
} while ($parent);

$key = $this->getKeyForField($form);
$data['formData'][$key] = $form->getData();

if ($form->isRequired()) {
Expand All @@ -143,6 +137,23 @@ private function parseFormData(FormInterface $form, array &$data, array $ignored
}
}

private function getKeyForField(FormInterface $field): string
{
$parent = null;
if ($field->getParent()) {

Check failure on line 143 in src/Serializer/FormNormalizer.php

View workflow job for this annotation

GitHub Actions / PHPStan & PHPUnit

Only booleans are allowed in an if condition, Symfony\Component\Form\FormInterface|null given.
$parent = $this->getKeyForField($field->getParent());
}

$name = (string) $field->getName();

Check failure on line 147 in src/Serializer/FormNormalizer.php

View workflow job for this annotation

GitHub Actions / PHPStan & PHPUnit

Casting to string something that's already string.
if ($parent) {

Check failure on line 148 in src/Serializer/FormNormalizer.php

View workflow job for this annotation

GitHub Actions / PHPStan & PHPUnit

Only booleans are allowed in an if condition, string|null given.
$key = sprintf('%s[%s]', $parent, $name);
} else {
$key = $name;
}

return $key;
}

/**
* @deprecated since Symfony 6.3, use "getSupportedTypes()" instead
*/
Expand Down

0 comments on commit 555fcd6

Please sign in to comment.