本文整理汇总了PHP中Symfony\Component\Form\FormFactoryInterface类的典型用法代码示例。如果您正苦于以下问题:PHP FormFactoryInterface类的具体用法?PHP FormFactoryInterface怎么用?PHP FormFactoryInterface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FormFactoryInterface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
protected function setUp()
{
$this->dispatcher = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface');
$this->factory = $this->getMock('Symfony\\Component\\Form\\FormFactoryInterface');
$this->builder = new TestFormBuilder('name', null, $this->dispatcher, $this->factory);
$this->factory->expects($this->any())->method('createNamedBuilder')->willReturn($this->builder);
}
示例2:
function it_creates_the_object_if_form_is_a_class_name(RequestConfiguration $requestConfiguration, ResourceInterface $resource, FormFactoryInterface $formFactory, FormInterface $form)
{
$requestConfiguration->isHtmlRequest()->willReturn(true);
$requestConfiguration->getFormType()->willReturn(TextType::class);
$formFactory->create(Argument::type(TextType::class), $resource)->willReturn($form);
$this->create($requestConfiguration, $resource)->shouldReturn($form);
}
示例3:
function it_gets_form_from_class_name(Configuration $configuration, FormFactoryInterface $formFactory, FormInterface $form)
{
$formClass = 'spec\\Sylius\\Bundle\\ResourceBundle\\Controller\\TestFormType';
$configuration->getFormType()->willReturn($formClass);
$formFactory->create(Argument::type($formClass), Argument::cetera())->shouldBeCalled()->willReturn($form);
$this->getForm()->shouldReturn($form);
}
示例4: getFormBuilder
/**
* {@inheritdoc}
*/
public function getFormBuilder(FormFactoryInterface $factory)
{
if (!isset($this->formBuilder)) {
$this->formBuilder = $factory->createNamedBuilder($this->getResourceProperty(), $this->getFormType(), null, $this->buildFormOptions());
}
return $this->formBuilder;
}
示例5: createForm
/**
* @param mixed|null $data
* @param array $options
*
* @return \Symfony\Component\Form\FormInterface
*/
public function createForm($data = null, array $options = [])
{
if ($data != null) {
$this->setData($data);
}
return $this->formFactory->create($this->type, null, array_merge($this->options, $options));
}
示例6: switchLocaleAction
public function switchLocaleAction(Request $request)
{
$this->guard->userIsLoggedIn();
$this->logger->notice('User requested to switch locale');
$returnUrl = $request->query->get('return-url');
// Return URLs generated by us always include a path (ie. at least a forward slash)
// @see https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpFoundation/Request.php#L878
$domain = $request->getSchemeAndHttpHost() . '/';
if (strpos($returnUrl, $domain) !== 0) {
$this->logger->error(sprintf('Illegal return-url ("%s") for redirection after changing locale, aborting request', $returnUrl));
throw new BadRequestHttpException('Invalid return-url given');
}
$command = new ChangeLocaleCommand();
$form = $this->formFactory->create('profile_switch_locale', $command, [])->handleRequest($request);
$this->logger->notice(sprintf('Switching locale from "%s" to "%s"', $request->getLocale(), $command->newLocale));
if ($form->isValid()) {
$this->userService->changeLocale($command);
$this->flashBag->add('success', 'profile.locale.locale_change_success');
$this->logger->notice(sprintf('Successfully switched locale from "%s" to "%s"', $request->getLocale(), $command->newLocale));
} else {
$this->flashBag->add('error', 'profile.locale.locale_change_fail');
$this->logger->error('Locale not switched: the switch locale form contained invalid data');
}
return new RedirectResponse($returnUrl);
}
示例7: create
/**
* {@inheritdoc}
*/
public function create($namespace, $data = null, array $options = [])
{
$schema = $this->schemaRegistry->getSchema($namespace);
$builder = $this->formFactory->createBuilder('form', $data, array_merge_recursive(['data_class' => null], $options));
$schema->buildForm($builder);
return $builder->getForm();
}
示例8: getForm
/**
* {@inheritDoc}
*/
public function getForm()
{
if (!$this->form) {
$this->form = $this->formFactory->create($this->getFormType(), [], array_merge($this->getOr(FilterUtility::FORM_OPTIONS_KEY, []), ['csrf_protection' => false]));
}
return $this->form;
}
示例9: getItemFormView
/**
* @param array $options
*
* @return FormView
*/
public function getItemFormView(array $options = array())
{
$cartItem = $this->cartItemFactory->createNew();
$this->orderItemQuantityModifier->modify($cartItem, 1);
$form = $this->formFactory->create('sylius_cart_item', $cartItem, $options);
return $form->createView();
}
示例10: getForm
/**
* @param Location $location
* @return \Symfony\Component\Form\FormInterface
* @throws \Heliopsis\eZFormsBundle\Exceptions\UnknownFormException
*/
public function getForm(Location $location)
{
if (!isset($this->map[$location->contentInfo->remoteId])) {
throw new UnknownFormException(sprintf("No form could be mapped to content remote id %s", $location->contentInfo->remoteId));
}
return $this->formFactory->create($this->map[$location->contentInfo->remoteId]);
}
示例11: testSubmit
public function testSubmit()
{
$this->translatableResource->expects($this->once())->method('getModel')->will($this->returnValue(TranslatableTest::class));
$this->translatableResource->expects($this->once())->method('getRelation')->with($this->identicalTo('translation'))->will($this->returnValue($translationResource = $this->createResourceMock()));
$translationResource->expects($this->once())->method('getForm')->will($this->returnValue(TranslationTestType::class));
$this->translatableFactory->expects($this->once())->method('create')->will($this->returnValue(new TranslatableTest()));
$form = $this->formFactory->create(TranslatableTestType::class)->submit(['translations' => ['en' => ['value' => 'value-en'], 'fr' => ['value' => 'value-fr']]]);
$translatable = $form->getData();
$view = $form->createView();
$this->assertInstanceOf(TranslatableTest::class, $translatable);
$this->assertCount(1, $view->children);
$this->assertArrayHasKey('translations', $view->children);
$this->assertCount(2, $translatable->getTranslations());
$this->assertTrue($translatable->getTranslations()->containsKey('en'));
$this->assertTrue($translatable->getTranslations()->containsKey('fr'));
$this->assertCount(2, $view->children['translations']);
$this->assertArrayHasKey('en', $view->children['translations']);
$this->assertArrayHasKey('fr', $view->children['translations']);
$this->assertInstanceOf(TranslationTest::class, $translatable->getTranslations()['en']);
$this->assertSame('value-en', $translatable->getTranslations()['en']->getValue());
$this->assertCount(1, $view->children['translations']['en']);
$this->assertArrayHasKey('value', $view->children['translations']['en']);
$this->assertInstanceOf(TranslationTest::class, $translatable->getTranslations()['fr']);
$this->assertSame('value-fr', $translatable->getTranslations()['fr']->getValue());
$this->assertCount(1, $view->children['translations']['fr']);
$this->assertArrayHasKey('value', $view->children['translations']['fr']);
}
示例12: process
/**
*
* @param Request $request
* @param AbstractType|string $formType
* @param Query $query
* @param string $sessionKey
* @param array $formOptions
* @return array
*/
public function process(Request $request, $formType, $query, $sessionKey, array $formOptions = array())
{
$filterForm = $this->formFactory->create($formType, null, $formOptions);
$method = $filterForm->getConfig()->getMethod();
$requestData = $method == 'GET' ? $request->query->get($filterForm->getName()) : $request->request->get($filterForm->getName());
if (isset($requestData['reset'])) {
if ($method == 'POST') {
$request->getSession()->remove($sessionKey);
return array($filterForm, null, true);
}
$request->getSession()->set($sessionKey, array());
$requestData = array();
}
$filterData = empty($requestData) ? $request->getSession()->get($sessionKey, $requestData) : $requestData;
if (!empty($filterData)) {
$this->applyFilter($filterForm, $filterData, $query);
if (empty($filterData)) {
$request->getSession()->remove($sessionKey);
} else {
$request->getSession()->set($sessionKey, $filterData);
}
}
$this->updatePerPage($request, $sessionKey);
$page = $request->query->get($this->knpParams['pageParameterName'], 1);
$event = $this->eventDispatcher->dispatch(FilterEvent::POST_FILTER, new FilterEvent($query));
if ($event->hasNewQuery()) {
$query = $event->getNewQuery();
}
return array($filterForm, $this->paginator->paginate($query, $page, $this->perPage, $this->knpParams), false);
}
示例13: createForm
/**
* Gets the form
*
* @param \Sonata\AdminBundle\Util\AdminObjectAclData $data
* @return \Symfony\Component\Form\Form
*/
public function createForm(AdminObjectAclData $data)
{
// Retrieve object identity
$objectIdentity = ObjectIdentity::fromDomainObject($data->getObject());
$acl = $data->getSecurityHandler()->getObjectAcl($objectIdentity);
if (!$acl) {
$acl = $data->getSecurityHandler()->createAcl($objectIdentity);
}
$data->setAcl($acl);
$masks = $data->getMasks();
// Create a form to set ACL
$formBuilder = $this->formFactory->createBuilder('form');
foreach ($data->getAclUsers() as $aclUser) {
$securityIdentity = UserSecurityIdentity::fromAccount($aclUser);
foreach ($data->getUserPermissions() as $permission) {
try {
$checked = $acl->isGranted(array($masks[$permission]), array($securityIdentity));
} catch (NoAceFoundException $e) {
$checked = false;
}
$formBuilder->add($aclUser->getId() . $permission, 'checkbox', array('required' => false, 'data' => $checked));
}
}
$form = $formBuilder->getForm();
$data->setForm($form);
return $form;
}
示例14: testIcon
public function testIcon()
{
$form = $this->factory->create(FormType::class, null, ['icon' => $icon = 'my.icon']);
$view = $form->createView();
$this->assertArrayHasKey('icon', $view->vars);
$this->assertSame($icon, $view->vars['icon']);
}
示例15: couldBeCreatedByFormFactory
/**
* @test
*/
public function couldBeCreatedByFormFactory()
{
$form = $this->formFactory->create('payum_gateway_config', null, array('data_class' => 'Payum\\Core\\Model\\GatewayConfig'));
$view = $form->createView();
$this->assertInstanceOf('Symfony\\Component\\Form\\FormInterface', $form);
$this->assertInstanceOf('Symfony\\Component\\Form\\FormView', $view);
}