当前位置: 首页>>代码示例>>PHP>>正文


PHP Form\FormConfigBuilder类代码示例

本文整理汇总了PHP中Symfony\Component\Form\FormConfigBuilder的典型用法代码示例。如果您正苦于以下问题:PHP FormConfigBuilder类的具体用法?PHP FormConfigBuilder怎么用?PHP FormConfigBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了FormConfigBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testbuildViewWithWithSonataAdmin

 public function testbuildViewWithWithSonataAdmin()
 {
     $admin = $this->getMock('Sonata\\AdminBundle\\Admin\\AdminInterface');
     $admin->expects($this->once())->method('getCode')->will($this->returnValue('my.admin.reference'));
     $eventDispatcher = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface');
     $formView = new FormView();
     $options = array();
     $config = new FormConfigBuilder('test', 'stdClass', $eventDispatcher, $options);
     $config->setAttribute('sonata_admin', array('admin' => $admin, 'name' => 'name'));
     $config->setAttribute('sonata_admin_enabled', true);
     $form = new Form($config);
     $formView->vars['block_prefixes'] = array('form', 'field', 'text', '_s50b26aa76cb96_username');
     $extension = new FormTypeFieldExtension();
     $extension->buildView($formView, $form, array());
     $this->assertArrayHasKey('block_prefixes', $formView->vars);
     $this->assertArrayHasKey('sonata_admin_enabled', $formView->vars);
     $this->assertArrayHasKey('sonata_admin', $formView->vars);
     $expected = array('form', 'field', 'text', 'my_admin_reference_text', 'my_admin_reference_name_text', 'my_admin_reference_name_text_username');
     $this->assertEquals($expected, $formView->vars['block_prefixes']);
     $this->assertTrue($formView->vars['sonata_admin_enabled']);
 }
开发者ID:r1pp3rj4ck,项目名称:SonataAdminBundle,代码行数:21,代码来源:FormTypeFieldExtensionTest.php

示例2: getForm

 protected function getForm($name = 'name', $propertyPath = null, $dataClass = null, $errorMapping = array(), $virtual = false, $synchronized = true)
 {
     $config = new FormConfigBuilder($name, $dataClass, $this->dispatcher, array('error_mapping' => $errorMapping));
     $config->setMapped(true);
     $config->setVirtual($virtual);
     $config->setPropertyPath($propertyPath);
     $config->setCompound(true);
     $config->setDataMapper($this->getDataMapper());
     if (!$synchronized) {
         $config->addViewTransformer(new CallbackTransformer(function ($normData) {
             return $normData;
         }, function () {
             throw new TransformationFailedException();
         }));
     }
     return new Form($config);
 }
开发者ID:joan16v,项目名称:symfony2_test,代码行数:17,代码来源:ViolationMapperTest.php

示例3: addChoice

 /**
  * Adds a new choice.
  *
  * @param array  $bucketForPreferred The bucket where to store the preferred
  *                                   view objects.
  * @param array  $bucketForRemaining The bucket where to store the
  *                                   non-preferred view objects.
  * @param mixed  $choice             The choice to add.
  * @param string $label              The label for the choice.
  * @param array  $preferredChoices   The preferred choices.
  *
  * @throws InvalidConfigurationException If no valid value or index could be created.
  */
 protected function addChoice(array &$bucketForPreferred, array &$bucketForRemaining, $choice, $label, array $preferredChoices, $level = 0)
 {
     $index = $this->createIndex($choice);
     if ('' === $index || null === $index || !FormConfigBuilder::isValidName((string) $index)) {
         throw new InvalidConfigurationException(sprintf('The index "%s" created by the choice list is invalid. It should be a valid, non-empty Form name.', $index));
     }
     $value = $this->createValue($choice);
     if (!is_string($value)) {
         throw new InvalidConfigurationException(sprintf('The value created by the choice list is of type "%s", but should be a string.', gettype($value)));
     }
     $view = new TreeChoiceView($choice, $value, $label, $level);
     $this->choices[$index] = $this->fixChoice($choice);
     $this->values[$index] = $value;
     if ($this->isPreferred($choice, $preferredChoices)) {
         $bucketForPreferred[$index] = $view;
     } else {
         $bucketForRemaining[$index] = $view;
     }
 }
开发者ID:Charlie-Lucas,项目名称:InfiniteFormBundle,代码行数:32,代码来源:TreeChoiceList.php

示例4: getFormName

 /**
  * Get form name
  *
  * @return string
  */
 public function getFormName()
 {
     if (FormConfigBuilder::isValidName($this->exposedName)) {
         return $this->exposedName;
     }
     $name = $this->exposedName;
     $name = preg_replace('/[^a-zA-Z0-9_]/', '', $name);
     $name = preg_replace('/[^a-zA-Z0-9_\\-:]/', '', $name);
     return $name === '' ? $this->fieldName : $name;
 }
开发者ID:alebon,项目名称:graviton,代码行数:15,代码来源:AbstractField.php

示例5: testSubmitEmptyGetRequestToSimpleForm

 public function testSubmitEmptyGetRequestToSimpleForm()
 {
     $request = new Request(array(), array(), array(), array(), array(), array('REQUEST_METHOD' => 'GET'));
     $dispatcher = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface');
     $config = new FormConfigBuilder('author', null, $dispatcher);
     $config->setCompound(false);
     $form = new Form($config);
     $event = new FormEvent($form, $request);
     $listener = new BindRequestListener();
     $listener->preBind($event);
     $this->assertNull($event->getData());
 }
开发者ID:rolas123,项目名称:weather-homework,代码行数:12,代码来源:LegacyBindRequestListenerTest.php

示例6: testSetDataCannotInvokeItself

 /**
  * @expectedException \Symfony\Component\Form\Exception\RuntimeException
  */
 public function testSetDataCannotInvokeItself()
 {
     // Cycle detection to prevent endless loops
     $config = new FormConfigBuilder('name', 'stdClass', $this->dispatcher);
     $config->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
         $event->getForm()->setData('bar');
     });
     $form = new Form($config);
     $form->setData('foo');
 }
开发者ID:yceruto,项目名称:symfony,代码行数:13,代码来源:SimpleFormTest.php

示例7: testMapFormsToDataIgnoresDisabled

 public function testMapFormsToDataIgnoresDisabled()
 {
     $car = new \stdClass();
     $engine = new \stdClass();
     $propertyPath = $this->getPropertyPath('engine');
     $this->propertyAccessor->expects($this->never())->method('setValue');
     $config = new FormConfigBuilder('name', '\\stdClass', $this->dispatcher);
     $config->setByReference(true);
     $config->setPropertyPath($propertyPath);
     $config->setData($engine);
     $config->setDisabled(true);
     $form = $this->getForm($config);
     $this->mapper->mapFormsToData(array($form), $car);
 }
开发者ID:d3ancole1995,项目名称:symfony,代码行数:14,代码来源:PropertyPathMapperTest.php

示例8: testbuildViewWithNestedForm

 public function testbuildViewWithNestedForm()
 {
     $eventDispatcher = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface');
     $formView = new FormView();
     $formView->vars['name'] = 'format';
     $options = array();
     $config = new FormConfigBuilder('test', 'stdClass', $eventDispatcher, $options);
     $config->setAttribute('sonata_admin', array('admin' => false));
     $form = new Form($config);
     $formView->parent = new FormView();
     $formView->parent->vars['sonata_admin_enabled'] = true;
     $formView->parent->vars['sonata_admin_code'] = 'parent_code';
     $formView->parent->vars['name'] = 'settings';
     $formView->vars['block_prefixes'] = array('form', 'field', 'text', '_s50b26aa76cb96_settings_format');
     $extension = new FormTypeFieldExtension(array(), array());
     $extension->buildView($formView, $form, array('sonata_help' => 'help text'));
     $this->assertArrayHasKey('block_prefixes', $formView->vars);
     $this->assertArrayHasKey('sonata_admin_enabled', $formView->vars);
     $this->assertArrayHasKey('sonata_admin', $formView->vars);
     $expected = array('value' => null, 'attr' => array(), 'name' => 'format', 'block_prefixes' => array('form', 'field', 'text', 'parent_code_text', 'parent_code_text_settings_format', 'parent_code_text_settings_settings_format'), 'sonata_admin_enabled' => true, 'sonata_admin' => array('admin' => false, 'field_description' => false, 'name' => false, 'edit' => 'standard', 'inline' => 'natural', 'block_name' => false, 'class' => false, 'options' => array()), 'sonata_admin_code' => 'parent_code');
     $this->assertEquals($expected, $formView->vars);
 }
开发者ID:jerome-fix,项目名称:SonataAdminBundle,代码行数:22,代码来源:FormTypeFieldExtensionTest.php

示例9: testMapFormsToDataSkipsVirtualForms

 public function testMapFormsToDataSkipsVirtualForms()
 {
     $car = new \stdClass();
     $engine = new \stdClass();
     $parentPath = $this->getPropertyPath('name');
     $childPath = $this->getPropertyPath('engine');
     // getValue() and setValue() must never be invoked for $parentPath
     $this->propertyAccessor->expects($this->once())->method('getValue')->with($car, $childPath);
     $this->propertyAccessor->expects($this->once())->method('setValue')->with($car, $childPath, $engine);
     $config = new FormConfigBuilder('name', '\\stdClass', $this->dispatcher);
     $config->setPropertyPath($parentPath);
     $config->setVirtual(true);
     $config->setCompound(true);
     $config->setDataMapper($this->getDataMapper());
     $form = $this->getForm($config);
     $config = new FormConfigBuilder('engine', '\\stdClass', $this->dispatcher);
     $config->setByReference(true);
     $config->setPropertyPath($childPath);
     $config->setData($engine);
     $child = $this->getForm($config);
     $form->add($child);
     $this->mapper->mapFormsToData(array($form), $car);
 }
开发者ID:nfabre,项目名称:symfony,代码行数:23,代码来源:PropertyPathMapperTest.php

示例10: testFormErrorsWithNonFormComponents

 public function testFormErrorsWithNonFormComponents()
 {
     if (!class_exists(SubmitType::class)) {
         $this->markTestSkipped('Not using Symfony Form >= 2.3 with submit type');
     }
     $dispatcher = $this->createMock(EventDispatcherInterface::class);
     $factoryBuilder = new FormFactoryBuilder();
     $factoryBuilder->addType(new SubmitType());
     $factoryBuilder->addType(new ButtonType());
     $factory = $factoryBuilder->getFormFactory();
     $formConfigBuilder = new FormConfigBuilder('foo', null, $dispatcher);
     $formConfigBuilder->setFormFactory($factory);
     $formConfigBuilder->setCompound(true);
     $formConfigBuilder->setDataMapper($this->createMock(DataMapperInterface::class));
     $fooConfig = $formConfigBuilder->getFormConfig();
     $form = new Form($fooConfig);
     $form->add('save', method_exists(AbstractType::class, 'getBlockPrefix') ? SubmitType::class : 'submit');
     $this->serialize($form);
     $this->assertTrue(true);
     // Exception not thrown
 }
开发者ID:alekitto,项目名称:serializer,代码行数:21,代码来源:BaseSerializationTest.php

示例11: addTerms

 protected function addTerms(Terms $terms)
 {
     $index = $this->createIndex($terms);
     if ('' === $index || null === $index || !FormConfigBuilder::isValidName((string) $index)) {
         throw new InvalidConfigurationException(sprintf('The index "%s" created by the choice list is invalid. It should be a valid, non-empty Form name.', $index));
     }
     $value = $this->createValue($terms);
     $label = $this->createLabel($terms);
     $view = new ChoiceView($terms, $value, $label);
     $this->choices[$index] = $terms;
     $this->values[$index] = $value;
     if ($terms->isFinal()) {
         $this->final[$index] = $view;
     } else {
         $this->drafts[$index] = $view;
     }
 }
开发者ID:coopers-peele,项目名称:CPTermsBundle,代码行数:17,代码来源:TermsChoiceList.php

示例12: testSubmitEmptyGetRequestToSimpleForm

 public function testSubmitEmptyGetRequestToSimpleForm()
 {
     if (!class_exists('Symfony\\Component\\HttpFoundation\\Request')) {
         $this->markTestSkipped('The "HttpFoundation" component is not available');
     }
     $request = new Request(array(), array(), array(), array(), array(), array('REQUEST_METHOD' => 'GET'));
     $dispatcher = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface');
     $config = new FormConfigBuilder('author', null, $dispatcher);
     $config->setCompound(false);
     $form = new Form($config);
     $event = new FormEvent($form, $request);
     $listener = new BindRequestListener();
     DeprecationErrorHandler::preBind($listener, $event);
     $this->assertNull($event->getData());
 }
开发者ID:acappel01,项目名称:opencall,代码行数:15,代码来源:BindRequestListenerTest.php

示例13: getFormConfig

 /**
  * {@inheritdoc}
  */
 public function getFormConfig()
 {
     /** @var $config self */
     $config = parent::getFormConfig();
     $config->children = array();
     $config->unresolvedChildren = array();
     return $config;
 }
开发者ID:tahermarkos,项目名称:Transport,代码行数:11,代码来源:FormBuilder.php

示例14: __construct

 /**
  * Creates a new form builder.
  *
  * @param string                   $name
  * @param string                   $dataClass
  * @param EventDispatcherInterface $dispatcher
  * @param FormFactoryInterface     $factory
  * @param array                    $options
  */
 public function __construct($name, $dataClass, EventDispatcherInterface $dispatcher, FormFactoryInterface $factory, array $options = array())
 {
     parent::__construct($name, $dataClass, $dispatcher, $options);
     $this->setFormFactory($factory);
 }
开发者ID:ronnylt,项目名称:symfony,代码行数:14,代码来源:FormBuilder.php

示例15: getFormConfig

 /**
  * {@inheritdoc}
  */
 public function getFormConfig()
 {
     $config = parent::getFormConfig();
     $config->parent = null;
     $config->children = array();
     $config->unresolvedChildren = array();
     return $config;
 }
开发者ID:ronaldlunaramos,项目名称:webstore,代码行数:11,代码来源:FormBuilder.php


注:本文中的Symfony\Component\Form\FormConfigBuilder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。