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

[DoctrineBridge][Validator] Expose all fields for message validation failure#38969

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

Open
ahmed-bhs wants to merge4 commits intosymfony:7.4
base:7.4
Choose a base branch
Loading
fromahmed-bhs:improve_unique_entity_message_params

Conversation

ahmed-bhs
Copy link
Contributor

@ahmed-bhsahmed-bhs commentedNov 2, 2020
edited
Loading

QA
Branch?5.x
Bug fix?no
New feature?no
Deprecations?no
Tickets
LicenseMIT
Doc PRIn progress

The main reason of the pull request is to improve the wayUniqueEntity validator provide invalide values for us.
Unfortunately, if we use the validator with more than one field, we will only have the first value at our disposal to customize the message that’s displayed when the constraint fails, cause, according to this line:
$invalidValue = isset($criteria[$errorPath]) ? $criteria[$errorPath] : $criteria[$fields[0]]; the message is always mapped to the first field causing the violation.

Imagine we have an entityDummy class, and we post ajson data that looks like this:{"foo": "space", "bar": "github"}.

/*** @ORM\Entity()* @UniqueEntity(fields={ "foo", "bar"}, message="Registration failed, the foo *{{ foo }}* is already exist for *{{ bar }}*")*/class Dummy{/*** @ORM\Column(type="string", length=255)*/private $foo;/*** @ORM\Column(type="string", length=255)*/private $bar;..}

The result that will be displayed is:Registration failed, the foo *space* is already exist for *github*" and that's more specific and friendly.

Any way, just let me know if this requires to add some unit tests or some documentation, (if it'is an interesting idea).
Best regards,

@fabpotfabpot modified the milestones:5.4,6.1Nov 16, 2021
@fabpotfabpot modified the milestones:6.1,6.2May 20, 2022
@nicolas-grekasnicolas-grekas modified the milestones:6.2,6.3Nov 5, 2022
@nicolas-grekasnicolas-grekas modified the milestones:6.3,6.4May 23, 2023
@nicolas-grekasnicolas-grekas modified the milestones:6.4,7.1Nov 15, 2023
@xabbuhxabbuh modified the milestones:7.1,7.2May 15, 2024
@fabpotfabpot modified the milestones:7.2,7.3Nov 20, 2024
@fabpotfabpot modified the milestones:7.3,7.4May 26, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@jderussejderussejderusse left review comments

Assignees
No one assigned
Projects
None yet
Milestone
7.4
Development

Successfully merging this pull request may close these issues.

6 participants
@ahmed-bhs@jderusse@fabpot@nicolas-grekas@xabbuh@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp