Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Validator] Explained how to use array constant in annotation #10810

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

Conversation

nikophil
Copy link
Contributor

Hi,

few days ago i tried to add a new feature to the choice validator constraint, by adding a new choicesFromConstant option.
symfony/symfony#29658
But then, i realized this was already supported.

I think this should be documented, as i think a lot of people don't know this feature.

thanks.

@HeahDude HeahDude added Form Waiting Code Merge Docs for features pending to be merged labels Dec 27, 2018
@HeahDude HeahDude added this to the 4.3 milestone Dec 27, 2018
@HeahDude HeahDude removed the Waiting Code Merge Docs for features pending to be merged label Dec 27, 2018
@HeahDude HeahDude modified the milestones: 4.3, 3.4 Dec 27, 2018
Copy link
Contributor

@HeahDude HeahDude left a comment

Choose a reason for hiding this comment

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

Thank you very much for this contribution!

@nikophil
Copy link
Contributor Author

Hi @HeahDude
i think you know what i'm talking about here ;)

i've wondered if this would need a configuration-block and if we have to list all the other way to configure this, but i think it's really specific to the annotation...
what do you think ?

@nikophil nikophil force-pushed the validator_choices_from_constant branch 2 times, most recently from a810dae to 83a2304 Compare December 27, 2018 12:37
Supplying the Choices from an Array Constant
--------------------------------------------

You can also directly provide an array constant to the ``choices`` option in the annotation::
Copy link
Contributor

Choose a reason for hiding this comment

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

- array constant
+ constant containing an array

sounds a bit better


class Author
{
const GENRES = ['fiction', 'non-fiction'];
Copy link
Contributor

Choose a reason for hiding this comment

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

I would prefer sth like action and comedy

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep, i agree, but i've chosen these one for the coherence with the example above
would you mind that i change the other example as well ?


.. note::

If the constant is stored in a different class, you can pass the fully qualified class name
Copy link
Contributor

Choose a reason for hiding this comment

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

s/stored/defined/

.. note::

If the constant is stored in a different class, you can pass the fully qualified class name
of the class or import this class by adding it to the "use" list.
Copy link
Contributor

Choose a reason for hiding this comment

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

This line is not needed

@OskarStark
Copy link
Contributor

Thank you for your contribution 👍

@nikophil nikophil force-pushed the validator_choices_from_constant branch from 83a2304 to 3f0ad71 Compare December 27, 2018 14:50

.. warning::

Notice that the constant in the option is used without quotes.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Notice that the constant in the option is used without quotes.
The constant in the option is used without quotes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

@HeahDude HeahDude changed the title validator : choice constraint : explain how to supply choices from an array constant [Validator] Explained how to use array constant in annotation Jan 1, 2019
@nikophil nikophil force-pushed the validator_choices_from_constant branch from 3f0ad71 to 9b23462 Compare January 2, 2019 13:29
@@ -279,6 +279,35 @@ you can pass the class name and the method as an array.
}
}

Supplying the Choices from an Array Constant
Copy link
Contributor

Choose a reason for hiding this comment

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

array constant in lower case is better i think, wdyt?

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 you're right

Copy link
Contributor Author

Choose a reason for hiding this comment

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

actually i've wrote like this, to be consistent with the title above which is Supplying the Choices with a Callback Function


.. warning::

The constant in the option is used without quotes.
Copy link
Contributor

Choose a reason for hiding this comment

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

what about both inside note instead of warning? warning can be misunderstood

Copy link
Contributor Author

Choose a reason for hiding this comment

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

do you mean in the same note or two different notes ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

do you mean both inside the same note ?

Copy link
Contributor

Choose a reason for hiding this comment

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

the same i think

@xabbuh
Copy link
Member

xabbuh commented Jan 11, 2019

I wonder if it would not be easier to expand the code example that we have in the "Basic usage" section to also contain choices coming from a constant and adding an inline comment there.

@OskarStark
Copy link
Contributor

friendly ping @nikophil

@xabbuh's comment is a legitimate consideration 🤔

@nikophil
Copy link
Contributor Author

hi @OskarStark sorry, i've forgotten this one, i was thinking it was merged.

here is some update.

@javiereguiluz
Copy link
Member

Nicolas, thanks for this contribution ... and sorry for the late merge!

javiereguiluz added a commit that referenced this pull request Mar 7, 2019
…ation (nikophil)

This PR was squashed before being merged into the 3.4 branch (closes #10810).

Discussion
----------

[Validator] Explained how to use array constant in annotation

Hi,

few days ago i tried to add a new feature to the `choice` validator constraint, by adding a new `choicesFromConstant` option.
symfony/symfony#29658
But then, i realized this was already supported.

I think this should be documented, as i think a lot of people don't know this feature.

thanks.

Commits
-------

7774aab [Validator] Explained how to use array constant in annotation
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.

7 participants