Author: Kamil Kokot (kamil.kokot@lakion.com)
コード例 #1
0
ファイル: AttributeType.php プロジェクト: sylius/sylius
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->addEventSubscriber(new AddCodeFormSubscriber())->add('translations', ResourceTranslationsType::class, ['entry_type' => $this->attributeTranslationType, 'label' => 'sylius.form.attribute.translations'])->add('type', AttributeTypeChoiceType::class, ['label' => 'sylius.form.attribute.type', 'disabled' => true]);
     $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
         $attribute = $event->getData();
         if (!$attribute instanceof AttributeInterface) {
             return;
         }
         if (!$this->formTypeRegistry->has($attribute->getType(), 'configuration')) {
             return;
         }
         $event->getForm()->add('configuration', $this->formTypeRegistry->get($attribute->getType(), 'configuration'), ['auto_initialize' => false, 'label' => 'sylius.form.attribute_type.configuration']);
     });
 }
コード例 #2
0
 /**
  * @param FormInterface $form
  * @param string $calculatorName
  * @param array $data
  */
 protected function addConfigurationFields(FormInterface $form, $calculatorName, array $data = [])
 {
     /** @var CalculatorInterface $calculator */
     $calculator = $this->calculatorRegistry->get($calculatorName);
     $calculatorType = $calculator->getType();
     if (!$this->formTypeRegistry->has($calculatorType, 'default')) {
         return;
     }
     $configurationField = $this->factory->createNamed('configuration', $this->formTypeRegistry->get($calculatorType, 'default'), $data, ['auto_initialize' => false]);
     $form->add($configurationField);
 }
コード例 #3
0
ファイル: ShippingMethodType.php プロジェクト: sylius/sylius
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->addEventSubscriber($this->buildShippingMethodFormSubscriber)->addEventSubscriber(new AddCodeFormSubscriber())->add('translations', ResourceTranslationsType::class, ['entry_type' => $this->shippingMethodTranslationType, 'label' => 'sylius.form.shipping_method.translations'])->add('position', IntegerType::class, ['required' => false, 'label' => 'sylius.form.shipping_method.position'])->add('category', ShippingCategoryChoiceType::class, ['required' => false, 'placeholder' => 'sylius.ui.no_requirement', 'label' => 'sylius.form.shipping_method.category'])->add('categoryRequirement', ChoiceType::class, ['choices' => array_flip(ShippingMethod::getCategoryRequirementLabels()), 'multiple' => false, 'expanded' => true, 'label' => 'sylius.form.shipping_method.category_requirement'])->add('calculator', CalculatorChoiceType::class, ['label' => 'sylius.form.shipping_method.calculator'])->add('enabled', CheckboxType::class, ['label' => 'sylius.form.locale.enabled']);
     $prototypes = ['rules' => [], 'calculators' => []];
     /** @var RuleCheckerInterface $checker */
     foreach ($this->checkerRegistry->all() as $type => $checker) {
         $prototypes['rules'][$type] = $builder->create('__name__', $checker->getConfigurationFormType())->getForm();
     }
     /** @var CalculatorInterface $calculator */
     foreach ($this->calculatorRegistry->all() as $name => $calculator) {
         $calculatorType = $calculator->getType();
         if (!$this->formTypeRegistry->has($calculatorType, 'default')) {
             continue;
         }
         $form = $builder->create('configuration', $this->formTypeRegistry->get($calculatorType, 'default'));
         $prototypes['calculators'][$name] = $form->getForm();
     }
     $builder->setAttribute('prototypes', $prototypes);
 }
コード例 #4
0
ファイル: AttributeValueType.php プロジェクト: sylius/sylius
 /**
  * @param FormInterface $form
  * @param AttributeInterface $attribute
  */
 protected function addValueField(FormInterface $form, AttributeInterface $attribute)
 {
     $form->add('value', $this->formTypeRegistry->get($attribute->getType(), 'default'), ['auto_initialize' => false, 'label' => $attribute->getName()]);
 }