Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7772415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:53:07+00:00 2026-06-01T16:53:07+00:00

I have validation constraints defined in my validation.yml for my User entity, but none

  • 0

I have validation constraints defined in my validation.yml for my User
entity, but none of them are actually being called; it was working at
one point but now none of the three constraints are being checked for.
I get SQL unique constraint errors, so it’s definitely not being
handled in the code properly.

Here’s my validation.yml:

Acme\CPBundle\Entity\User:
   constraints:
        - Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity: { fields: username, message: userExists }
        - FOS\UserBundle\Validator\Unique: {property: usernameCanonical, message: userExists}
        - Callback:
            methods: [isTimeZoneValid]
   properties:
        firstName:
            - MaxLength: 255
        lastName:
            - MaxLength: 255
        username:
            - NotBlank: { groups: [create_user] }
            - MinLength: { limit: 4, groups: [create_user] }
            - MaxLength: { limit: 50, groups: [create_user] }
        email:
            - NotBlank: { groups: [create_user, edit_user] }
            - MaxLength: { limit: 255, groups: [create_user, edit_user] }
            - Email:
                message: The email "{{ value }}" is not a valid email
                checkMX: true
        plainPassword:
            - NotBlank:  { groups: [create_user] }
            - MinLength: { limit: 6, groups: [create_user], message: "passwordMin {{ limit }}" }
        newPassword:
            - MinLength: { limit: 6, groups: [edit_user], message: "passwordMin {{ limit }}" }
        singleRole:
            - Choice: { callback: getAllowedRoles }

and here’s my User Entity:

<?php

namespace Acme\CPBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use FOS\UserBundle\Model\User as BaseUser;
use Acme\CPBundle\Constant\SecurityConstant;
use Symfony\Component\Validator\ExecutionContext;

/**
* Acme\CPBundle\Entity\User
*/
class User extends BaseUser {

/**
* @var \Acme\CPBundle\Entity\Organization $organization
*/
private $organization;

/**
* @var string $firstName
*/
private $firstName;

/**
* @var string $lastName
*/
private $lastName;

/**
* @var DateTime $timeZone
*/
private $timeZone;

/**
* @var Role $singleRole
*/
private $singleRole;

/**
* @var ArrayCollection $sessions
*/
private $sessions;


/**
* @var integer $id
*/
protected $id;

public function __construct() {
    parent::__construct();
    $this->enabled = true;
    $this->sessions = new ArrayCollection();
}

public function setFirstName($firstName) {
    $this->firstName = $firstName;
}

public function getFirstName() {
    return $this->firstName;
}

public function setLastName($lastName) {
    $this->lastName = $lastName;
}

public function getLastName() {
    return $this->lastName;
}

public function setTimeZone($timeZone) {
    $this->timeZone = $timeZone;
}

public function getTimeZone() {
    return $this->timeZone;
}

public function getId() {
    return $this->id;
}

public function setOrganization(\Acme\CPBundle\Entity\Organization
    $organization) {
        $this->organization = $organization;
}

public function getOrganization() {
    return $this->organization;
}

public function setSingleRole($singleRole) {
    $this->singleRole = $singleRole;
}

public function getSingleRole() {
    return $this->singleRole;
}

public function setSessions($sessions) {
    $this->sessions = $sessions;
}

public function getSessions() {
    return $this->sessions;
}

/*
* Form Validation Methods
*/
public static function getAllowedRoles() {
    return array(SecurityConstant::ROLE_ADMIN,
        SecurityConstant::ROLE_ORG_ADMIN, SecurityConstant::ROLE_USER);
}

public function isTimeZoneValid(ExecutionContext $context) {
    $timeZoneIdentifiers = \DateTimeZone::listIdentifiers();
    if (!in_array($this->getTimeZone(), $timeZoneIdentifiers)) {
        $propertyPath = $context->getPropertyPath() . '.timeZone';
        $context->setPropertyPath($propertyPath);
        $context->addViolation('timeZoneInvalid', array(), null);
    }
}

I’ve been trying to figure this out for days, but I have no slightest
idea of what the problem may be.

Any help would be appreciated.

Thanks,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T16:53:08+00:00Added an answer on June 1, 2026 at 4:53 pm

    Apparently, you can also set the groups like any other constraints.

    constraints:
        - Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity: { fields: username, groups: [create_user, default], message: userExists }
        - FOS\UserBundle\Validator\Unique: { property: usernameCanonical, groups: [create_user, default], message: userExists }
        - Callback:
            methods: [isTimeZoneValid]
            groups: [create_user, default]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have jquery validation code which is working fine in ff but the same
In my form I have field of type entity . How to disable validation
I have a RegistrationFormType with following validation constraints: public function getDefaultOptions(array $options) { $collectionConstraint
In a class called 'Quality' I have the following constants defined: class Quality <
I'm trying to create a custom validation wherein I have defined the annotation to
I have an Entity with the field url , this entity is being persisted
I'm having a hard time figuring this validation problem. I have one parent domain
I have a entity property defined as follows public virtual string Subject { get;
I have a simple class like this, import javax.validation.constraints.NotNull; import org.hibernate.validator.constraints.Length; public class Form
I have a trouble as description below: One or more validation errors were detected

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.