public function testPrepareDefinition()
 {
     $node = new FieldNodeDefinition(self::TEST_NAME, array());
     // should set default definition values
     $this->assertEquals(0, $node->getPriority());
     $this->assertInternalType('array', $node->getOptions());
 }
 /**
  * @dataProvider constraintsProvider
  *
  * @param array $definition
  * @param array $expected
  */
 public function testPrepareValidators($definition, $expected)
 {
     $node = new FieldNodeDefinition(self::TEST_NAME, $definition);
     $result = $node->getOptions();
     $this->assertArrayHasKey('constraints', $result);
     $this->assertEquals($expected, $result['constraints']);
 }
 /**
  * @param string $widget
  *
  * @return FormInterface
  * @throws InvalidArgumentException
  */
 public function getForm($widget)
 {
     if (!$this->hasForm($widget)) {
         throw new InvalidArgumentException(sprintf('Can\'t find form for widget "%s"', $widget));
     }
     $widgetConfig = $this->configProvider->getWidgetConfig($widget);
     $fields = $widgetConfig[static::FORM_FIELDS_KEY];
     $builder = $this->formFactory->createNamedBuilder($widget);
     foreach ($fields as $name => $config) {
         $field = new FieldNodeDefinition($name, $config);
         $builder->add($field->getName(), $config['type'], $field->getOptions());
     }
     return $builder->getForm();
 }
 /**
  * @param FormBuilderInterface $form
  * @param FieldNodeDefinition  $fieldDefinition
  */
 protected function addFieldToForm(FormBuilderInterface $form, FieldNodeDefinition $fieldDefinition)
 {
     if ($fieldDefinition->getAclResource() && !$this->checkIsGranted($fieldDefinition->getAclResource())) {
         // field is not allowed to be shown, do nothing
         return;
     }
     $name = str_replace(ConfigManager::SECTION_MODEL_SEPARATOR, ConfigManager::SECTION_VIEW_SEPARATOR, $fieldDefinition->getName());
     // take config field options form field definition
     $configFieldOptions = array_intersect_key($fieldDefinition->getOptions(), array_flip(['label', 'required', 'block', 'subblock', 'tooltip', 'resettable']));
     // pass only options needed to "value" form type
     $configFieldOptions['target_field_type'] = $fieldDefinition->getType();
     $configFieldOptions['target_field_options'] = array_diff_key($fieldDefinition->getOptions(), $configFieldOptions);
     $form->add($name, 'oro_config_form_field_type', $configFieldOptions);
 }
 protected function addFieldToForm(FormBuilderInterface $form, FieldNodeDefinition $fieldDefinition)
 {
     if ($fieldDefinition->getAclResource() && !$this->checkIsGranted($fieldDefinition->getAclResource())) {
         // field is not allowed to be shown, do nothing
         return;
     }
     $name = str_replace(ConfigManager::SECTION_MODEL_SEPARATOR, ConfigManager::SECTION_VIEW_SEPARATOR, $fieldDefinition->getName());
     $form->add($name, 'oro_config_form_field_type', $fieldDefinition->toFormFieldOptions());
 }