Skip to content

Choice assert with callback fails inside the All assert #21706

@murilolobato

Description

@murilolobato
Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no
Symfony version 2.8.14

If I try to use the Assert\Choice inside the Assert\All, like following I receive a The choice constraint expects a valid callback error message.

// src/AppBundle/Entity/User.php
namespace AppBundle\Entity;

use Symfony\Component\Validator\Constraints as Assert;

class User
{
    /**
     * @Assert\Count(min="1")
     * @Assert\All({
     *     @Assert\Choice(callback={"getValidColors"})
     * })
     */
     protected $favoriteColors = array();

     public static function getValidColors()
     {
          return array('red', 'green', 'blue');
     }
}

The error message:
image

To walkaround this problem, I've added the full-qualified-class-name to the first paramater of the callback option of the Assert\Choice, as follow:

// src/AppBundle/Entity/User.php
namespace AppBundle\Entity;

use Symfony\Component\Validator\Constraints as Assert;

class User
{
    /**
     * @Assert\Count(min="1")
     * @Assert\All({
     *     @Assert\Choice(callback={"AppBundle\Entity\User", "getValidColors"})
     * })
     */
     protected $favoriteColors = array();

     public static function getValidColors()
     {
          return array('red', 'green', 'blue');
     }
}

And this way it has worked, but this method is not covered at any documentation. I'm willing to help if I know what needs to be done.

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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy