2
votes

I'm trying to get in a "usable" array (for the front) all the constraints of my entity. While I've found how to do it for the constraints attached to a property (like not blank, length etc) I'm having trouble to find the UniqueEntity.

I'm using the script wrote here: symfony2 get all validation constraints on an entity (yml, xml, annotations)

And it seems that inside the:

$propertyMetadata=$metadata->getPropertyMetadata($constrainedProperty);

the UniqueEntity constraints do not appear.

So I've tried to add this code:

$entityConstraints = [];

    foreach($metadata->getConstraints() as $constraint)
    {
        var_dump($constraint);
        array_push($entityConstraints,$constraint->getTargets());
    }

and here they are but these $constraints are Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity objects, which I cannot use as an array to extract its property "fields" nor is there a method allowing that.

Is there another way to ? Or a trick I can use to get this "fields" property ?

1

1 Answers

1
votes

$fields is public property of UniqueEntity constraint, so you can just do something like

 $entityConstraints = array_merge($entityConstraints, $constraint->fields);