Skip to content

[Form] add isSubmittedRequestValid function #54726

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

Closed
wants to merge 7 commits into from

Conversation

Oviglo
Copy link
Contributor

@Oviglo Oviglo commented Apr 25, 2024

Q A
Branch? 7.1
Bug fix? no
New feature? yes
Deprecations? no
Issues
License MIT

In controllers, we often have to call three functions to validate a form: handleRequest, ìsSubmittedand isValid. I wrote a new method that calls handlerequestand return the result of the conditionisSubmitted() && isValid()`

@carsonbot
Copy link

Hey!

Thanks for your PR. You are targeting branch "7.1" but it seems your PR description refers to branch "7.1 for features / 5.4, 6.4, or 7.0 for bug fixes".
Could you update the PR description or change target branch? This helps core maintainers a lot.

Cheers!

Carsonbot

@OskarStark OskarStark modified the milestones: 7.1, 7.2 Apr 25, 2024
Copy link
Member

@yceruto yceruto left a comment

Choose a reason for hiding this comment

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

LGTM!

@yceruto
Copy link
Member

yceruto commented Apr 25, 2024

There is a minor CS remaining spotted by fabbot https://fabbot.io/report/symfony/symfony/54726/6b8a8b268f32cd4037a04d217aa8bb551774cf51

@Oviglo
Copy link
Contributor Author

Oviglo commented Apr 25, 2024

There is a minor CS remaining spotted by fabbot https://fabbot.io/report/symfony/symfony/54726/6b8a8b268f32cd4037a04d217aa8bb551774cf51

https://fabbot.io/patch/symfony/symfony/54726/6b8a8b268f32cd4037a04d217aa8bb551774cf51/exception_messages.diff
This change request is weird isn't it ? It concern to add '.' before quote in the string

@derrabus
Copy link
Member

I'm not entirely convinced, we need this feature, tbh. My biggest concern is that we change a well established interface and add an unnecessary method to it.

If your main motivation is saving a few keystrokes of boilerplate in controllers, let's add that method to the AbstractController class or some trait instead?

@Oviglo
Copy link
Contributor Author

Oviglo commented Apr 26, 2024

I'm not entirely convinced, we need this feature, tbh. My biggest concern is that we change a well established interface and add an unnecessary method to it.

If your main motivation is saving a few keystrokes of boilerplate in controllers, let's add that method to the AbstractController class or some trait instead?

This is an interesting observation, I can make a new PR to write this in AbstractController:

$form = $this->createForm(FormType::class);
if ($this->isSubmittedFormValid($form, $request)) {
}

I don't think this will be useful except to not forget the handleRequest method

@@ -416,6 +417,13 @@ public function handleRequest(mixed $request = null): static
return $this;
}

public function isSubmittedRequestValid(?Request $request = null): bool
Copy link
Member

@derrabus derrabus Apr 26, 2024

Choose a reason for hiding this comment

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

This signature breaks the component's abstraction, btw: handleRequest() has no opinion on how a request is represented, but this method surprisingly requires an HttpFoundation request.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed this at @yceruto 's request: (cf: #54726 (comment))

@derrabus
Copy link
Member

This is an interesting observation, I can make a new PR to write this in AbstractController:

$form = $this->createForm(FormType::class);
if ($this->isSubmittedFormValid($form, $request)) {
}

If we want to have such a utility function in the core at all, I think AbstractController is the place.

@Oviglo Oviglo closed this Apr 26, 2024
@Oviglo
Copy link
Contributor Author

Oviglo commented Apr 26, 2024

It rewrite the method in AbstractController: #54743

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants