Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Validator] [DateTime] Addformat to error messages#58559

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

saulius334
Copy link

@saulius334saulius334 commentedOct 14, 2024
edited
Loading

QA
Branch?7.2
Bug fix?no
New feature?yes
Deprecations?no
Issues-
LicenseMIT

Problem

Currently there is no way to dynamically add theformat value into error messages when using theDateTime constraint. It has to be hardcoded on everyDateTime constraint.
For example:

#[Assert\DateTime(format:'Y-m-d', message:'Value {{ value }} is invalid. Expected format: "Y-m-d"')]public string$from;#[Assert\DateTime(format:'Y-m-d', message:'Value {{ value }} is invalid. Expected format: "Y-m-d"')]public string$to;

Goal

The goal is to add the possibility to use a parameter instead of hardcoding the selected format.
For example:

#[Assert\DateTime(format:'Y-m-d', message:'Value {{ value }} is invalid. Expected format:{{ format }}')]public string$from;

If using thesymfony translator we would even not need to set the message when creating the constraint.
For example:

$translator =newTranslator('en');$translator->addLoader('array',newArrayLoader());$translator->addResource('array', ['This value is not a valid datetime.' =>'Value {{ value }} is invalid. Expected format:{{ format }}',],'en');

Solution

When building the violations set a new parameter calledformat which represents the givenformat when theDateTime constraint is created.

valtzu reacted with thumbs up emoji
@carsonbot

This comment was marked as outdated.

@saulius334saulius334 marked this pull request as ready for reviewOctober 14, 2024 09:04
@carsonbotcarsonbot added this to the5.4 milestoneOct 14, 2024
@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has acontribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (seehttps://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (seehttps://symfony.com/releases)
  • Features and deprecations must be submitted against the 7.2 branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@OskarStarkOskarStark modified the milestones:5.4,7.2Oct 14, 2024
@OskarStark
Copy link
Contributor

Hi, thanks for this new feature. New features need to target the latest branch, which is7.2 right now.

@saulius334saulius334 changed the base branch from5.4 to7.2October 14, 2024 10:42
@saulius334
Copy link
Author

Hi, thanks for this new feature. New features need to target the latest branch, which is7.2 right now.

@OskarStark Thank you for your quick review. Changed the target branch to latest (7.2)

OskarStark reacted with thumbs up emoji

@OskarStarkOskarStark changed the title[Validator] [DateTime] Add "format" to error messages[Validator] [DateTime] Addformat to error messagesOct 14, 2024
@nicolas-grekas
Copy link
Member

Duplicate of#58602, which was rejected.
Please open an issue if you want to discuss this.

@nicolas-grekas
Copy link
Member

Aaah sorry I was too fast, that's different.

@nicolas-grekas
Copy link
Member

Please add a line to the changelog of the component.

@saulius334saulius334force-pushed thevalidator_add_datetime_format_to_violation_message branch from9e2f5ad tod5beef3CompareNovember 8, 2024 07:20
@saulius334
Copy link
Author

@nicolas-grekas Thank you for your comment. Added changes to changelog

@fabpotfabpot modified the milestones:7.2,7.3Nov 20, 2024
@saulius334
Copy link
Author

Bump, anything else I need to add/change to move this forward ?

@fabpotfabpotforce-pushed thevalidator_add_datetime_format_to_violation_message branch from996e398 toa695074CompareJanuary 5, 2025 14:43
@fabpotfabpotforce-pushed thevalidator_add_datetime_format_to_violation_message branch froma695074 to20e83b9CompareJanuary 5, 2025 14:44
@fabpot
Copy link
Member

Thank you@saulius334.

@fabpotfabpot merged commitfc65c8f intosymfony:7.3Jan 5, 2025
3 checks passed
nicolas-grekas added a commit that referenced this pull requestJan 7, 2025
This PR was merged into the 7.3 branch.Discussion----------[MonologBridge] revert test changes| Q             | A| ------------- | ---| Branch?       | 7.3| Bug fix?      | no| New feature?  | no| Deprecations? | no| Issues        || License       | MITI fail to see why these changes have been done in#58559.Commits-------71d8ec0 revert test changes
@fabpotfabpot mentioned this pull requestMay 2, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@fabpotfabpotfabpot approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
7.3
Development

Successfully merging this pull request may close these issues.

5 participants
@saulius334@carsonbot@OskarStark@nicolas-grekas@fabpot

[8]ページ先頭

©2009-2025 Movatter.jp