Skip to content

Commit 763d8ca

Browse files
author
Benjamin
committed
compatible symfony 2.7 ~ 3.X
1 parent 582b03b commit 763d8ca

12 files changed

+782
-31
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
vendor
22
composer.lock
3+
/nbproject/private/

DependencyInjection/GenemuFormExtension.php

+1-16
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function load(array $configs, ContainerBuilder $container)
5555
$loader->load('mongodb.xml');
5656
}
5757

58-
foreach (array('captcha', 'recaptcha', 'tinymce', 'date', 'file', 'image', 'autocomplete', 'select2') as $type) {
58+
foreach (array('captcha', 'recaptcha', 'tinymce', 'date', 'file', 'image', 'autocomplete', 'select2Entity', 'select2Choice', 'select2Hidden') as $type) {
5959
if (isset($configs[$type]) && !empty($configs[$type]['enabled'])) {
6060
$method = 'register' . ucfirst($type) . 'Configuration';
6161

@@ -250,21 +250,6 @@ private function registerAutocompleteConfiguration(array $configs, ContainerBuil
250250

251251
}
252252

253-
private function registerSelect2Configuration(array $configs, ContainerBuilder $container)
254-
{
255-
$serviceId = 'genemu.form.jquery.type.select2';
256-
foreach (array_merge($this->getChoiceTypeNames(), array('hidden')) as $type) {
257-
$typeDef = new DefinitionDecorator($serviceId);
258-
$typeDef
259-
->addArgument($type)
260-
->addArgument($configs['configs'])
261-
->addTag('form.type', array('alias' => 'genemu_jqueryselect2_'.$type))
262-
;
263-
264-
$container->setDefinition($serviceId.'.'.$type, $typeDef);
265-
}
266-
}
267-
268253
/**
269254
* Loads extended form types.
270255
*
+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the GenemuFormBundle package.
5+
*
6+
* (c) Olivier Chauvel <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Genemu\Bundle\FormBundle\Form\JQuery\Type;
13+
14+
use Symfony\Component\Form\AbstractType;
15+
use Symfony\Component\Form\FormView;
16+
use Symfony\Component\Form\FormInterface;
17+
use Symfony\Component\OptionsResolver\OptionsResolver;
18+
use Symfony\Component\OptionsResolver\Options;
19+
20+
/**
21+
* Select2ChoiceType to JQueryLib
22+
*
23+
* @author Bilal Amarni <[email protected]>
24+
* @author Chris Tickner <[email protected]>
25+
* @author Benjamin Schumacher <[email protected]>
26+
*/
27+
class Select2ChoiceType extends AbstractType
28+
{
29+
private $configs;
30+
31+
public function __construct(array $configs = array())
32+
{
33+
$this->configs = $configs;
34+
}
35+
36+
/**
37+
* {@inheritdoc}
38+
*/
39+
public function buildView(FormView $view, FormInterface $form, array $options)
40+
{
41+
$view->vars['configs'] = $options['configs'];
42+
43+
// Adds a custom block prefix
44+
array_splice(
45+
$view->vars['block_prefixes'],
46+
array_search($this->getName(), $view->vars['block_prefixes']),
47+
0,
48+
'genemu_jqueryselect2'
49+
);
50+
}
51+
52+
/**
53+
* {@inheritdoc}
54+
*/
55+
public function configureOptions(OptionsResolver $resolver)
56+
{
57+
$defaults = $this->configs;
58+
$resolver
59+
->setDefaults(array(
60+
'configs' => $defaults,
61+
'transformer' => null,
62+
))
63+
->setNormalizer(
64+
'configs',
65+
function (Options $options, $configs) use ($defaults) {
66+
return array_merge($defaults, $configs);
67+
}
68+
)
69+
;
70+
}
71+
72+
/**
73+
* {@inheritdoc}
74+
*/
75+
public function getParent()
76+
{
77+
return 'Symfony\Component\Form\Extension\Core\Type\ChoiceType';
78+
}
79+
80+
/**
81+
* {@inheritdoc}
82+
*/
83+
public function getName()
84+
{
85+
return 'genemu_jqueryselect2_choice';
86+
}
87+
88+
/**
89+
* {@inheritdoc}
90+
*/
91+
public function getBlockPrefix()
92+
{
93+
return 'genemu_jqueryselect2_choice';
94+
}
95+
}
+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the GenemuFormBundle package.
5+
*
6+
* (c) Olivier Chauvel <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Genemu\Bundle\FormBundle\Form\JQuery\Type;
13+
14+
use Symfony\Component\Form\AbstractType;
15+
use Symfony\Component\Form\FormView;
16+
use Symfony\Component\Form\FormInterface;
17+
use Symfony\Component\OptionsResolver\OptionsResolver;
18+
use Symfony\Component\OptionsResolver\Options;
19+
20+
/**
21+
* Select2CountryType to JQueryLib
22+
*
23+
* @author Bilal Amarni <[email protected]>
24+
* @author Chris Tickner <[email protected]>
25+
* @author Benjamin Schumacher <[email protected]>
26+
*/
27+
class Select2CountryType extends AbstractType
28+
{
29+
private $configs;
30+
31+
public function __construct(array $configs = array())
32+
{
33+
$this->configs = $configs;
34+
}
35+
36+
/**
37+
* {@inheritdoc}
38+
*/
39+
public function buildView(FormView $view, FormInterface $form, array $options)
40+
{
41+
$view->vars['configs'] = $options['configs'];
42+
43+
// Adds a custom block prefix
44+
array_splice(
45+
$view->vars['block_prefixes'],
46+
array_search($this->getName(), $view->vars['block_prefixes']),
47+
0,
48+
'genemu_jqueryselect2'
49+
);
50+
}
51+
52+
/**
53+
* {@inheritdoc}
54+
*/
55+
public function configureOptions(OptionsResolver $resolver)
56+
{
57+
$defaults = $this->configs;
58+
$resolver
59+
->setDefaults(array(
60+
'configs' => $defaults,
61+
'transformer' => null,
62+
))
63+
->setNormalizer(
64+
'configs',
65+
function (Options $options, $configs) use ($defaults) {
66+
return array_merge($defaults, $configs);
67+
}
68+
)
69+
;
70+
}
71+
72+
/**
73+
* {@inheritdoc}
74+
*/
75+
public function getParent()
76+
{
77+
return 'Symfony\Component\Form\Extension\Core\Type\CountryType';
78+
}
79+
80+
/**
81+
* {@inheritdoc}
82+
*/
83+
public function getName()
84+
{
85+
return 'genemu_jqueryselect2_country';
86+
}
87+
88+
/**
89+
* {@inheritdoc}
90+
*/
91+
public function getBlockPrefix()
92+
{
93+
return 'genemu_jqueryselect2_country';
94+
}
95+
}
+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the GenemuFormBundle package.
5+
*
6+
* (c) Olivier Chauvel <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Genemu\Bundle\FormBundle\Form\JQuery\Type;
13+
14+
use Symfony\Component\Form\AbstractType;
15+
use Symfony\Component\Form\FormView;
16+
use Symfony\Component\Form\FormInterface;
17+
use Symfony\Component\OptionsResolver\OptionsResolver;
18+
use Symfony\Component\OptionsResolver\Options;
19+
20+
/**
21+
* Select2CurrencyType to JQueryLib
22+
*
23+
* @author Bilal Amarni <[email protected]>
24+
* @author Chris Tickner <[email protected]>
25+
* @author Benjamin Schumacher <[email protected]>
26+
*/
27+
class Select2CurrencyType extends AbstractType
28+
{
29+
private $configs;
30+
31+
public function __construct(array $configs = array())
32+
{
33+
$this->configs = $configs;
34+
}
35+
36+
/**
37+
* {@inheritdoc}
38+
*/
39+
public function buildView(FormView $view, FormInterface $form, array $options)
40+
{
41+
$view->vars['configs'] = $options['configs'];
42+
43+
// Adds a custom block prefix
44+
array_splice(
45+
$view->vars['block_prefixes'],
46+
array_search($this->getName(), $view->vars['block_prefixes']),
47+
0,
48+
'genemu_jqueryselect2'
49+
);
50+
}
51+
52+
/**
53+
* {@inheritdoc}
54+
*/
55+
public function configureOptions(OptionsResolver $resolver)
56+
{
57+
$defaults = $this->configs;
58+
$resolver
59+
->setDefaults(array(
60+
'configs' => $defaults,
61+
'transformer' => null,
62+
))
63+
->setNormalizer(
64+
'configs',
65+
function (Options $options, $configs) use ($defaults) {
66+
return array_merge($defaults, $configs);
67+
}
68+
)
69+
;
70+
}
71+
72+
/**
73+
* {@inheritdoc}
74+
*/
75+
public function getParent()
76+
{
77+
return 'Symfony\Component\Form\Extension\Core\Type\CurrencyType';
78+
}
79+
80+
/**
81+
* {@inheritdoc}
82+
*/
83+
public function getName()
84+
{
85+
return 'genemu_jqueryselect2_currency';
86+
}
87+
88+
/**
89+
* {@inheritdoc}
90+
*/
91+
public function getBlockPrefix()
92+
{
93+
return 'genemu_jqueryselect2_currency';
94+
}
95+
}

0 commit comments

Comments
 (0)