Skip to content

Add necessary call to Form::isSubmitted and remove boilerplate #10068

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 3 commits into from

Conversation

keichinger
Copy link
Contributor

This code example was the last parts of the docs that wasn't calling Form::isSubmitted() as required as of Symfony 4.0.

Other than that I've simplified the action a little bit to remove some rather unnecessary noise in an already little more complicated example to ease reading and understanding it. If you want to keep the boilerplate, I'm more than happy to remove it from this PR :)

- Since Symfony 4.0 it's required to call `Form::isSubmitted()` before you call `Form::isValid()`
- Remove some unnecessary boilerplate code by using automatic parameter conversion and parameter injection of the `EntityManager`
{
$entityManager = $this->getDoctrine()->getManager();
Copy link
Member

Choose a reason for hiding this comment

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

Personally I like removing this code ... but to not complicate the example with more concepts (ParamConverters), let's go back to the original code, but improved with the injection of $em that you proposed. Something like this:

public function edit($id, Request $request, EntityManagerInterface $entityManager)
{
    if (null === $task = $entityManager->getRepository(Task::class)->find($id)) {
        throw $this->createNotFoundException('No task found for id '.$id);
    }
    
    // ...
}

@javiereguiluz
Copy link
Member

Thanks @keichinger.

javiereguiluz added a commit that referenced this pull request Jul 23, 2018
…rplate (keichinger, javiereguiluz)

This PR was submitted for the master branch but it was merged into the 4.0 branch instead (closes #10068).

Discussion
----------

Add necessary call to Form::isSubmitted and remove boilerplate

This code example was the last parts of the docs that wasn't calling `Form::isSubmitted()` as required as of Symfony 4.0.

Other than that I've simplified the action a little bit to remove some rather unnecessary noise in an already little more complicated example to ease reading and understanding it. If you want to keep the boilerplate, I'm more than happy to remove it from this PR :)

Commits
-------

ae265d7 Update form_collections.rst
f140342 Minor refactor
6f2c417 Add necessary call to Form::isSubmitted and remove boilerplate
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.

3 participants