/**
  * @param array $expectedConfig
  * @param FormConfigInterface $actualConfig
  */
 protected function assertFormConfig(array $expectedConfig, FormConfigInterface $actualConfig)
 {
     foreach ($expectedConfig as $key => $value) {
         $this->assertTrue($actualConfig->hasOption($key));
         $this->assertEquals($value, $actualConfig->getOption($key));
     }
 }
Пример #2
0
 function it_builds_view(FormConfigInterface $config, FormView $view, FormInterface $form, FormInterface $formTable, FormInterface $formUserRegistration)
 {
     $prototypes = ['dataFetchers' => ['user_registration' => $formUserRegistration], 'renderers' => ['table' => $formTable]];
     $config->getAttribute('prototypes')->willReturn($prototypes);
     $form->getConfig()->willReturn($config);
     $formTable->createView($view)->shouldBeCalled();
     $formUserRegistration->createView($view)->shouldBeCalled();
     $this->buildView($view, $form, []);
 }
 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);
 }
 protected function getFormRuleMessage(FormConfigInterface $config)
 {
     // Get correct error message if one is set.
     if ($config->hasOption('invalid_message')) {
         $params = $config->getOption('invalid_message_parameters');
         return new RuleMessage($config->getOption('invalid_message'), is_array($params) ? $params : array());
     }
     return null;
 }
Пример #5
0
 public function __construct(FormConfigInterface $config)
 {
     if ($config->getCompound() && !$config->getDataMapper()) {
         throw new LogicException('Compound forms need a data mapper');
     }
     if ($config->getInheritData()) {
         $this->defaultDataSet = true;
     }
     $this->config = $config;
     $this->children = new OrderedHashMap();
 }
 /**
  * {@inheritdoc}
  */
 public function configure($name, array $options, array $metadata, FormConfigInterface $parentConfig)
 {
     // The implementation uses a FormTypeGuesserInterface instance in order
     // to guess the "required" value from different sources (PHPdoc,
     // validation or doctrine metadata, etc.)
     $guessed = $this->guesser->guessRequired($parentConfig->getDataClass(), $name);
     if (null !== $guessed) {
         $options['required'] = $guessed->getValue();
     }
     return $options;
 }
 /**
  * Prepare form options from config
  *
  * @param FormConfigInterface $config
  *
  * @return $config
  */
 protected function prepareOptions(FormConfigInterface $config)
 {
     $options = array('disabled' => true, 'read_only' => true);
     if ($help = $config->getOption('help')) {
         $options['help'] = $help;
     }
     if ($label = $config->getOption('label')) {
         $options['label'] = $label;
     }
     if ($select2 = $config->getOption('select2')) {
         $options['select2'] = $select2;
     }
     return $options;
 }
Пример #8
0
 /**
  * {@inheritdoc}
  */
 public function createView(FormView $parent = null)
 {
     if (null === $parent && $this->parent) {
         $parent = $this->parent->createView();
     }
     return $this->config->getType()->createView($this, $parent);
 }
 /**
  * {@inheritdoc}
  */
 public function configure($name, array $options, array $metadata, FormConfigInterface $parentConfig)
 {
     if (!isset($options['class'])) {
         $guessedOptions = $this->guesser->guessType($parentConfig->getDataClass(), $name)->getOptions();
         $options['class'] = $guessedOptions['class'];
         $options['multiple'] = $guessedOptions['multiple'];
         $options['em'] = $guessedOptions['em'];
     }
     if ($metadata['associationType'] & ClassMetadata::TO_MANY) {
         $options['attr']['multiple'] = true;
     }
     // Supported associations are displayed using advanced JavaScript widgets
     $options['attr']['data-widget'] = 'select2';
     // Configure "placeholder" option for entity fields
     if ($metadata['associationType'] & ClassMetadata::TO_ONE && !isset($options[$placeHolderOptionName = $this->getPlaceholderOptionName()]) && false === $options['required']) {
         $options[$placeHolderOptionName] = 'form.label.empty_value';
     }
     return $options;
 }
Пример #10
0
 /**
  * Reverse transforms a value if a value transformer is set.
  *
  * @param string $value The value to reverse transform
  *
  * @return mixed
  */
 private function viewToNorm($value)
 {
     $transformers = $this->config->getViewTransformers();
     if (!$transformers) {
         return '' === $value ? null : $value;
     }
     for ($i = count($transformers) - 1; $i >= 0; --$i) {
         $value = $transformers[$i]->reverseTransform($value);
     }
     return $value;
 }
Пример #11
0
 /**
  * {@inheritdoc}
  */
 public function createView(FormView $parent = null)
 {
     if (null === $parent && $this->parent) {
         $parent = $this->parent->createView();
     }
     $type = $this->config->getType();
     $options = $this->config->getOptions();
     $view = $type->createView($this, $parent);
     $type->buildView($view, $this, $options);
     $type->finishView($view, $this, $options);
     return $view;
 }
Пример #12
0
 /**
  * Buildform function.
  *
  * @param FormBuilderInterface $builder the formBuilder
  * @param array                $options the options for this form
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $entityAlias = $this->entityConfiguration['alias'];
     $entityIdGetter = $this->entityConfiguration['idGetter'];
     $fieldOptions = $this->formConfig->getOptions();
     $fieldType = $this->formConfig->getType()->getName();
     foreach ($this->locales as $locale) {
         $translatedFieldName = $locale . '_' . $this->fieldName;
         $entityId = $this->entity->{$entityIdGetter}();
         $translationData = $entityId ? $this->entityTranslationProvider->getTranslation($entityAlias, $entityId, $this->fieldName, $locale) : '';
         $builder->add($translatedFieldName, $fieldType, ['required' => isset($fieldOptions['required']) ? $this->evaluateRequired($fieldOptions['required'], $locale) : false, 'mapped' => false, 'label' => $fieldOptions['label'], 'data' => $translationData, 'constraints' => $fieldOptions['constraints']]);
     }
 }
Пример #13
0
 /**
  * Reverse transforms a value if a value transformer is set.
  *
  * @param string $value The value to reverse transform
  *
  * @return mixed
  *
  * @throws TransformationFailedException If the value cannot be transformed to "normalized" format
  */
 private function viewToNorm($value)
 {
     $transformers = $this->config->getViewTransformers();
     if (!$transformers) {
         return '' === $value ? null : $value;
     }
     try {
         for ($i = count($transformers) - 1; $i >= 0; --$i) {
             $value = $transformers[$i]->reverseTransform($value);
         }
     } catch (TransformationFailedException $exception) {
         throw new TransformationFailedException('Unable to reverse value for property path "' . $this->getPropertyPath() . '": ' . $exception->getMessage(), $exception->getCode(), $exception);
     }
     return $value;
 }
Пример #14
0
 /**
  * Get filter type name by form config
  *
  * @param FormConfigInterface $config
  *
  * @return string
  *
  * @deprecated Deprecated since version 2.0, to be removed in 2.1. Use EventDispatcher instead.
  */
 protected function getFilterTypeName(FormConfigInterface $config)
 {
     $formType = $config->getType()->getInnerType();
     return $config->hasAttribute('apply_filter') && is_string($config->getAttribute('apply_filter')) ? $config->getAttribute('apply_filter') : $formType->getName();
 }
 protected function getFormRuleMessage(FormConfigInterface $config)
 {
     // Get correct error message if one is set.
     if ($config->hasOption('invalid_message')) {
         // TODO support invalid_message_parameters
         return new RuleMessage($config->getOption('invalid_message'));
     }
     return null;
 }
 protected function validateChoiceLoaderForDefaultOptions(FormConfigInterface $config)
 {
     $this->assertNull($config->getOption('choice_loader'));
 }
Пример #17
0
 /**
  * Creates an unmodifiable copy of a given configuration.
  *
  * @param  FormConfigInterface $config The configuration to copy.
  */
 public function __construct(FormConfigInterface $config)
 {
     $dispatcher = $config->getEventDispatcher();
     if (!$dispatcher instanceof UnmodifiableEventDispatcher) {
         $dispatcher = new UnmodifiableEventDispatcher($dispatcher);
     }
     $this->dispatcher = $dispatcher;
     $this->name = $config->getName();
     $this->propertyPath = $config->getPropertyPath();
     $this->mapped = $config->getMapped();
     $this->byReference = $config->getByReference();
     $this->virtual = $config->getVirtual();
     $this->compound = $config->getCompound();
     $this->types = $config->getTypes();
     $this->viewTransformers = $config->getViewTransformers();
     $this->modelTransformers = $config->getModelTransformers();
     $this->dataMapper = $config->getDataMapper();
     $this->validators = $config->getValidators();
     $this->required = $config->getRequired();
     $this->disabled = $config->getDisabled();
     $this->errorBubbling = $config->getErrorBubbling();
     $this->emptyData = $config->getEmptyData();
     $this->attributes = $config->getAttributes();
     $this->data = $config->getData();
     $this->dataClass = $config->getDataClass();
     $this->options = $config->getOptions();
 }
 protected function validateChoiceLoaderForDefaultOptions(FormConfigInterface $config)
 {
     $this->assertInstanceOf('Symfony\\Bridge\\Doctrine\\Form\\ChoiceList\\DoctrineChoiceLoader', $config->getOption('choice_loader'));
 }
Пример #19
0
 /**
  * @param \Smarty_Internal_Template $template
  * @param FormConfigInterface       $formFieldConfig
  * @param FormView                  $formFieldView
  */
 protected function assignFormTypeValues($template, $formFieldConfig, $formFieldView)
 {
     $formFieldType = $formFieldConfig->getType()->getInnerType();
     /* access to choices */
     if ($formFieldType instanceof ChoiceType) {
         $template->assign("choices", $formFieldView->vars['choices']);
     }
     /* access to collections */
     if ($formFieldType instanceof CollectionType) {
         if (true === $formFieldConfig->getOption('prototype')) {
         } else {
             /* access to choices */
             if (isset($formFieldView->vars['choices'])) {
                 $template->assign("choices", $formFieldView->vars['choices']);
             }
         }
     }
     /* access to thelia type */
     if ($formFieldType instanceof TheliaType) {
         $template->assign("formType", $formFieldView->vars['type']);
         switch ($formFieldView->vars['type']) {
             case "choice":
                 if (!isset($formFieldView->vars['options']['choices']) || !is_array($formFieldView->vars['options']['choices'])) {
                     //throw new
                 }
                 $choices = array();
                 foreach ($formFieldView->vars['options']['choices'] as $value => $choice) {
                     $choices[] = new ChoiceView($value, $value, $choice);
                 }
                 $template->assign("choices", $choices);
                 break;
         }
     }
 }
Пример #20
0
 /**
  * @param \Smarty_Internal_Template $template
  * @param FormConfigInterface       $formFieldConfig
  * @param FormView                  $formFieldView
  */
 protected function assignFormTypeValues($template, $formFieldConfig, $formFieldView)
 {
     $formFieldType = $formFieldConfig->getType()->getInnerType();
     /* access to choices */
     if ($formFieldType instanceof ChoiceType) {
         $template->assign("choices", $formFieldView->vars['choices']);
     }
     /* access to collections */
     if ($formFieldType instanceof CollectionType) {
         if (true === $formFieldConfig->getOption('prototype')) {
         } else {
             /* access to choices */
             if (isset($formFieldView->vars['choices'])) {
                 $template->assign("choices", $formFieldView->vars['choices']);
             }
         }
     }
     /* access to date */
     if ($formFieldType instanceof DateType || $formFieldType instanceof DateTimeType || $formFieldType instanceof BirthdayType) {
         if ('choice' === $formFieldConfig->getOption('widget')) {
             /* access to years */
             if ($formFieldConfig->getOption('years')) {
                 $formFieldView->vars['years'] = $formFieldConfig->getOption('years');
                 $template->assign("years", $formFieldView->vars['years']);
             }
             /* access to month */
             if ($formFieldConfig->getOption('months')) {
                 $formFieldView->vars['months'] = $formFieldConfig->getOption('months');
                 $template->assign("months", $formFieldView->vars['months']);
             }
             /* access to days */
             if ($formFieldConfig->getOption('days')) {
                 $formFieldView->vars['days'] = $formFieldConfig->getOption('days');
                 $template->assign("days", $formFieldView->vars['days']);
             }
             /* access to empty_value */
             if ($formFieldConfig->getOption('empty_value')) {
                 $formFieldView->vars['empty_value'] = $formFieldConfig->getOption('empty_value');
                 $template->assign("empty_value", $formFieldView->vars['empty_value']);
             }
         }
     }
     /* access to thelia type */
     if ($formFieldType instanceof TheliaType) {
         $template->assign("formType", $formFieldView->vars['type']);
         switch ($formFieldView->vars['type']) {
             case "choice":
                 if (!isset($formFieldView->vars['options']['choices']) || !is_array($formFieldView->vars['options']['choices'])) {
                     //throw new
                 }
                 $choices = array();
                 foreach ($formFieldView->vars['options']['choices'] as $value => $choice) {
                     $choices[] = new ChoiceView($value, $value, $choice);
                 }
                 $template->assign("choices", $choices);
                 break;
         }
     }
 }