Skip to content

Commit c2f80d9

Browse files
lashusAdrian Gorny
authored andcommitted
Add support for symfony 3.0
Add support for symfony 3.0 fix tests
1 parent 07385cb commit c2f80d9

25 files changed

+212
-71
lines changed

Command/GenerateCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
6767
return;
6868
}
6969

70-
$filter = $this->getContainer()->getParameter('braincrafted_bootstrap.less_filter');
70+
$filter = $this->getContainer()->getParameter('braincrafted_bootstrap.css_preprocessor');
7171
if ('less' !== $filter && 'lessphp' !== $filter) {
7272
$output->writeln(
7373
'<error>Bundle must be configured with "less" or "lessphp" to generated bootstrap.less</error>'

Command/InstallCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ protected function getSrcDir()
8989
$this->getContainer()->getParameter('braincrafted_bootstrap.assets_dir'),
9090
(
9191
// Sass version stores fonts in a different directory
92-
in_array($this->getContainer()->getParameter('braincrafted_bootstrap.less_filter'), array('sass', 'scssphp')) ?
92+
in_array($this->getContainer()->getParameter('braincrafted_bootstrap.css_preprocessor'), array('sass', 'scssphp')) ?
9393
'fonts/bootstrap' :
9494
'fonts'
9595
)

DependencyInjection/AsseticConfiguration.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@ public function build(array $config)
3535
$config['output_dir'] .= '/';
3636
}
3737

38-
if (in_array($config['less_filter'], array('sass', 'scssphp'))) {
38+
// changed from css_preprocessor to css_preprocessor for 3.0
39+
if (in_array($config['css_preprocessor'], array('sass', 'scssphp'))) {
3940
$output['bootstrap_css'] = $this->buildCssWithSass($config);
40-
} elseif ('none' !== $config['less_filter']) {
41+
} elseif ('none' !== $config['css_preprocessor']) {
4142
$output['bootstrap_css'] = $this->buildCssWithLess($config);
4243
} else {
4344
$output['bootstrap_css'] = $this->buildCssWithoutLess($config);
@@ -93,7 +94,7 @@ protected function buildCssWithLess(array $config)
9394

9495
return array(
9596
'inputs' => $inputs,
96-
'filters' => array($config['less_filter']),
97+
'filters' => array($config['css_preprocessor']),
9798
'output' => $config['output_dir'].'css/bootstrap.css'
9899
);
99100
}
@@ -121,7 +122,7 @@ protected function buildCssWithSass(array $config)
121122

122123
return array(
123124
'inputs' => $inputs,
124-
'filters' => array($config['less_filter']),
125+
'filters' => array($config['css_preprocessor']),
125126
'output' => $config['output_dir'].'css/bootstrap.css'
126127
);
127128
}
@@ -133,7 +134,7 @@ protected function buildCssWithSass(array $config)
133134
*/
134135
protected function buildJs(array $config)
135136
{
136-
$path = !in_array($config['less_filter'], array('sass', 'scssphp')) ? "/js" : "/javascripts/bootstrap";
137+
$path = !in_array($config['css_preprocessor'], array('sass', 'scssphp')) ? "/js" : "/javascripts/bootstrap";
137138

138139
return array(
139140
'inputs' => array(

DependencyInjection/BraincraftedBootstrapExtension.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ public function load(array $configs, ContainerBuilder $container)
6161
$container->setParameter('braincrafted_bootstrap.fontawesome_dir', $config['fontawesome_dir']);
6262
$container->setParameter('braincrafted_bootstrap.fonts_dir', $config['fonts_dir']);
6363
$container->setParameter('braincrafted_bootstrap.output_dir', $config['output_dir']);
64-
$container->setParameter('braincrafted_bootstrap.less_filter', $config['less_filter']);
64+
65+
// changed from css_preprocessor to css_preprocessor for 3.0
66+
$container->setParameter('braincrafted_bootstrap.css_preprocessor', $config['css_preprocessor']);
6567
$container->setParameter('braincrafted_bootstrap.icon_prefix', $config['icon_prefix']);
6668
$container->setParameter('braincrafted_bootstrap.icon_tag', $config['icon_tag']);
6769
}
@@ -114,7 +116,8 @@ public function prepend(ContainerBuilder $container)
114116
*/
115117
protected function processSassConfiguration(array $config)
116118
{
117-
if (in_array($config['less_filter'], array('sass', 'scssphp'))) {
119+
// changed from css_preprocessor to css_preprocessor for 3.0
120+
if (in_array($config['css_preprocessor'], array('sass', 'scssphp'))) {
118121
if ($config['assets_dir'] === Configuration::DEFAULT_ASSETS_DIR) {
119122
$config['assets_dir'] = Configuration::DEFAULT_ASSETS_DIR_SASS;
120123
}

DependencyInjection/Configuration.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ private function buildConfigTree()
7777
->scalarNode('fonts_dir')
7878
->defaultValue(self::DEFAULT_FONTS_DIR)
7979
->end()
80-
// TODO for v3.0: Rename to css_preprocessor
81-
->scalarNode('less_filter')
80+
81+
// renamed from css_preprocessor to css_preprocessor
82+
->scalarNode('css_preprocessor')
8283
->defaultValue('less')
8384
->validate()
8485
->ifNotInArray(array('less', 'lessphp', 'sass', 'scssphp', 'none'))

Form/Extension/ButtonTypeExtension.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
use Symfony\Component\Form\FormView;
88
use Symfony\Component\Form\FormInterface;
99

10+
use Braincrafted\Bundle\BootstrapBundle\Util\LegacyFormHelper;
11+
1012
/**
1113
* FormControlStaticType
1214
*
@@ -43,6 +45,7 @@ public function configureOptions(OptionsResolver $resolver)
4345
*/
4446
public function getExtendedType()
4547
{
46-
return 'button';
48+
// map old class to new one using LegacyFormHelper
49+
return LegacyFormHelper::getType('button');
4750
}
4851
}

Form/Extension/InputGroupButtonExtension.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use Symfony\Component\Form\FormInterface;
99
use Symfony\Component\Form\FormView;
1010

11+
use Braincrafted\Bundle\BootstrapBundle\Util\LegacyFormHelper;
12+
1113
/**
1214
* Class InputGroupButtonExtension
1315
*
@@ -34,7 +36,8 @@ class InputGroupButtonExtension extends AbstractTypeExtension
3436
*/
3537
public function getExtendedType()
3638
{
37-
return 'text';
39+
// map old class to new one using LegacyFormHelper
40+
return LegacyFormHelper::getType('text');
3841
}
3942

4043
/**
@@ -100,6 +103,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
100103
*/
101104
protected function addButton(FormBuilderInterface $builder, $config)
102105
{
106+
103107
$options = (isset($config['options']))? $config['options'] : array();
104108

105109
return $builder->create($config['name'], $config['type'], $options);
@@ -114,6 +118,7 @@ protected function addButton(FormBuilderInterface $builder, $config)
114118
*/
115119
protected function storeButton(ButtonBuilder $buttonBuilder, FormBuilderInterface $form, $position)
116120
{
121+
117122
if (!isset($this->buttons[$form->getName()])) {
118123
$this->buttons[$form->getName()] = array();
119124
}

Form/Extension/StaticControlExtension.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use Symfony\Component\Form\FormInterface;
99
use Symfony\Component\Form\FormBuilderInterface;
1010

11+
use Braincrafted\Bundle\BootstrapBundle\Util\LegacyFormHelper;
12+
1113
/**
1214
* StaticControlExtension
1315
*
@@ -58,6 +60,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
5860
*/
5961
public function getExtendedType()
6062
{
61-
return 'form';
63+
// map old class to new one using LegacyFormHelper
64+
return LegacyFormHelper::getType('form');
6265
}
6366
}

Form/Extension/TypeSetterExtension.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
use Symfony\Component\Form\FormView;
1111
use Symfony\Component\Form\FormInterface;
1212

13+
use Braincrafted\Bundle\BootstrapBundle\Util\LegacyFormHelper;
14+
1315
/**
1416
* TypeSetterExtension
1517
*
@@ -27,14 +29,15 @@ class TypeSetterExtension extends AbstractTypeExtension
2729
*/
2830
public function buildView(FormView $view, FormInterface $form, array $options)
2931
{
30-
$view->vars['original_type'] = $form->getConfig()->getType()->getName();
32+
$view->vars['original_type'] = LegacyFormHelper::isLegacy() ? $form->getConfig()->getType()->getName() : $form->getConfig()->getType()->getBlockPrefix();
3133
}
3234

3335
/**
3436
* {@inheritDoc}
3537
*/
3638
public function getExtendedType()
3739
{
38-
return "form";
40+
// map old class to new one using LegacyFormHelper
41+
return LegacyFormHelper::getType('form');
3942
}
4043
}

Form/Type/BootstrapCollectionType.php

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
use Symfony\Component\OptionsResolver\Options;
1313
use Symfony\Component\OptionsResolver\OptionsResolver;
1414

15+
use Braincrafted\Bundle\BootstrapBundle\Util\LegacyFormHelper;
16+
1517
/**
1618
* BootstrapCollectionType
1719
*
@@ -64,18 +66,23 @@ public function configureOptions(OptionsResolver $resolver)
6466
// @codeCoverageIgnoreEnd
6567
};
6668

67-
$resolver->setDefaults(array(
69+
$defaults = array(
6870
'allow_add' => false,
6971
'allow_delete' => false,
7072
'prototype' => true,
7173
'prototype_name' => '__name__',
72-
'type' => 'text',
7374
'add_button_text' => 'Add',
7475
'delete_button_text' => 'Delete',
7576
'sub_widget_col' => 10,
7677
'button_col' => 2,
7778
'options' => array(),
78-
));
79+
);
80+
81+
82+
// map old class to new one using LegacyFormHelper
83+
$defaults['type'] = LegacyFormHelper::getType('text');
84+
85+
$resolver->setDefaults($defaults);
7986

8087
$resolver->setNormalizer('options', $optionsNormalizer);
8188
}
@@ -85,14 +92,24 @@ public function configureOptions(OptionsResolver $resolver)
8592
*/
8693
public function getParent()
8794
{
88-
return 'collection';
95+
// map old class to new one using LegacyFormHelper
96+
return LegacyFormHelper::getType('collection');
8997
}
9098

9199
/**
92100
* {@inheritDoc}
93101
*/
94-
public function getName()
102+
public function getBlockPrefix()
95103
{
96104
return 'bootstrap_collection';
97105
}
106+
107+
/**
108+
* Backward compatibility for SF < 3.0
109+
*
110+
* @return null|string
111+
*/
112+
public function getName() {
113+
return $this->getBlockPrefix();
114+
}
98115
}

0 commit comments

Comments
 (0)