public function buildForm(FormBuilder $builder, array $options) { $factory = $builder->getFormFactory(); // throw new \Exception('El valor de region es '.$regionId); $builder->add('nombre')->add('apellido'); if (null == $options['data']->getId()) { $builder->add('login')->add('password', 'password', array('required' => true)); } else { $builder->add('login', null, array('read_only' => true))->add('password', 'password', array('required' => false)); } $builder->add('rut')->add('cargo')->add('profesion')->add('especialidades')->add('email')->add('email2')->add('codigoPostal')->add('direccion')->add('telefono')->add('telefono2')->add('celular')->add('empresa')->add('paginaWeb')->add('tipoUsuario', null, array('required' => true, 'preferred_choices' => array(5))); /* if (null == $options['data']->getRegion()) { $builder->add('comuna', null , array('required' => false, 'empty_value' => '...', 'choices' => array())); } else { $builder->add('comuna', 'entity', array( 'required' => false, 'class' => 'TipddyMasleadsBundle:Comunas', 'empty_value' => 'Seleccione una comuna', 'query_builder' => function(EntityRepository $repository) use ($regionId) { return $repository->createQueryBuilder('c') ->where('c.region = :region') ->setParameter('region', $regionId) ->orderBy('c.id', 'ASC'); })); } */ $builder->add('region', null, array('empty_value' => 'Seleccione', 'required' => false)); /* Probando Eventos en Formularios */ $factory = $builder->getFormFactory(); $refreshComuna = function ($form, $region) use($factory) { $form->add($factory->createNamed('entity', 'comuna', null, array('class' => 'TipddyMasleadsBundle:Comunas', 'empty_value' => $region == null ? '...' : 'Seleccione', 'label' => 'register.comuna.label', 'query_builder' => function (EntityRepository $repository) use($region) { return $repository->createQueryBuilder('c')->where('c.region = :region')->setParameter('region', $region)->orderBy('c.id', 'ASC'); }))); }; $builder->addEventListener(FormEvents::PRE_SET_DATA, function (DataEvent $event) use($refreshComuna) { $form = $event->getForm(); $data = $event->getData(); if ($data == null) { $refreshComuna($form, null); } if ($data instanceof Usuarios) { $refreshComuna($form, $data->getRegion()); } }); $builder->addEventListener(FormEvents::PRE_BIND, function (DataEvent $event) use($refreshComuna) { $form = $event->getForm(); $data = $event->getData(); if (array_key_exists('region', $data)) { $refreshComuna($form, $data['region']); } }); }
function it_should_add_rule_event_subscriber(FormBuilder $builder, FormFactoryInterface $factory) { $builder->getFormFactory()->willReturn($factory); $builder->add(Argument::any(), Argument::cetera())->willReturn($builder); $builder->addEventSubscriber(Argument::type(BuildRuleFormSubscriber::class))->willReturn($builder); $this->buildForm($builder, array()); }
function it_builds_form_with_proper_fields(FormBuilder $builder, FormFactoryInterface $factory) { $builder->getFormFactory()->willReturn($factory); $builder->addEventSubscriber(Argument::type('Sylius\\Bundle\\TaxonomyBundle\\Form\\EventListener\\BuildTaxonFormSubscriber'))->willReturn($builder); $builder->add('translations', 'a2lix_translationsForms', Argument::any())->willReturn($builder); $this->buildForm($builder, array()); }
function it_should_add_rule_event_subscriber(FormBuilder $builder, FormFactoryInterface $factory) { $builder->getFormFactory()->willReturn($factory); $builder->add(Argument::any(), Argument::cetera())->willReturn($builder); $builder->addEventSubscriber(Argument::type('Sylius\\Bundle\\ShippingBundle\\Form\\EventListener\\BuildRuleFormSubscriber'))->willReturn($builder); $this->buildForm($builder, array()); }
function it_builds_attribute_types_prototype_and_passes_it_as_argument(FormBuilder $builder, FormFactoryInterface $formFactory) { $builder->getFormFactory()->willReturn($formFactory); $builder->add('attribute', 'sylius_server_attribute_choice', Argument::any())->willReturn($builder); $builder->addEventSubscriber(Argument::any())->willReturn($builder); $this->buildForm($builder, array()); }
function it_should_add_build_promotion_action_event_subscriber(FormBuilder $builder, FormFactoryInterface $factory) { $builder->getFormFactory()->willReturn($factory); $builder->add(Argument::any(), Argument::any(), Argument::any())->willReturn($builder); $builder->addEventSubscriber(Argument::type('Sylius\\Bundle\\PromotionBundle\\Form\\EventListener\\BuildActionFormListener'))->willReturn($builder); $this->buildForm($builder, array()); }
public function buildForm(FormBuilder $builder, array $options) { if ($options['allow_add'] && $options['prototype']) { $builder->add('$$name$$', $options['type'], array_replace(array('property_path' => false, 'required' => false), $options['options'])); } $listener = new ResizeFormListener($builder->getFormFactory(), $options['type'], $options['options'], $options['allow_add'], $options['allow_delete']); $builder->addEventSubscriber($listener)->setAttribute('allow_add', $options['allow_add'])->setAttribute('allow_delete', $options['allow_delete']); }
function it_builds_form_with_proper_fields(FormBuilder $builder, FormFactoryInterface $factory) { $builder->getFormFactory()->willReturn($factory); $builder->addEventSubscriber(Argument::type(BuildTaxonFormSubscriber::class))->shouldBeCalled()->willReturn($builder); $builder->addEventSubscriber(Argument::type(AddCodeFormSubscriber::class))->shouldBeCalled()->willReturn($builder); $builder->add('translations', 'sylius_translations', Argument::any())->shouldBeCalled()->willReturn($builder); $this->buildForm($builder, []); }
function it_builds_form_with_proper_fields(FormBuilder $builder, FormFactoryInterface $factory) { $builder->getFormFactory()->willReturn($factory); $builder->add('name', 'text', Argument::any())->willReturn($builder); $builder->add('permalink', 'text', Argument::any())->willReturn($builder); $builder->add('description', 'textarea', Argument::any())->willReturn($builder); $this->buildForm($builder, []); }
/** * Adds a CSRF field to the form when the CSRF protection is enabled. * * @param FormBuilder $builder The form builder * @param array $options The options */ public function buildForm(FormBuilder $builder, array $options) { if (!$options['csrf_protection']) { return; } // use a low priority so higher priority listeners don't remove the field $builder->setAttribute('csrf_field_name', $options['csrf_field_name'])->setAttribute('csrf_provider', $options['csrf_provider'])->setAttribute('csrf_intention', $options['intention'])->setAttribute('csrf_factory', $builder->getFormFactory())->addEventSubscriber(new CsrfValidationListener($options['csrf_field_name'], $options['csrf_provider'], $options['intention'])); }
function it_builds_form_with_name_and_permalink_and_description_fields(FormBuilder $builder, FormFactoryInterface $factory) { $builder->getFormFactory()->willReturn($factory); $builder->addEventSubscriber(Argument::type('Sylius\\Bundle\\TaxonomyBundle\\Form\\EventListener\\BuildTaxonFormListener'))->willReturn($builder); $builder->add('name', 'text', Argument::any())->willReturn($builder); $builder->add('permalink', 'text', Argument::any())->willReturn($builder); $builder->add('description', 'text', Argument::any())->willReturn($builder); $this->buildForm($builder, array()); }
function it_add_form_builder_specified_by_resource_definition(MapBuilder $map, FormBuilder $builder, TextType $resource, FormFactory $factory, FormBuilder $textBuilder) { $map->hasResource('resources.resource_text')->willReturn(true); $map->getResource('resources.resource_text')->shouldBeCalled()->willReturn($resource); $builder->getFormFactory()->willReturn($factory); $resource->getFormBuilder($factory)->shouldBeCalled()->willReturn($textBuilder); $builder->add($textBuilder)->shouldBeCalled(); $this->buildForm($builder, array('resource_key' => 'resources.resource_text')); }
/** * Adds a CSRF field to the form when the CSRF protection is enabled. * * @param FormBuilder $builder The form builder * @param array $options The options */ public function buildForm(FormBuilder $builder, array $options) { if (!$options['csrf_protection']) { return; } $listener = new EnsureCsrfFieldListener($builder->getFormFactory(), $options['csrf_field_name'], $options['intention'], $options['csrf_provider']); // use a low priority so higher priority listeners don't remove the field $builder->setAttribute('csrf_field_name', $options['csrf_field_name'])->addEventListener(FormEvents::PRE_SET_DATA, array($listener, 'ensureCsrfField'), -10)->addEventListener(FormEvents::PRE_BIND, array($listener, 'ensureCsrfField'), -10); }
/** * {@inheritdoc} */ public function buildForm(FormBuilder $builder, array $options) { if ($options['allow_add'] && $options['prototype']) { $prototype = $builder->create('$$' . $options['prototype_name'] . '$$', $options['type'], $options['options']); $builder->setAttribute('prototype', $prototype->getForm()); } $listener = new ResizeFormListener($builder->getFormFactory(), $options['type'], $options['options'], $options['allow_add'], $options['allow_delete']); $builder->addEventSubscriber($listener)->setAttribute('allow_add', $options['allow_add'])->setAttribute('allow_delete', $options['allow_delete']); }
public function buildForm(FormBuilder $builder, array $options) { $listener = new ResizeFormListener( $builder->getFormFactory(), $options['type'], $options['type_options'], $options['modifiable'] ); $builder->addEventSubscriber($listener); }
function let( ServiceRegistryInterface $calculatorRegistry, ServiceRegistryInterface $checkerRegistry, FormBuilder $builder, FormFactoryInterface $factory ) { $this->beConstructedWith('ShippingMethod', array('sylius'), $calculatorRegistry, $checkerRegistry); $builder->getFormFactory()->willReturn($factory); $checkerRegistry->all()->willReturn(array()); }
public function buildForm(FormBuilder $builder, array $options) { $formFactory = $builder->getFormFactory(); $builder->add('firstname', 'text', array('label' => 'form.label.firstname'))->add('lastname', 'text', array('label' => 'form.label.lastname'))->addEventSubscriber(new MyFormSubscriber($formFactory))->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use($formFactory) { $data = $event->getData(); $form = $event->getForm(); if (null === $data) { return; } $form->add($formFactory->createNamed('zip', 'text', null, array('label' => 'form.label.zip', 'translation_domain' => 'address'))); }); }
public function buildForm(FormBuilder $builder, array $options) { if ($options['modifiable'] && $options['prototype']) { $builder->add('$$name$$', $options['type'], array( 'property_path' => false, 'required' => false, )); } $listener = new ResizeFormListener($builder->getFormFactory(), $options['type'], $options['modifiable']); $builder->addEventSubscriber($listener); }
/** * {@inheritdoc} */ public function buildForm(FormBuilder $builder, array $options) { if ($options['allow_add'] && $options['prototype']) { $prototype = $builder->create($options['prototype_name'], $options['type'], array_replace(array('label' => $options['prototype_name'] . 'label__'), $options['options'])); $builder->setAttribute('prototype', $prototype->getForm()); } $resizeListener = new ResizeFormListener($builder->getFormFactory(), $options['type'], $options['options'], $options['allow_add'], $options['allow_delete']); $builder->addEventSubscriber($resizeListener)->setAttribute('allow_add', $options['allow_add'])->setAttribute('allow_delete', $options['allow_delete']); // Enable support for adders/removers unless "by_reference" is disabled // (explicit calling of the setter is desired) if ($options['by_reference']) { $builder->addEventSubscriber(new MergeCollectionListener($options['allow_add'], $options['allow_delete'], MergeCollectionListener::MERGE_INTO_PARENT, $options['add_method'], $options['remove_method'])); } }
function it_builds_attribute_types_prototype_and_passes_it_as_argument(FormBuilder $builder, FormBuilder $fieldBuilder, FormFactoryInterface $formFactory, ChoiceListInterface $choiceList, AttributeInterface $attribute) { $builder->getFormFactory()->willReturn($formFactory); $builder->add('attribute', 'sylius_server_attribute_choice', Argument::any())->willReturn($builder); $builder->addEventSubscriber(Argument::any())->willReturn($builder); $attribute->getType()->willReturn('checkbox')->shouldBeCalled(); $attribute->getConfiguration()->willReturn(array('label' => 'sylius.form.attribute.server_attribute_value.value'))->shouldBeCalled(); $choiceList->getChoices()->willReturn(array($attribute)); $fieldBuilder->getOption('choice_list')->willReturn($choiceList); $builder->get('attribute')->willReturn($fieldBuilder); $builder->create('value', 'checkbox', array('label' => 'sylius.form.attribute.server_attribute_value.value'))->shouldBeCalled()->willReturn($fieldBuilder); $fieldBuilder->getForm()->willReturn('Form for attribute'); $builder->setAttribute('prototypes', array(0 => 'Form for attribute'))->shouldBeCalled(); $this->buildForm($builder, array()); }
function it_builds_form_with_proper_fields($feeCalculatorRegistry, FeeCalculatorInterface $feeCalculatorTest, Form $form, FormBuilder $builder, FormFactoryInterface $formFactory) { $builder->getFormFactory()->willReturn($formFactory)->shouldBeCalled(); $builder->add('translations', 'a2lix_translationsForms', Argument::any())->shouldBeCalled()->willReturn($builder); $builder->add('enabled', 'checkbox', Argument::type('array'))->willReturn($builder)->shouldBeCalled(); $builder->add('gateway', 'sylius_payment_gateway_choice', Argument::type('array'))->willReturn($builder)->shouldBeCalled(); $builder->add('feeCalculator', 'sylius_fee_calculator_choice', Argument::type('array'))->willReturn($builder)->shouldBeCalled(); $builder->addEventSubscriber(Argument::type('Sylius\\Bundle\\PaymentBundle\\Form\\Type\\EventListener\\BuildPaymentMethodFeeCalculatorFormSubscriber'))->shouldBeCalled(); $feeCalculatorRegistry->all()->willReturn(array('test' => $feeCalculatorTest))->shouldBeCalled(); $feeCalculatorTest->getType()->willReturn('test')->shouldBeCalled(); $builder->create('feeCalculatorConfiguration', 'sylius_fee_calculator_test')->willReturn($builder)->shouldBeCalled(); $builder->getForm()->willReturn($form)->shouldBeCalled(); $builder->setAttribute('feeCalculatorsConfigurations', array('test' => $form))->willReturn($builder)->shouldBeCalled(); $this->buildForm($builder, array()); }
public function buildForm(FormBuilder $builder, array $options) { $builder->add('category', 'entity', array('label' => 'Tipo de Obra:', 'empty_value' => '', 'required' => true, 'class' => 'ProjectBundle:ProjectCategory', 'query_builder' => function (ProjectRepository $repository) { return $repository->createQueryBuilder('ProjectBundle:ProjectCategory')->where('ProjectBundle:ProjectCategory.enabled = :enabled')->setParameter('enabled', true)->orderBy('ProjectBundle:ProjectCategory.name', 'ASC'); }))->add('title', null, array('label' => 'Nombre del proyecto:'))->add('image', 'hidden', array('label' => 'Imagen del proyecto:', 'error_bubbling' => false))->add('resume', 'textarea', array('label' => 'Descripción resumida del proyecto:', 'max_length' => 150))->add('description', null, array('label' => 'Descripción detallada del proyecto:', 'attr' => array('class' => 'mceEditor'), 'required' => false))->add('vurl', null, array('label' => 'Enlace vídeo:'))->add('aurl', null, array('label' => 'mp3 en Soundcloud (opcional):', 'required' => false))->add('amount', 'text', array('label' => 'Cantidad a recaudar:'))->add('days', 'text', array('label' => 'Días para recaudar fondos:'))->add('rewards', 'collection', array('type' => new RewardType(), 'allow_add' => true, 'allow_delete' => true, 'by_reference' => false, 'prototype' => true)); /* ->add('terms', 'checkbox', array('property_path' => false, )); */ $listener = new addAdminFieldsSubscriber($builder->getFormFactory()); $builder->addEventSubscriber($listener); /* if ($builder->has('terms')) { $builder->addValidator(new CallbackValidator( function (FormInterface $form){ $terms = $form->get('terms'); if (!$terms->getData()) { $terms->addError(new FormError('Debes aceptar los Términos de uso.')); } } )); }*/ }
public function buildForm(FormBuilder $builder, array $options) { $subscriber = new EntityNameFieldSubscriber($builder->getFormFactory()); $builder->addEventSubscriber($subscriber); $builder->add('fieldName', 'text', array('attr' => array('style' => 'width:120px;margin:0px;'), 'required' => true))->add('fieldType', 'choice', array('attr' => array('style' => 'width:120px;margin:0px;', 'class' => 'typeClass'), 'choices' => Field::getFieldTypes(), 'required' => true))->add('fragment', 'choice', array('attr' => array('style' => 'width:120px;margin:0px;', 'class' => 'fragmentClass'), 'choices' => Field::getFragmentTypes(), 'multiple' => false, 'required' => false, 'empty_data' => null))->add('length', 'number', array('attr' => array('style' => 'width:30px;margin:0px;'), 'required' => false))->add('search', 'checkbox', array('attr' => array('style' => 'margin:0px;'), 'required' => false))->add('required', 'checkbox', array('attr' => array('style' => 'margin:0px;'), 'required' => false))->add('bundleName', 'choice', array('attr' => array('style' => 'width:120px;margin:0px;', 'class' => 'bundleClass'), 'choices' => $this->bundles, 'required' => false))->add('entityName', 'choice', array('attr' => array('style' => 'width:120px;margin:0px;', 'class' => 'entityClass'), 'required' => false))->add('relationType', 'choice', array('attr' => array('style' => 'width:100px;margin:0px;', 'class' => 'relationClass'), 'choices' => Field::getRelationTypes(), 'multiple' => false, 'required' => false, 'empty_data' => null))->add('propertyName', 'choice', array('attr' => array('style' => 'width:120px;margin:0px;', 'class' => 'propertyClass'), 'required' => false))->add('collectionItem', 'textarea', array('attr' => array('style' => 'width:300px;margin:0px;display:none;'), 'required' => false))->add('id', 'hidden', array('attr' => array('style' => 'width:30px;margin:0px'), 'property_path' => false)); }
function let(FormBuilder $builder, FormFactoryInterface $formFactory, ServiceRegistryInterface $attributeTypeRegistry) { $this->beConstructedWith('ProductAttribute', ['sylius'], 'server', $attributeTypeRegistry); $builder->getFormFactory()->willReturn($formFactory); }
function let(FormBuilder $builder, FormFactoryInterface $formFactory) { $this->beConstructedWith('Attribute', array('sylius'), 'server'); $builder->getFormFactory()->willReturn($formFactory); }