Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Form] Add form type guesser forEnumType#61297

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

@mttsch
Copy link
Contributor

QA
Branch?7.4
Bug fix?no
New feature?yes
Deprecations?no
IssuesFix#61272
LicenseMIT

This new form type guesser guesses the form type of an enum property and also sets theclass option of theEnumType to the relevant enum name.

valtzu reacted with hooray emoji
@mttschmttschforce-pushed thefeature/61272-form-enum-type-guesser branch 4 times, most recently from30ce63c to0796aa4CompareAugust 1, 2025 16:27
@mttsch

This comment was marked as outdated.

@mttschmttschforce-pushed thefeature/61272-form-enum-type-guesser branch 2 times, most recently from80d176c to78a2346CompareAugust 3, 2025 03:40
@mttschmttschforce-pushed thefeature/61272-form-enum-type-guesser branch 2 times, most recently from1fbb523 toa5eebb2CompareAugust 5, 2025 09:53

privatefunctiongetPropertyType(string$class,string$property): ?\ReflectionNamedType
{
if (isset($this->cache[$class]) &&\array_key_exists($property,$this->cache[$class])) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
if (isset($this->cache[$class]) &&\array_key_exists($property,$this->cache[$class])) {
if (isset($this->cache[$class][$property])) {

Comment on lines 57 to 60
if (!isset($this->cache[$class])) {
$this->cache[$class] = [];
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
if (!isset($this->cache[$class])) {
$this->cache[$class] = [];
}

$classReflection =new \ReflectionClass($class);
$propertyReflection =$classReflection->getProperty($property);
}catch (\ReflectionException) {
return$this->cache[$class][$property] =null;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
return$this->cache[$class][$property] =null;
return$this->cache[$class][$property] =false;

Comment on lines 62 to 63
$classReflection =new \ReflectionClass($class);
$propertyReflection =$classReflection->getProperty($property);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
$classReflection =new \ReflectionClass($class);
$propertyReflection =$classReflection->getProperty($property);
$propertyReflection =new \ReflectionProperty($class,$property);

Comment on lines 68 to 72
if (!$propertyReflection->getType()instanceof \ReflectionNamedType || !enum_exists($propertyReflection->getType()->getName())) {
return$this->cache[$class][$property] =null;
}

return$this->cache[$class][$property] =$propertyReflection->getType();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
if (!$propertyReflection->getType()instanceof \ReflectionNamedType || !enum_exists($propertyReflection->getType()->getName())) {
return$this->cache[$class][$property] =null;
}
return$this->cache[$class][$property] =$propertyReflection->getType();
$type =$propertyReflection->getType();
if (!$typeinstanceof \ReflectionNamedType || !enum_exists($enum->getName())) {
$type =false;
}
return$this->cache[$class][$property] =$type;

@mttschmttschforce-pushed thefeature/61272-form-enum-type-guesser branch froma5eebb2 to1e540ebCompareAugust 5, 2025 14:51
$container->removeDefinition('form.type_extension.form.html_sanitizer');
}

if (!class_exists(EnumFormTypeGuesser::class)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I would do this insideregisterFormConfiguration()

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Done

@mttschmttschforce-pushed thefeature/61272-form-enum-type-guesser branch from1e540eb todc492c9CompareAugust 6, 2025 03:28
@mttsch
Copy link
ContributorAuthor

@nicolas-grekas@xabbuh Is there anything more to do for me in this PR?

@mttschmttschforce-pushed thefeature/61272-form-enum-type-guesser branch fromdc492c9 to7918e76CompareAugust 22, 2025 14:31
@mttschmttschforce-pushed thefeature/61272-form-enum-type-guesser branch from7918e76 to9e8a923CompareAugust 28, 2025 14:26
@fabpot
Copy link
Member

Thank you@mttsch.

@fabpotfabpot merged commit87b42a6 intosymfony:7.4Aug 30, 2025
10 of 13 checks passed
@mttschmttsch deleted the feature/61272-form-enum-type-guesser branchAugust 30, 2025 07:57
This was referencedOct 27, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas left review comments

@fabpotfabpotfabpot approved these changes

@xabbuhxabbuhxabbuh approved these changes

@ycerutoycerutoAwaiting requested review from ycerutoyceruto is a code owner

Assignees

No one assigned

Projects

None yet

Milestone

7.4

Development

Successfully merging this pull request may close these issues.

[Form] With form builder, auto-detect Enum properties

5 participants

@mttsch@fabpot@nicolas-grekas@xabbuh@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp