Skip to content

[Validator] Added CssColor constraint #14965

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 1 commit into from
Oct 8, 2021

Conversation

welcoMattic
Copy link
Member

@welcoMattic welcoMattic commented Feb 12, 2021

This PR introduces the new CssColor constraint, contributed in symfony/symfony#40168

@welcoMattic welcoMattic requested a review from xabbuh as a code owner February 12, 2021 15:49
@welcoMattic welcoMattic force-pushed the hexadecimal-constraint branch from fc18710 to b21f21b Compare February 12, 2021 15:57
@welcoMattic welcoMattic changed the title Added HexaColor constraint [Validator] Added HexaColor constraint Feb 12, 2021
@welcoMattic welcoMattic force-pushed the hexadecimal-constraint branch from b21f21b to d301bfd Compare February 12, 2021 16:07
@javiereguiluz javiereguiluz added the Waiting Code Merge Docs for features pending to be merged label Feb 12, 2021
@carsonbot carsonbot added this to the next milestone Feb 12, 2021
@welcoMattic welcoMattic changed the title [Validator] Added HexaColor constraint [Validator] Added CssColor constraint Jul 4, 2021
@welcoMattic welcoMattic force-pushed the hexadecimal-constraint branch 2 times, most recently from 5e2c888 to 4a20f74 Compare July 4, 2021 20:57
@welcoMattic welcoMattic force-pushed the hexadecimal-constraint branch 2 times, most recently from e9f296c to fa5743e Compare July 5, 2021 08:10
fabpot added a commit to symfony/symfony that referenced this pull request Oct 6, 2021
This PR was merged into the 5.4 branch.

Discussion
----------

[Validator] Added `CssColor` constraint

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       |
| License       | MIT
| Doc PR        | symfony/symfony-docs#14965

This PR introduces a new `CssColor` constraint. It comes with 3 validation modes:

- Long, which allows all hexadecimal representation of a color, or 9 (#EEEEEEFF) characters
- Short, which only allows hexadecimal colors on 4 (#EEE), 5 (#FFF00) characters
- Named colors, which matches [the official list of named colors](https://www.w3.org/TR/css-color-4/#named-color)
- HTML5, which allows hexadecimal colors on 7 (#EEEEEE) characters as well as the HTML5 input type color

I know that such a color validation already exists in Symfony (in the `ColorType` class), but it's hardcoded in the FormType, and not usable as an assert Annotation. We could decide to remove this hardcoded validation in favor of the new added `CssColor` constraint. Let me know, if yes, I will make the change.

Commits
-------

b36371c Added new CssColor constraint
symfony-splitter pushed a commit to symfony/validator that referenced this pull request Oct 6, 2021
This PR was merged into the 5.4 branch.

Discussion
----------

[Validator] Added `CssColor` constraint

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       |
| License       | MIT
| Doc PR        | symfony/symfony-docs#14965

This PR introduces a new `CssColor` constraint. It comes with 3 validation modes:

- Long, which allows all hexadecimal representation of a color, or 9 (#EEEEEEFF) characters
- Short, which only allows hexadecimal colors on 4 (#EEE), 5 (#FFF00) characters
- Named colors, which matches [the official list of named colors](https://www.w3.org/TR/css-color-4/#named-color)
- HTML5, which allows hexadecimal colors on 7 (#EEEEEE) characters as well as the HTML5 input type color

I know that such a color validation already exists in Symfony (in the `ColorType` class), but it's hardcoded in the FormType, and not usable as an assert Annotation. We could decide to remove this hardcoded validation in favor of the new added `CssColor` constraint. Let me know, if yes, I will make the change.

Commits
-------

b36371c06e Added new CssColor constraint
@derrabus
Copy link
Member

derrabus commented Oct 6, 2021

The feature PR has been merged.

@welcoMattic
Copy link
Member Author

It needs some work here to report the last changes (modes instead of mode) from the code.

@OskarStark OskarStark added Validator and removed Waiting Code Merge Docs for features pending to be merged labels Oct 7, 2021
@OskarStark OskarStark modified the milestones: next, 5.4 Oct 7, 2021
@welcoMattic welcoMattic force-pushed the hexadecimal-constraint branch 2 times, most recently from f395714 to 10810ad Compare October 7, 2021 15:45
@welcoMattic
Copy link
Member Author

I don't understand why the CI fails 🤔

@OskarStark
Copy link
Contributor

friendly ping @Nyholm can you help?

Copy link
Contributor

@OskarStark OskarStark left a comment

Choose a reason for hiding this comment

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

Some minor, afterwards good to merge

@Nyholm
Copy link
Member

Nyholm commented Oct 8, 2021

The CI is correct. The class is called “Constraint”

https://github.com/symfony/symfony/blob/5.4/src/Symfony/Component/Validator/Constraint.php

@Nyholm
Copy link
Member

Nyholm commented Oct 8, 2021

Oh. Sorry. I see now that you import partial FQCN. Ci does not support that (appearently)

Feel free to ignore that :)

@welcoMattic welcoMattic force-pushed the hexadecimal-constraint branch from fd57353 to fc1539c Compare October 8, 2021 08:20
@OskarStark
Copy link
Contributor

Thanks Mathieu for working on this feature, this is much appreciated.

@OskarStark OskarStark merged commit 0710b02 into symfony:5.4 Oct 8, 2021
@welcoMattic welcoMattic deleted the hexadecimal-constraint branch October 8, 2021 09:46
javiereguiluz added a commit to javiereguiluz/symfony-docs that referenced this pull request Oct 12, 2021
…aviereguiluz)

This PR was merged into the 5.4 branch.

Discussion
----------

[Validator] Some tweaks to CssColor constraint

This tweaks the great work made by `@welcoMattic` in symfony#14965.

It's mostly minor tweaks ... but I also expanded the "basic usage" example to show the case of not adding any parameters to the constraint, which is a common case when you just want to allow any of the valid CSS color formats.

Commits
-------

07e38b7 [Validator] Some tweaks to CssColor constraint
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