當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。