Skip to content
This repository was archived by the owner on May 10, 2019. It is now read-only.

Commit a685d93

Browse files
committed
init
1 parent baaf473 commit a685d93

12 files changed

+869
-0
lines changed

DependencyInjection/Configuration.php

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Xthiago\FormExtraBundle\DependencyInjection;
4+
5+
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
6+
use Symfony\Component\Config\Definition\ConfigurationInterface;
7+
8+
/**
9+
* This is the class that validates and merges configuration from your app/config files
10+
*
11+
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
12+
*/
13+
class Configuration implements ConfigurationInterface
14+
{
15+
/**
16+
* {@inheritDoc}
17+
*/
18+
public function getConfigTreeBuilder()
19+
{
20+
$treeBuilder = new TreeBuilder();
21+
$rootNode = $treeBuilder->root('xthiago_form_extra');
22+
23+
// Here you should define the parameters that are allowed to
24+
// configure your bundle. See the documentation linked above for
25+
// more information on that topic.
26+
27+
return $treeBuilder;
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace Xthiago\FormExtraBundle\DependencyInjection;
4+
5+
use Symfony\Component\DependencyInjection\ContainerBuilder;
6+
use Symfony\Component\Config\FileLocator;
7+
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
8+
use Symfony\Component\DependencyInjection\Loader;
9+
10+
/**
11+
* This is the class that loads and manages your bundle configuration
12+
*
13+
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
14+
*/
15+
class XthiagoFormExtraExtension extends Extension
16+
{
17+
/**
18+
* {@inheritDoc}
19+
*/
20+
public function load(array $configs, ContainerBuilder $container)
21+
{
22+
$configuration = new Configuration();
23+
$config = $this->processConfiguration($configuration, $configs);
24+
25+
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
26+
$loader->load('services.yml');
27+
}
28+
}

Form/Type/DateRangeType.php

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?php
2+
3+
namespace Xthiago\FormExtraBundle\Form\Type;
4+
5+
use Symfony\Component\Form\AbstractType;
6+
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
7+
use Symfony\Component\OptionsResolver\Options;
8+
use Symfony\Component\Form\FormView;
9+
use Symfony\Component\Form\FormView\FormInterface;
10+
use Symfony\Component\Form\FormBuilderInterface;
11+
12+
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToStringTransformer;
13+
14+
15+
class DateRangeType extends AbstractType
16+
{
17+
public function buildForm(FormBuilderInterface $builder, array $options)
18+
{
19+
$builder
20+
->add('from', 'xthiago_datetime',
21+
array(
22+
'format' => $options['format'],
23+
'label' => 'de',
24+
'required' => false,
25+
'returnDatetime' => $options['returnDatetime'],
26+
'dateType' => $options['dateType'],
27+
'datepicker' => $options['datepicker'],
28+
)
29+
)
30+
->add('to', 'xthiago_datetime',
31+
array(
32+
'format' => $options['format'],
33+
'label' => 'até',
34+
'required' => false,
35+
'returnDatetime' => $options['returnDatetime'],
36+
'dateType' => $options['dateType'],
37+
'datepicker' => $options['datepicker'],
38+
)
39+
)
40+
;
41+
/*if($options['retornar_datetime'] === true) {
42+
43+
//$transformer = new DatetimeToStringTransformer($options['format']);
44+
$transformer = new DateTimeToStringTransformer(null, null, $options['format']);
45+
$builder->addModelTransformer($transformer);
46+
}*/
47+
}
48+
49+
public function setDefaultOptions(OptionsResolverInterface $resolver)
50+
{
51+
$resolver->setDefaults(
52+
array(
53+
'format' => 'd/m/Y', // formato das datas
54+
'dateType' => 'date',
55+
'compound' => true,
56+
57+
'returnDatetime' => true,
58+
59+
'onchange' => null,
60+
'datepicker' => true, // false para desabilitar o datepicker nos campos
61+
)
62+
);
63+
}
64+
65+
protected function convertFormatToJavascriptDate($formato)
66+
{
67+
$padroes = // key: php - value: javascript
68+
array(
69+
'y' => 'yy',
70+
'Y' => 'yyyy',
71+
'm' => 'mm',
72+
'd' => 'dd',
73+
'H' => 'hh',
74+
'i' => 'ii',
75+
's' => 'ss',
76+
)
77+
;
78+
79+
return str_replace(array_keys($padroes), array_values($padroes), $formato);
80+
}
81+
82+
public function buildView(\Symfony\Component\Form\FormView $view, \Symfony\Component\Form\FormInterface $form, array $options)
83+
{
84+
$formato = array_key_exists('format', $options) ? $options['format'] : 'd/m/Y H:i:s';
85+
$view->vars['format'] = $this->convertFormatToJavascriptDate($formato);
86+
87+
$view->vars['dateType'] = array_key_exists('dateType', $options) ? $options['dateType'] : 'date';
88+
89+
$view->vars['datepicker'] = array_key_exists('datepicker', $options) ? $options['datepicker'] : true;
90+
}
91+
92+
public function getParent()
93+
{
94+
return 'text';
95+
}
96+
97+
public function getName()
98+
{
99+
return 'xthiago_daterange';
100+
}
101+
}

Form/Type/DatetimeType.php

+138
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
<?php
2+
3+
namespace Xthiago\FormExtraBundle\Form\Type;
4+
5+
use Symfony\Component\Form\AbstractType;
6+
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
7+
use Symfony\Component\OptionsResolver\Options;
8+
use Symfony\Component\Form\FormView;
9+
use Symfony\Component\Form\FormView\FormInterface;
10+
use Symfony\Component\Form\FormBuilderInterface;
11+
12+
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToStringTransformer;
13+
14+
15+
class DatetimeType extends AbstractType
16+
{
17+
public function buildForm(FormBuilderInterface $builder, array $options)
18+
{
19+
if($options['returnDatetime'] === true) {
20+
21+
//$transformer = new DatetimeToStringTransformer($options['format']);
22+
$transformer = new DateTimeToStringTransformer(null, null, $options['format']);
23+
$builder->addModelTransformer($transformer);
24+
}
25+
}
26+
27+
public function setDefaultOptions(OptionsResolverInterface $resolver)
28+
{
29+
$resolver->setDefaults(
30+
array(
31+
'format' => 'd/m/Y', // formato da data (exemplo: d/m/Y H:i)
32+
'autoclose' => true, // fecha a picker ao selecionar data
33+
'todayBtn' => true, // mostra botão 'hoje'
34+
'startDate' => null, // primeira data que pode ser selecionada (deve estar no mesmo formato de 'format') - ex: '05/11/2013 00:00'
35+
'endDate' => null, // última data que pode ser selecionada (deve estar no mesmo formato de 'format') - ex: '15/11/2013 23:59'
36+
'minuteStep' => 30, // incremento usado para exibir a seleção de minutos
37+
'language' => 'pt-BR', // idioma do picker
38+
'startView' => null, // janela que aparece quando o datepicker é aberto
39+
'minView' => 2, // última janela a ser exibida para concluir a seleção (0 -minutos, 1-hora, 2 - dias, 3 - meses, 4- anos)
40+
'maxView' => null,
41+
'todayHighlight' => true, // destaca o dia atual na listagem de dias
42+
'keyboardNavigation' => true, // permite navegar pelo teclado
43+
'daysOfWeekDisabled' => null, // dias da semana que devem ser desabilitado (ex: '0,6')
44+
'weekStart' => 0, // primeiro dia da semana
45+
46+
'returnDatetime' => true, // true para retornar \DateTime e false para string
47+
48+
'dateType' => 'date', // tipos possíveis: date (d/m/Y), datetime (d/m/Y H:i), month (m/Y), year (Y)
49+
50+
'onchange' => null,
51+
'datepicker' => true, // false para desabilitar o datepicker
52+
)
53+
);
54+
}
55+
56+
protected function convertFormatToJavascriptDate($formato)
57+
{
58+
$padroes = // key: php - value: javascript
59+
array(
60+
'y' => 'yy',
61+
'Y' => 'yyyy',
62+
'm' => 'mm',
63+
'd' => 'dd',
64+
'H' => 'hh',
65+
'i' => 'ii',
66+
's' => 'ss',
67+
)
68+
;
69+
70+
return str_replace(array_keys($padroes), array_values($padroes), $formato);
71+
}
72+
73+
public function buildView(\Symfony\Component\Form\FormView $view, \Symfony\Component\Form\FormInterface $form, array $options)
74+
{
75+
/*if($options['format'] === null) {
76+
77+
$type = $options['type'];
78+
79+
if($type == 'date') {
80+
81+
$options['format'] = 'd/m/Y';
82+
$options['minView'] = 2;
83+
84+
} else if($type == 'datetime') {
85+
86+
$options['format'] = 'd/m/Y H:i';
87+
$options['minView'] = 0;
88+
89+
} else if($type == 'month') {
90+
91+
$options['format'] = 'm/Y';
92+
$options['minView'] = 3;
93+
$options['startView'] = 3;
94+
95+
} else if($type == 'year') {
96+
97+
$options['format'] = 'Y';
98+
$options['minView'] = 4;
99+
$options['startView'] = 4;
100+
101+
}
102+
}*/
103+
104+
$formato = array_key_exists('format', $options) ? $options['format'] : 'd/m/Y H:i:s';
105+
$view->vars['format'] = $this->convertFormatToJavascriptDate($formato);
106+
107+
$view->vars['readonly'] = array_key_exists('readonly', $options) ? $options['readonly'] : null;
108+
$view->vars['autoclose'] = array_key_exists('autoclose', $options) ? $options['autoclose'] : null;
109+
$view->vars['todayBtn'] = array_key_exists('todayBtn', $options) ? $options['todayBtn'] : null;
110+
$view->vars['startDate'] = array_key_exists('startDate', $options) ? $options['startDate'] : null;
111+
$view->vars['endDate'] = array_key_exists('endDate', $options) ? $options['endDate'] : null;
112+
$view->vars['minuteStep'] = array_key_exists('minuteStep', $options) ? $options['minuteStep'] : null;
113+
$view->vars['language'] = array_key_exists('language', $options) ? $options['language'] : null;
114+
$view->vars['minView'] = array_key_exists('minView', $options) ? $options['minView'] : null;
115+
$view->vars['maxView'] = array_key_exists('maxView', $options) ? $options['maxView'] : null;
116+
$view->vars['todayHighlight'] = array_key_exists('todayHighlight', $options) ? $options['todayHighlight'] : null;
117+
$view->vars['keyboardNavigation'] = array_key_exists('keyboardNavigation', $options) ? $options['keyboardNavigation'] : null;
118+
$view->vars['daysOfWeekDisabled'] = array_key_exists('daysOfWeekDisabled', $options) ? $options['daysOfWeekDisabled'] : null;
119+
$view->vars['weekStart'] = array_key_exists('weekStart', $options) ? $options['weekStart'] : null;
120+
$view->vars['startView'] = array_key_exists('startView', $options) ? $options['startView'] : null;
121+
122+
$view->vars['onchange'] = array_key_exists('onchange', $options) ? $options['onchange'] : null;
123+
124+
$view->vars['dateType'] = array_key_exists('dateType', $options) ? $options['dateType'] : 'date';
125+
126+
$view->vars['datepicker'] = array_key_exists('datepicker', $options) ? $options['datepicker'] : true;
127+
}
128+
129+
public function getParent()
130+
{
131+
return 'text';
132+
}
133+
134+
public function getName()
135+
{
136+
return 'xthiago_datetime';
137+
}
138+
}

Form/Type/SelectAsyncType.php

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
namespace Xthiago\FormExtraBundle\Form\Type;
4+
5+
use Symfony\Component\Form\AbstractType;
6+
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
7+
use Symfony\Component\OptionsResolver\Options;
8+
use Symfony\Component\Form\FormView;
9+
use Symfony\Component\Form\FormView\FormInterface;
10+
11+
12+
class SelectAsyncType extends AbstractType
13+
{
14+
public function setDefaultOptions(OptionsResolverInterface $resolver)
15+
{
16+
$resolver->setDefaults(
17+
array(
18+
'multiple' => false,
19+
'data_source_route' => null,
20+
'allowcreate' => false,
21+
'placeholder' => null,
22+
'extrainfo' => null,
23+
)
24+
);
25+
}
26+
27+
public function buildView(\Symfony\Component\Form\FormView $view, \Symfony\Component\Form\FormInterface $form, array $options)
28+
{
29+
$view->vars['data_source_route'] = array_key_exists('data_source_route', $options) ? $options['data_source_route'] : null;
30+
$view->vars['multiple'] = array_key_exists('multiple', $options) ? $options['multiple'] : null;
31+
$view->vars['allowcreate'] = array_key_exists('allowcreate', $options) ? $options['allowcreate'] : null;
32+
$view->vars['placeholder'] = array_key_exists('placeholder', $options) ? $options['placeholder'] : null;
33+
$view->vars['extrainfo'] = array_key_exists('extrainfo', $options) ? $options['extrainfo'] : null;
34+
}
35+
36+
public function getParent()
37+
{
38+
return 'text';
39+
}
40+
41+
public function getName()
42+
{
43+
return 'xthiago_select_async';
44+
}
45+
}

Form/Type/SelectType.php

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
namespace Xthiago\FormExtraBundle\Form\Type;
4+
5+
use Symfony\Component\Form\AbstractType;
6+
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
7+
use Symfony\Component\OptionsResolver\Options;
8+
use Symfony\Component\Form\FormView;
9+
use Symfony\Component\Form\FormView\FormInterface;
10+
11+
12+
class SelectType extends AbstractType
13+
{
14+
public function setDefaultOptions(OptionsResolverInterface $resolver)
15+
{
16+
$resolver->setDefaults(
17+
array(
18+
'multiple' => false,
19+
'allowcreate' => false,
20+
'placeholder' => null,
21+
'extrainfo' => null,
22+
'choices' => null,
23+
'minimumInputLength' => 0,
24+
)
25+
);
26+
}
27+
28+
public function buildView(\Symfony\Component\Form\FormView $view, \Symfony\Component\Form\FormInterface $form, array $options)
29+
{
30+
$view->vars['multiple'] = array_key_exists('multiple', $options) ? $options['multiple'] : null;
31+
$view->vars['allowcreate'] = array_key_exists('allowcreate', $options) ? $options['allowcreate'] : null;
32+
$view->vars['placeholder'] = array_key_exists('placeholder', $options) ? $options['placeholder'] : null;
33+
$view->vars['extrainfo'] = array_key_exists('extrainfo', $options) ? $options['extrainfo'] : null;
34+
$view->vars['choices'] = array_key_exists('choices', $options) ? $options['choices'] : null;
35+
$view->vars['minimumInputLength'] = array_key_exists('minimumInputLength', $options) ? $options['minimumInputLength'] : null;
36+
}
37+
38+
public function getParent()
39+
{
40+
return 'text';
41+
}
42+
43+
public function getName()
44+
{
45+
return 'xthiago_select';
46+
}
47+
}

0 commit comments

Comments
 (0)