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

Fixed the logic to get the field name #10

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
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 @@
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 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
Loading