/**
  * @param JobInterface  $job
  * @param JobParameters $jobParameters
  * @param array         $groups
  *
  * @return ConstraintViolationListInterface A list of constraint violations. If the
  *                                          list is empty, validation succeeded.
  */
 public function validate(JobInterface $job, JobParameters $jobParameters, $groups = null)
 {
     $provider = $this->registry->get($job);
     $collection = $provider->getConstraintCollection();
     $parameters = $jobParameters->all();
     $errors = $this->validator->validate($parameters, $collection, $groups);
     return $errors;
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->setDataMapper($this);
     $factory = $builder->getFormFactory();
     $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use($factory) {
         $form = $event->getForm();
         $jobInstance = $form->getRoot()->getData();
         if (null === $jobInstance->getId()) {
             return;
         }
         $job = $this->jobRegistry->get($jobInstance->getJobName());
         $configProvider = $this->configProviderRegistry->get($job);
         $configs = $configProvider->getFormConfiguration();
         $constraintProvider = $this->constraintProviderRegistry->get($job);
         $constraintsCollection = $constraintProvider->getConstraintCollection();
         $fieldConstraints = $constraintsCollection->fields;
         foreach ($configs as $parameter => $config) {
             if (isset($config['system']) && true === $config['system']) {
                 continue;
             }
             $config = array_merge(['type' => 'text', 'options' => []], $config);
             $options = array_merge(['auto_initialize' => false, 'required' => false, 'label' => ucfirst($parameter)], $config['options']);
             if (isset($fieldConstraints[$parameter])) {
                 $options['constraints'] = $fieldConstraints[$parameter]->constraints;
             }
             $form->add($factory->createNamed($parameter, $config['type'], null, $options));
         }
     });
     $builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) {
         $form = $event->getForm();
         $jobInstance = $form->getRoot()->getData();
         if (null === $jobInstance->getId()) {
             return;
         }
         $job = $this->jobRegistry->get($jobInstance->getJobName());
         $configProvider = $this->configProviderRegistry->get($job);
         $configs = $configProvider->getFormConfiguration();
         $data = $event->getData();
         if (isset($configs['filters']) && isset($data['filters'])) {
             $data['filters'] = json_decode($data['filters'], true);
         }
         $event->setData($data);
     });
 }