Skip to content

[Form] Wrong cause constraint associated with top level form errors #25542

@SwanMougnoz

Description

@SwanMougnoz
Q A
Bug report? yes
Feature request? no
BC Break report? /no
RFC? no
Symfony version 2.8

Hi,

I'm trying to attach payload options to several form constraints in order to provide error codes in addition to messages with my API.

When the form is submitted, payloads are successfully attached to the corresponding fields and I'm able to process it excepts for top level errors which seems to provide inconsistent results.

When additional fields are submitted

An error with 'This form should not contain extra fields' is present (which is the wanted behaviour). But if a look at the associated constraint under (FormError) $error->getCause()->getConstraint, the designated constraint is a random constraint from another field of the form. Which is totally unrelated and can contains a totally unrelated payload.

With a UniqueEntity constraint

The error is mapped to the form top level error property but with no payload. The concerned field also show an error but with the expected payload.

The problem is easily reproducible with a standard FOSUserBundle setup with default fos_user_registration_register POST route. UniqueContraint being on email and payloads can be attached to desired field.

/**
 * @Assert\Email(payload={"error_code": "USER_INVALID_EMAIL"})
 * @var string
 */
protected $email;

May I have some help on this please ?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions