php Symfony-Component-Form-FormConfigBuilder类(方法)实例源码

下面列出了php Symfony-Component-Form-FormConfigBuilder 类(方法)源码代码实例,从而了解它的用法。

作者:r1pp3rj4c    项目:SonataAdminBundl   
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']);
 }

作者:joan16    项目:symfony2_tes   
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);
 }

作者:Charlie-Luca    项目:InfiniteFormBundl   
/**
  * 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;
     }
 }

作者:alebo    项目:gravito   
/**
  * 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;
 }

作者:rolas12    项目:weather-homewor   
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());
 }

作者:ycerut    项目:symfon   
/**
  * @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');
 }

作者:d3ancole199    项目:symfon   
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);
 }

作者:jerome-fi    项目:SonataAdminBundl   
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);
 }

作者:nfabr    项目:symfon   
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);
 }

作者:alekitt    项目:serialize   
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
 }

作者:coopers-peel    项目:CPTermsBundl   
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;
     }
 }

作者:acappel0    项目:opencal   
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());
 }

作者:tahermarko    项目:Transpor   
/**
  * {@inheritdoc}
  */
 public function getFormConfig()
 {
     /** @var $config self */
     $config = parent::getFormConfig();
     $config->children = array();
     $config->unresolvedChildren = array();
     return $config;
 }

作者:ronnyl    项目:symfon   
/**
  * 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);
 }

作者:ronaldlunaramo    项目:webstor   
/**
  * {@inheritdoc}
  */
 public function getFormConfig()
 {
     $config = parent::getFormConfig();
     $config->parent = null;
     $config->children = array();
     $config->unresolvedChildren = array();
     return $config;
 }


问题


面经


文章

微信
公众号

扫码关注公众号