public function process(FormRuleProcessorContext $context, FormRuleContextBuilder $collection)
 {
     $form = $context->getForm();
     $formConfig = $form->getConfig();
     if (!$formConfig->getCompound()) {
         return;
     }
     $transformer = $this->findTransformer($formConfig, 'Symfony\\Component\\Form\\Extension\\Core\\DataTransformer\\ValueToDuplicatesTransformer');
     if ($transformer === null) {
         return;
     }
     $keys = $this->getKeys($transformer);
     if (empty($keys)) {
         return;
     }
     $formView = $context->getView();
     // Use children here since we need the full_name
     $primary = array_shift($keys);
     $primaryView = $formView->children[$primary];
     // Copy all rules to the first child/key element
     $ruleCollection = $collection->get($formView);
     if (!empty($ruleCollection)) {
         $collection->add($primaryView, $ruleCollection);
     }
     $collection->remove($formView);
     // Get correct error message if one is set.
     $invalidMessage = $this->getFormRuleMessage($formConfig);
     // Create equalTo rules for all other fields
     $equalToPrimaryRule = new TransformerRule('equalTo', FormHelper::generateCssSelector($primaryView), $invalidMessage, array(new FieldDependency($primaryView)));
     foreach ($keys as $childName) {
         $childCollection = new RuleCollection();
         $childCollection->set('equalTo', $equalToPrimaryRule);
         $collection->add($formView->children[$childName], $childCollection);
     }
 }
 public function process(FormRuleProcessorContext $context, FormRuleContextBuilder $formRuleContext)
 {
     $form = $context->getForm();
     $formConfig = $form->getConfig();
     if (!$formConfig->getCompound()) {
         return;
     }
     /** @var \Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToArrayTransformer $transformer */
     $transformer = $this->findTransformer($formConfig, 'Symfony\\Component\\Form\\Extension\\Core\\DataTransformer\\DateTimeToArrayTransformer');
     if ($transformer === null) {
         return;
     }
     $view = $context->getView();
     $fields = $this->getTransformerFields($transformer);
     $invalidMessage = $this->getFormRuleMessage($formConfig);
     $views = array();
     $conditions = array();
     foreach ($fields as $fieldName) {
         $childView = $view->children[$fieldName];
         // Get child rules collection
         $childRules = $formRuleContext->get($childView);
         if ($childRules === null) {
             $formRuleContext->add($childView, new RuleCollection());
             $childRules = $formRuleContext->get($childView);
         }
         // Register rules
         $this->addNumberCheck($childView, $childRules, $invalidMessage, $conditions);
         $views[] = FormHelper::getFormName($childView);
         $conditions[] = new FieldDependency($childView);
     }
     if ($this->useGroupRule && count($views) > 1) {
         $rules = $formRuleContext->get(array_shift($views));
         $rules->set(CompoundCopyToChildPass::RULE_NAME_GROUP_REQUIRED, new TransformerRule(CompoundCopyToChildPass::RULE_NAME_GROUP_REQUIRED, $views, $invalidMessage));
     }
 }
 private function processDateTime(FormView $view, FormConfigInterface $config, FormRuleContextBuilder $context)
 {
     if ($config->getOption('format') !== DateTimeType::HTML5_FORMAT) {
         return;
     }
     $rules = new RuleCollection();
     $rules->set('date', new TransformerRule('date', true, $this->getFormRuleMessage($config)));
     $context->add($view, $rules);
 }
コード例 #4
0
 public function process(FormRuleProcessorContext $processContext, FormRuleContextBuilder $formRuleContext)
 {
     $constraints = $processContext->getConstraints();
     $form = $processContext->getForm();
     $collection = new RuleCollection();
     foreach ($this->mappers as $mapper) {
         foreach ($constraints as $constraint) {
             if (!$mapper->supports($constraint, $form)) {
                 continue;
             }
             $mapper->resolve($constraint, $form, $collection);
         }
     }
     $formRuleContext->add($processContext->getView(), $collection);
 }
コード例 #5
0
 protected function extractRules(FormRuleContextBuilder $formRuleContext, FormInterface $form, FormView $view)
 {
     $extracted = new FormRuleContextBuilder();
     if ($form->getConfig()->getCompound()) {
         $it = new \RecursiveIteratorIterator(new FormViewRecursiveIterator($view->getIterator()), \RecursiveIteratorIterator::SELF_FIRST);
         $found = array();
         foreach ($it as $childView) {
             $found[] = FormHelper::getFormName($childView);
         }
     } else {
         $found = array($view);
     }
     foreach ($found as $foundView) {
         $rules = $formRuleContext->get($foundView);
         if ($rules === null) {
             continue;
         }
         $extracted->add($foundView, $rules);
         $formRuleContext->remove($foundView);
     }
     return $extracted;
 }
コード例 #6
0
 /**
  * @param FormRuleContextBuilder $formRuleContext
  * @param FormView|string $view
  * @return RuleCollection|null
  */
 private function getOrCreateRuleCollection(FormRuleContextBuilder $formRuleContext, $view)
 {
     $collection = $formRuleContext->get($view);
     if ($collection !== null) {
         return $collection;
     }
     $formRuleContext->add($view, new RuleCollection());
     return $formRuleContext->get($view);
 }