作者:mcdi
项目:SonatraFormExtensionsBundl
protected function setUp()
{
parent::setUp();
$this->factory = Forms::createFormFactoryBuilder()->addExtensions($this->getExtensions())->addTypeExtension(new DateTimeJqueryTypeExtension())->addTypeExtension(new DateJqueryTypeExtension())->addTypeExtension(new BirthdayJqueryTypeExtension())->getFormFactory();
$this->dispatcher = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface');
$this->builder = new FormBuilder(null, null, $this->dispatcher, $this->factory);
}
作者:Maksol
项目:platfor
protected function setUp()
{
$this->factory = Forms::createFormFactoryBuilder()->addTypeExtension(new DataBlockExtension())->getFormFactory();
$templateRenderer = $this->getMock('Oro\\Bundle\\FormBundle\\Form\\Builder\\TemplateRendererInterface');
$templateRenderer->expects($this->any())->method('render')->will($this->returnArgument(0));
$this->builder = new DataBlockBuilder($templateRenderer, 'form');
}
作者:php-lu
项目:lu
/**
* {@inheritdoc}
*/
protected function setUp()
{
$this->translatableType = new TranslatableType();
$this->translatableResource = $this->createResourceMock();
$this->translatableFactory = $this->createFactoryMock();
$this->formFactory = Forms::createFormFactoryBuilder()->addType(new ResourceType())->addType($this->translatableType)->addType(new TranslationsFormsType(new TranslationForm($this->createFormRegistryMock(), $this->createManagerRegistryMock()), new TranslationsFormsListener(), new DefaultProvider(['en', 'fr'], 'en', ['en'])))->addType(new TranslationTestType())->addType(new TranslatableTestType($this->translatableResource, $this->translatableFactory))->getFormFactory();
}
作者:piotrantosi
项目:Payu
protected function setUp()
{
$this->fooGatewayFactoryMock = $this->getMock('Payum\\Core\\GatewayFactoryInterface');
$registry = $this->getMock('Payum\\Core\\Registry\\GatewayFactoryRegistryInterface');
$registry->expects($this->any())->method('getGatewayFactory')->with('foo')->willReturn($this->fooGatewayFactoryMock);
$this->formFactory = Forms::createFormFactoryBuilder()->addType(new GatewayFactoriesChoiceType(array('foo' => 'Foo Factory')))->addType(new GatewayConfigType($registry))->getFormFactory();
}
作者:Maksol
项目:platfor
protected function setUp()
{
parent::setUp();
$validator = new Validator(new ClassMetadataFactory(new LoaderChain([])), new ConstraintValidatorFactory(), new DefaultTranslator());
$this->factory = Forms::createFormFactoryBuilder()->addTypeExtension(new DataBlockExtension())->addTypeExtension(new FormTypeValidatorExtension($validator))->getFormFactory();
$this->type = new EntityType(new ExtendDbIdentifierNameGenerator());
}
作者:stef
项目:CompetencyBundl
protected function setUp()
{
parent::setUp();
$validator = $this->getMock('Symfony\\Component\\Validator\\ValidatorInterface');
$validator->expects($this->any())->method('validate')->willReturn([]);
$this->factory = Forms::createFormFactoryBuilder()->addExtensions($this->getExtensions())->addTypeExtension(new FormTypeValidatorExtension($validator))->getFormFactory();
}
作者:juniorab
项目:TRD
public function ajouterAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$sysmatricule = $this->get('trc_core.matricule');
$profil = new Profil();
$formFactory = Forms::createFormFactory();
$form = $this->get('form.factory')->create(new ProfilType(), $profil);
if ($form->handleRequest($request)->isValid()) {
$profil->setMatricule($sysmatricule->matriculeStandard($profil));
$em->persist($profil);
$em->flush();
return $this->redirect($this->generateUrl('trc_admin_profils'));
}
$p = 1;
$nbre = 5;
$criteres = array();
if ($request->query->get('p') !== null && !empty($request->query->get('p'))) {
$p = $request->query->get('p');
}
$id = ($p - 1) * $nbre;
if ($id < 0) {
$id = 0;
}
$profils = $em->getRepository('TRCCoreBundle:Profil')->findBy($criteres, array(), $nbre, $id);
$servicePagination = $this->get('trc_core.pagination');
$objet = 'Profil';
$url = $this->generateUrl('trc_admin_profils');
$urlRoute = 'trc_admin_profils';
$pagination = $servicePagination->pagination($objet, $p, $url, $urlRoute, $criteres, $nbre);
return $this->render('TRCAdminBundle:Profils:ajouter.html.twig', array('form' => $form->createView(), 'profils' => $profils, 'pagination' => $pagination));
}
作者:JPunt
项目:Symfon
protected function setUp()
{
if (!class_exists('Symfony\\Component\\EventDispatcher\\EventDispatcher')) {
$this->markTestSkipped('The "EventDispatcher" component is not available');
}
$this->factory = Forms::createFormFactoryBuilder()->addExtensions($this->getExtensions())->getFormFactory();
}
作者:helios-a
项目:FMTinyMCEBundl
/**
* {@inheritdooc}.
*/
protected function setUp()
{
parent::setUp();
$params = self::$kernel->getContainer()->get('service_container')->getParameter('fm_tinymce');
$this->tinyMCEtype = new TinyMCEType($params);
$this->factory = Forms::createFormFactoryBuilder()->addType($this->tinyMCEtype)->getFormFactory();
}
作者:pigroup
项目:SfynxCoreBundl
protected function setUp()
{
parent::setUp();
$this->factory = Forms::createFormFactoryBuilder()->addTypeExtension(new FormTypeValidatorExtension($this->getMock('Symfony\\Component\\Validator\\ValidatorInterface')))->addTypeGuesser($this->getMockBuilder('Symfony\\Component\\Form\\Extension\\Validator\\ValidatorTypeGuesser')->disableOriginalConstructor()->getMock())->getFormFactory();
$this->dispatcher = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface');
$this->builder = new FormBuilder(null, null, $this->dispatcher, $this->factory);
}
作者:silvestr
项目:banne
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
$this->zoneProvider = $this->getMock('Silvestra\\Component\\Banner\\Provider\\BannerZoneProviderInterface');
$this->factory = Forms::createFormFactoryBuilder()->addTypeExtension($this->createValidatorExtension())->addTypeGuesser($this->getMockValidatorTypeGuesser())->addTypes(array(new BannerZoneType('Silvestra\\Component\\Banner\\Model\\BannerZone', $this->zoneProvider)))->getFormFactory();
$this->builder = $this->createFormBuilder();
}
作者:radph
项目:categories-bundl
/**
* Get form
*
* @param Category $category
*
* @return \Symfony\Component\Form\Form
* @throws \Rad\DependencyInjection\Exception\ServiceNotFoundException
*/
public function getForm(Category $category = null)
{
$data = null;
if ($category) {
$data = $category->toArray();
}
$action = $category ? Container::get('router')->generateUrl(['categories', $data['id']]) : Container::get('router')->generateUrl(['categories']);
$formFactory = Forms::createFormFactory();
$options = ['action' => $action, 'method' => $category ? 'PUT' : 'POST'];
$event = $this->getEventManager()->dispatch(self::EVENT_CATEGORIES_FORM_SCOPE, $this);
/** @var CategoriesTable $categoriesTable */
$categoriesTable = TableRegistry::get('Categories.Categories');
$treeList = $categoriesTable->find('treeList');
if (!empty($category)) {
$treeList->where(['id !=' => $data['id']]);
}
$formBuilder = $formFactory->createBuilder('form', $data, $options)->add('title', 'text', ['required' => true, 'attr' => ['class' => 'form-control']])->add('slug', 'text', ['required' => true, 'attr' => ['class' => 'form-control']])->add('parent_id', 'choice', ['choices' => $treeList->toArray(), 'empty_data' => null, 'empty_value' => 'No Parent', 'label' => 'Parent', 'required' => false]);
if (!empty($event->getResult())) {
$choices = $event->getResult();
if (!is_array($choices)) {
$choices = [$choices];
}
$formBuilder->add('scope', 'choice', ['choices' => $choices, 'label' => 'Group']);
}
return $formBuilder->add('description', 'textarea', ['required' => false, 'attr' => ['class' => 'form-control wysiwyg']])->add('submit', 'submit')->getForm();
}
作者:reskum
项目:form-bundl
/**
* Prepare tests and include custom form options.
*/
protected function setUp()
{
// add TopicTypeExtension
$this->factory = Forms::createFormFactoryBuilder()->addExtensions($this->getExtensions())->addTypeExtension(new OptionalTypeExtension())->getFormFactory();
$this->dispatcher = $this->getMockBuilder('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface')->getMock();
$this->builder = new FormBuilder(null, null, $this->dispatcher, $this->factory);
}
作者:jbartfa
项目:TrsteelCkeditorBundl
/**
* {@inheritdooc}.
*/
public function setUp()
{
parent::setUp();
$ckeditorType = new CkeditorType($this->get('service_container'));
$this->factory = Forms::createFormFactoryBuilder()->addType($ckeditorType)->getFormFactory();
$this->formType = method_exists('Symfony\\Component\\Form\\AbstractType', 'getBlockPrefix') ? 'Trsteel\\CkeditorBundle\\Form\\Type\\CkeditorType' : 'ckeditor';
}
作者:hirenbhut9
项目:MopaBootstrapBundl
/**
* @throws \Twig_Error_Loader
*/
protected function setUp()
{
// Setup factory for tabs
$this->tabFactory = Forms::createFormFactory();
parent::setUp();
$rendererEngine = new TwigRendererEngine(array('form_div_layout.html.twig', 'fields.html.twig'));
if (interface_exists('Symfony\\Component\\Security\\Csrf\\CsrfTokenManagerInterface')) {
$csrfProviderInterface = 'Symfony\\Component\\Security\\Csrf\\CsrfTokenManagerInterface';
} else {
$csrfProviderInterface = 'Symfony\\Component\\Form\\Extension\\Csrf\\CsrfProvider\\CsrfProviderInterface';
}
$renderer = new TwigRenderer($rendererEngine, $this->getMock($csrfProviderInterface));
$this->extension = new FormExtension($renderer);
$reflection = new \ReflectionClass($renderer);
$bridgeDirectory = dirname($reflection->getFileName()) . '/../Resources/views/Form';
$loader = new \Twig_Loader_Filesystem(array($bridgeDirectory, __DIR__ . '/../../Resources/views/Form'));
$loader->addPath(__DIR__ . '/../../Resources/views', 'MopaBootstrap');
$environment = new Twig_Environment($loader, array('strict_variables' => true));
$environment->addExtension(new TranslationExtension(new StubTranslator()));
$environment->addExtension(new IconExtension('fontawesome'));
$environment->addExtension(new FormExtension2());
$environment->addGlobal('global', '');
$environment->addExtension($this->extension);
$this->extension->initRuntime($environment);
}
作者:nmallar
项目:platfor
protected function setUp()
{
$this->em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
$translator = $this->getMock('Symfony\\Component\\Translation\\TranslatorInterface');
$translator->expects($this->any())->method('trans')->will($this->returnArgument(0));
$registry = $this->getMockForAbstractClass('Doctrine\\Common\\Persistence\\ManagerRegistry', [], '', false);
$registry->expects($this->any())->method('getManagerForClass')->will($this->returnValue($this->em));
$this->formFactory = Forms::createFormFactoryBuilder()->addExtensions([new PreloadedExtension(['oro_type_filter' => new FilterType($translator), 'oro_type_choice_filter' => new ChoiceFilterType($translator), 'entity' => new EntityType($registry), 'oro_type_entity_filter' => new EntityFilterType($translator)], []), new CsrfExtension($this->getMock('Symfony\\Component\\Form\\Extension\\Csrf\\CsrfProvider\\CsrfProviderInterface'))])->getFormFactory();
$classMetaData = $this->getMockBuilder('Doctrine\\ORM\\Mapping\\ClassMetadata')->disableOriginalConstructor()->getMock();
$classMetaData->expects($this->any())->method('getName')->will($this->returnValue('OroSegment:Segment'));
$classMetaData->expects($this->any())->method('getIdentifier')->will($this->returnValue(['id']));
$this->em->expects($this->any())->method('getClassMetadata')->will($this->returnValue($classMetaData));
$this->dynamicSegmentQueryBuilder = $this->getMockBuilder('Oro\\Bundle\\SegmentBundle\\Query\\DynamicSegmentQueryBuilder')->disableOriginalConstructor()->getMock();
$this->staticSegmentQueryBuilder = $this->getMockBuilder('Oro\\Bundle\\SegmentBundle\\Query\\StaticSegmentQueryBuilder')->disableOriginalConstructor()->getMock();
$this->entityNameProvider = $this->getMock('Oro\\Bundle\\SegmentBundle\\Provider\\EntityNameProvider');
$this->entityNameProvider->expects($this->any())->method('getEntityName')->will($this->returnValue('Namespace\\Entity'));
$this->entityConfigProvider = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Provider\\ConfigProvider')->disableOriginalConstructor()->getMock();
$this->extendConfigProvider = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Provider\\ConfigProvider')->disableOriginalConstructor()->getMock();
$configManager = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Config\\ConfigManager')->disableOriginalConstructor()->getMock();
$this->entityConfigProvider->expects($this->any())->method('getConfigManager')->will($this->returnValue($configManager));
$configManager->expects($this->any())->method('getEntityManager')->will($this->returnValue($this->em));
$staticQBServiceID = uniqid('static');
$dynamicQBServiceID = uniqid('dynamic');
$container = new Container();
$container->set($staticQBServiceID, $this->staticSegmentQueryBuilder);
$container->set($dynamicQBServiceID, $this->dynamicSegmentQueryBuilder);
$this->filter = new SegmentFilter($this->formFactory, new FilterUtility(), new ServiceLink($container, $dynamicQBServiceID), new ServiceLink($container, $staticQBServiceID), $this->entityNameProvider, $this->entityConfigProvider, $this->extendConfigProvider);
$this->filter->init('segment', ['entity' => '']);
}
作者:bcreme
项目:shopware-symfony-form
/**
* FormFactory constructor.
* @param Container $container
*/
public function __construct(Container $container)
{
# configuring the form factory
$this->formFactory = Forms::createFormFactoryBuilder()->addExtension(new DoctrineOrmExtension(new ExtendedEntityManager($container->get('models'))))->addExtension(new ValidatorExtension(Validation::createValidator()))->getFormFactory();
# registering all necessary smarty plugins
new SmartyPlugins($this->getFormHelper(), $container->get('template'));
}
作者:seyd
项目:laravel-form-bridg
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$configPath = __DIR__ . '/../config/form.php';
$this->mergeConfigFrom($configPath, 'form');
$this->app->bind('twig.form.engine', function ($app) {
$theme = (array) $app['config']->get('form.theme', 'bootstrap_3_layout.html.twig');
return new TwigRendererEngine($theme);
});
$this->app->bind('twig.form.renderer', function ($app) {
return new TwigRenderer($app['twig.form.engine']);
});
$this->app->bind('form.types', function () {
return array();
});
$this->app->bind('form.type.extensions', function () {
return array();
});
$this->app->bind('form.type.guessers', function () {
return array();
});
$this->app->bind('form.extensions', function ($app) {
return array($app->make('Barryvdh\\Form\\Extension\\SessionExtension'), new HttpFoundationExtension(), new EloquentExtension());
});
$this->app->bind('form.factory', function ($app) {
return Forms::createFormFactoryBuilder()->addExtensions($app['form.extensions'])->addTypes($app['form.types'])->addTypeExtensions($app['form.type.extensions'])->addTypeGuessers($app['form.type.guessers'])->setResolvedTypeFactory($app['form.resolved_type_factory'])->getFormFactory();
});
$this->app->alias('form.factory', 'Symfony\\Component\\Form\\FormFactoryInterface');
$this->app->bind('form.resolved_type_factory', function () {
return new ResolvedFormTypeFactory();
});
}
作者:adam-paterso
项目:orocommerc
/**
* {@inheritdoc}
*/
protected function setUp()
{
$this->securityFacade = $this->getMockBuilder('Oro\\Bundle\\SecurityBundle\\SecurityFacade')->disableOriginalConstructor()->getMock();
$this->formType = new FrontendAccountUserType($this->securityFacade);
$this->formType->setAccountUserClass(self::DATA_CLASS);
$this->factory = Forms::createFormFactoryBuilder()->addExtensions($this->getExtensions())->getFormFactory();
}
作者:alex6353
项目:theli
public function __construct(Request $request, $type = "form", $data = array(), $options = array())
{
$this->request = $request;
$validator = Validation::createValidatorBuilder();
if (!isset($options["attr"]["name"])) {
$options["attr"]["thelia_name"] = $this->getName();
}
$builder = Forms::createFormFactoryBuilder()->addExtension(new HttpFoundationExtension());
if (!isset($options["csrf_protection"]) || $options["csrf_protection"] !== false) {
$builder->addExtension(new CsrfExtension(new SessionCsrfProvider($request->getSession(), isset($options["secret"]) ? $options["secret"] : ConfigQuery::read("form.secret", md5(__DIR__)))));
}
$translator = Translator::getInstance();
$validator->setTranslationDomain('validators')->setTranslator($translator);
$this->formBuilder = $builder->addExtension(new ValidatorExtension($validator->getValidator()))->getFormFactory()->createNamedBuilder($this->getName(), $type, $data, $this->cleanOptions($options));
$this->buildForm();
// If not already set, define the success_url field
// This field is not included in the standard form hidden fields
// This field is not included in the hidden fields generated by form_hidden_fields Smarty function
if (!$this->formBuilder->has('success_url')) {
$this->formBuilder->add("success_url", "hidden");
}
// The "error_message" field defines the error message displayed if
// the form could not be validated. If it is empty, a standard error message is displayed instead.
// This field is not included in the hidden fields generated by form_hidden_fields Smarty function
if (!$this->formBuilder->has('error_message')) {
$this->formBuilder->add("error_message", "hidden");
}
$this->form = $this->formBuilder->getForm();
}