-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Validator] Added CssColor
constraint
#40168
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
Conversation
74700e0
to
fc3a5ef
Compare
fc3a5ef
to
ed5f06d
Compare
Why only hex? Maybe Color constraint with hex, rgb(a),hsl(a) support would be better :) |
@norkunas Yes, I thought about it. But I was not sure if we have to support hex,rgb(a),hsl(a) in the same Constraint. I think that we should make separate Constraints to avoid to guess the format. WDYT? |
Also good idea :) |
Actually, CSS 4 defines four kinds of hexadecimal colors (https://www.w3.org/TR/css-color-4/#typedef-hex-color):
|
src/Symfony/Component/Validator/Constraints/HexaColorValidator.php
Outdated
Show resolved
Hide resolved
Interesting previous discussions on #35626 |
I would prefer HexColor instead of HexaColor |
src/Symfony/Component/Validator/Tests/Constraints/HexaColorValidatorTest.php
Outdated
Show resolved
Hide resolved
Here are some comments in case we want to move this forward:
|
src/Symfony/Component/Validator/Resources/translations/validators.fr.xlf
Outdated
Show resolved
Hide resolved
@welcoMattic How can we move forward? |
@fabpot I intend to apply Javier's comments, and make a first version of this constraint that we can improve later following user's needs. |
cf0bba7
to
cead49a
Compare
I addressed @javiereguiluz's comments about making a first usable version of CssColor Constraint, with common formats support, which are:
Let me know if we are agree on this 1st version |
src/Symfony/Component/Validator/Tests/Constraints/CssColorTest.php
Outdated
Show resolved
Hide resolved
0eae445
to
454d531
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mathieu, you've done a fantastic job here. This constraint is much more complete than I imagined. It's great!
I left some minor comments ... and I also wonder if modes
is the best word to describe the different types of CSS colors allowed by the constraint. I can't suggest a better alternative, but modes
doesn't feel 100% correct to me.
Thanks!
src/Symfony/Component/Validator/Resources/translations/validators.en.xlf
Outdated
Show resolved
Hide resolved
@javiereguiluz thanks! About status: needs review |
347b2a1
to
781598a
Compare
a741651
to
23709e7
Compare
23709e7
to
8925155
Compare
8925155
to
b36371c
Compare
Fabbot is wrong about the italian typo correction, it's |
@javiereguiluz @derrabus I don't know exactly when the feature freeze will happen, but I think this PR is ready to be merged in 5.4. |
I agree, this PR is ready. But I need a second approval to merge a feature PR. |
Thank you @welcoMattic. |
This PR was merged into the 5.4 branch. Discussion ---------- [Validator] Added CssColor constraint This PR introduces the new `CssColor` constraint, contributed in symfony/symfony#40168 Commits ------- fc1539c Added CssColor constraint
*/ | ||
public function __construct($formats, string $message = null, array $groups = null, $payload = null, array $options = null) | ||
{ | ||
$validationModesAsString = array_reduce(self::$validationModes, function ($carry, $value) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, I'm reading this PR and wondering if it wouldn't be a good idea to type things as much as we can when doing a chance?
Since Symfony 6 has better typing support, wouldn't it be a good idea to require adding typing when submitting a PR ?
Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could be great, but in this case I made a little mistake, this array_reduce
is overengineered, it has to be a implode
call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at it twice now, and indeed, it could be replace with an implode :)
This PR introduces a new
CssColor
constraint. It comes with 3 validation modes: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 addedCssColor
constraint. Let me know, if yes, I will make the change.