Skip to content

Added doc entry for delete_empty form option with callable #8510

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

Merged
merged 3 commits into from
Oct 29, 2017
Merged

Added doc entry for delete_empty form option with callable #8510

merged 3 commits into from
Oct 29, 2017

Conversation

hiddewie
Copy link
Contributor

Fix #8244.

I hope the explanation is clear enough. Now it is just an addition to the existing text. The piece of code is taken from the tests (adapted slightly for simplicity).

// ...
'delete_empty' => function ($obj = null) {
return null === $obj || empty($obj->firstName);
},
Copy link
Member

@yceruto yceruto Oct 12, 2017

Choose a reason for hiding this comment

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

The users field suggests a collection of type User, right?

'delete_empty' => function (User $user = null) {
    return null === $user || empty($user->getFirstName());
},

Something like this would be good for you?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes! I've updated the code example.

A value is deleted from the collection only if the normalized value is ``null``.
However, you can also set the option value to a ``callable``, which will be called
for each value in the submitted collection. The ``callable`` should return
whether or not a value must be removed from the collection. For example::
Copy link
Member

Choose a reason for hiding this comment

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

The feature is especially useful for compound type entries only, we should mention it somewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. I've added a sentence explaining that use case after the code example.

@xabbuh xabbuh added this to the 3.4 milestone Oct 13, 2017
@hiddewie
Copy link
Contributor Author

@yceruto I've added your comments to the commit. Thanks.

@yceruto
Copy link
Member

yceruto commented Oct 16, 2017

We might have to add .. versionadded:: 3.4 block too?

- Added User type hint
- Added sentence about compound collection type use case
- Added versionadded block
@hiddewie
Copy link
Contributor Author

@yceruto Done!

Copy link
Member

@javiereguiluz javiereguiluz left a comment

Choose a reason for hiding this comment

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

Nice! Thanks for documenting this.

@@ -286,6 +286,27 @@ the empty values will be kept.
Read about the :ref:`form's empty_data option <reference-form-option-empty-data>`
to learn why this is necessary.

A value is deleted from the collection only if the normalized value is ``null``.
However, you can also set the option value to a callable, which will be executed
for each value in the submitted collection. If the callable returns ``false``,
Copy link
Member

Choose a reason for hiding this comment

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

This looks wrong to me. The item is removed if the callable returns true, isn't?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, of course! Edited.

may define complex conditions for considering them empty.

.. versionadded:: 3.4
Using a callable for the ``delete_empty`` option was introduced in Symfony 3.4.
Copy link
Member

Choose a reason for hiding this comment

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

Support for using a callable [...]

@weaverryan
Copy link
Member

Thank you @hiddewie.

@weaverryan
Copy link
Member

Btw, this is a pretty cool feature. So extra thanks for doc'ing it and to @Koc for the feature!

@weaverryan weaverryan merged commit 0373a97 into symfony:3.4 Oct 29, 2017
weaverryan added a commit that referenced this pull request Oct 29, 2017
…ble (hiddewie, javiereguiluz)

This PR was merged into the 3.4 branch.

Discussion
----------

Added doc entry for delete_empty form option with callable

Fix #8244.

I hope the explanation is clear enough. Now it is just an addition to the existing text. The piece of code is taken from the tests (adapted slightly for simplicity).

Commits
-------

0373a97 Processed xabbuh comments
3f1a814 Minor rewords
1722628 Added doc entry for delete_empty form option with callable
@hiddewie hiddewie deleted the callable-collection-type branch October 29, 2017 09:59
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