Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

230
Views
Symfony Callback constraints on collectiontype

I want to constraint the value startTime must be lower than endTime.

Below is the inside of collectiontype form.

public function buildForm(FormBuilderInterface $builder, array $options)
{
    \Doctrine\Common\Util\Debug::dump($options);
    $builder
    ->add('startTime',TimeType::class, [
        'required' => false,
        'input' => 'string',
    ])
    ->add('endTime', TimeType::class, [
        'required' => false,
        'input' => 'string',
        'constraints'=>[
             new Assert\Callback(array($this, 'validateInterval')),
        ],
    ])
}



public function validateInterval($value, ExecutionContextInterface $context)
{
    $form = $context->getRoot();
    $data = $form->getData();

    print_r($data);

    if ($data[shoul be some number]['startTime'] >= $value) {
        $context
            ->buildViolation('The end value has to be higher than the start value')
            ->addViolation();
    }
}

$data is this below

Array ( 
    [data] => Array ( 
        [1] => Array ( 
            [id] => 1 
            [startTime] => 09:00:00 
            [endTime] => 18:00:00  
        ) 
        [2] => Array ( 
            [id] => 2 
            [startTime] => 09:00:00 
            [endTime] => 18:00:00  
        ) 
        [3] => Array ( 
            [id] => 3 
            [startTime] => 09:00:00 
            [endTime] => 18:00:00 
        ) 
        [4] => Array ( 
            [id] => 4 
            [startTime] => 09:00:00 
            [endTime] => 18:00:00  
        ) 
        [5] => Array ( 
            [id] => 5 
            [startTime] => 09:00:00 
            [endTime] => 18:00:00  
        ) 
        [6] => Array ( 
            [id] => 6 
            [startTime] => 09:00:00 
            [endTime] => 18:00:00  
        ) 
        [7] => Array ( 
            [id] => 7 
            [startTime] => 09:00:00 
            [endTime] => 18:00:00 
        ) 
    ) 
)

I want to pass the right [id] to the validateInterval constraint.

Is it possible to pass different numbers to each fields?

help me please.

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!