Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Command/GenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
return;
}

$filter = $this->getContainer()->getParameter('braincrafted_bootstrap.less_filter');
$filter = $this->getContainer()->getParameter('braincrafted_bootstrap.css_preprocessor');
if ('less' !== $filter && 'lessphp' !== $filter) {
$output->writeln(
'<error>Bundle must be configured with "less" or "lessphp" to generated bootstrap.less</error>'
Expand Down
2 changes: 1 addition & 1 deletion Command/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ protected function getSrcDir()
$this->getContainer()->getParameter('braincrafted_bootstrap.assets_dir'),
(
// Sass version stores fonts in a different directory
in_array($this->getContainer()->getParameter('braincrafted_bootstrap.less_filter'), array('sass', 'scssphp')) ?
in_array($this->getContainer()->getParameter('braincrafted_bootstrap.css_preprocessor'), array('sass', 'scssphp')) ?
'fonts/bootstrap' :
'fonts'
)
Expand Down
11 changes: 6 additions & 5 deletions DependencyInjection/AsseticConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ public function build(array $config)
$config['output_dir'] .= '/';
}

if (in_array($config['less_filter'], array('sass', 'scssphp'))) {
// changed from css_preprocessor to css_preprocessor for 3.0
if (in_array($config['css_preprocessor'], array('sass', 'scssphp'))) {
$output['bootstrap_css'] = $this->buildCssWithSass($config);
} elseif ('none' !== $config['less_filter']) {
} elseif ('none' !== $config['css_preprocessor']) {
$output['bootstrap_css'] = $this->buildCssWithLess($config);
} else {
$output['bootstrap_css'] = $this->buildCssWithoutLess($config);
Expand Down Expand Up @@ -93,7 +94,7 @@ protected function buildCssWithLess(array $config)

return array(
'inputs' => $inputs,
'filters' => array($config['less_filter']),
'filters' => array($config['css_preprocessor']),
'output' => $config['output_dir'].'css/bootstrap.css'
);
}
Expand Down Expand Up @@ -121,7 +122,7 @@ protected function buildCssWithSass(array $config)

return array(
'inputs' => $inputs,
'filters' => array($config['less_filter']),
'filters' => array($config['css_preprocessor']),
'output' => $config['output_dir'].'css/bootstrap.css'
);
}
Expand All @@ -133,7 +134,7 @@ protected function buildCssWithSass(array $config)
*/
protected function buildJs(array $config)
{
$path = !in_array($config['less_filter'], array('sass', 'scssphp')) ? "/js" : "/javascripts/bootstrap";
$path = !in_array($config['css_preprocessor'], array('sass', 'scssphp')) ? "/js" : "/javascripts/bootstrap";

return array(
'inputs' => array(
Expand Down
7 changes: 5 additions & 2 deletions DependencyInjection/BraincraftedBootstrapExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ public function load(array $configs, ContainerBuilder $container)
$container->setParameter('braincrafted_bootstrap.fontawesome_dir', $config['fontawesome_dir']);
$container->setParameter('braincrafted_bootstrap.fonts_dir', $config['fonts_dir']);
$container->setParameter('braincrafted_bootstrap.output_dir', $config['output_dir']);
$container->setParameter('braincrafted_bootstrap.less_filter', $config['less_filter']);

// changed from css_preprocessor to css_preprocessor for 3.0
$container->setParameter('braincrafted_bootstrap.css_preprocessor', $config['css_preprocessor']);
$container->setParameter('braincrafted_bootstrap.icon_prefix', $config['icon_prefix']);
$container->setParameter('braincrafted_bootstrap.icon_tag', $config['icon_tag']);
}
Expand Down Expand Up @@ -114,7 +116,8 @@ public function prepend(ContainerBuilder $container)
*/
protected function processSassConfiguration(array $config)
{
if (in_array($config['less_filter'], array('sass', 'scssphp'))) {
// changed from css_preprocessor to css_preprocessor for 3.0
if (in_array($config['css_preprocessor'], array('sass', 'scssphp'))) {
if ($config['assets_dir'] === Configuration::DEFAULT_ASSETS_DIR) {
$config['assets_dir'] = Configuration::DEFAULT_ASSETS_DIR_SASS;
}
Expand Down
5 changes: 3 additions & 2 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ private function buildConfigTree()
->scalarNode('fonts_dir')
->defaultValue(self::DEFAULT_FONTS_DIR)
->end()
// TODO for v3.0: Rename to css_preprocessor
->scalarNode('less_filter')

// renamed from css_preprocessor to css_preprocessor
->scalarNode('css_preprocessor')
->defaultValue('less')
->validate()
->ifNotInArray(array('less', 'lessphp', 'sass', 'scssphp', 'none'))
Expand Down
5 changes: 4 additions & 1 deletion Form/Extension/ButtonTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use Symfony\Component\Form\FormView;
use Symfony\Component\Form\FormInterface;

use Braincrafted\Bundle\BootstrapBundle\Util\LegacyFormHelper;

/**
* FormControlStaticType
*
Expand Down Expand Up @@ -43,6 +45,7 @@ public function configureOptions(OptionsResolver $resolver)
*/
public function getExtendedType()
{
return 'button';
// map old class to new one using LegacyFormHelper
return LegacyFormHelper::getType('button');
}
}
7 changes: 6 additions & 1 deletion Form/Extension/InputGroupButtonExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;

use Braincrafted\Bundle\BootstrapBundle\Util\LegacyFormHelper;

/**
* Class InputGroupButtonExtension
*
Expand All @@ -34,7 +36,8 @@ class InputGroupButtonExtension extends AbstractTypeExtension
*/
public function getExtendedType()
{
return 'text';
// map old class to new one using LegacyFormHelper
return LegacyFormHelper::getType('text');
}

/**
Expand Down Expand Up @@ -100,6 +103,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
*/
protected function addButton(FormBuilderInterface $builder, $config)
{

$options = (isset($config['options']))? $config['options'] : array();

return $builder->create($config['name'], $config['type'], $options);
Expand All @@ -114,6 +118,7 @@ protected function addButton(FormBuilderInterface $builder, $config)
*/
protected function storeButton(ButtonBuilder $buttonBuilder, FormBuilderInterface $form, $position)
{

if (!isset($this->buttons[$form->getName()])) {
$this->buttons[$form->getName()] = array();
}
Expand Down
5 changes: 4 additions & 1 deletion Form/Extension/StaticControlExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormBuilderInterface;

use Braincrafted\Bundle\BootstrapBundle\Util\LegacyFormHelper;

/**
* StaticControlExtension
*
Expand Down Expand Up @@ -58,6 +60,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
*/
public function getExtendedType()
{
return 'form';
// map old class to new one using LegacyFormHelper
return LegacyFormHelper::getType('form');
}
}
7 changes: 5 additions & 2 deletions Form/Extension/TypeSetterExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
use Symfony\Component\Form\FormView;
use Symfony\Component\Form\FormInterface;

use Braincrafted\Bundle\BootstrapBundle\Util\LegacyFormHelper;

/**
* TypeSetterExtension
*
Expand All @@ -27,14 +29,15 @@ class TypeSetterExtension extends AbstractTypeExtension
*/
public function buildView(FormView $view, FormInterface $form, array $options)
{
$view->vars['original_type'] = $form->getConfig()->getType()->getName();
$view->vars['original_type'] = LegacyFormHelper::isLegacy() ? $form->getConfig()->getType()->getName() : $form->getConfig()->getType()->getBlockPrefix();
}

/**
* {@inheritDoc}
*/
public function getExtendedType()
{
return "form";
// map old class to new one using LegacyFormHelper
return LegacyFormHelper::getType('form');
}
}
27 changes: 22 additions & 5 deletions Form/Type/BootstrapCollectionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;

use Braincrafted\Bundle\BootstrapBundle\Util\LegacyFormHelper;

/**
* BootstrapCollectionType
*
Expand Down Expand Up @@ -64,18 +66,23 @@ public function configureOptions(OptionsResolver $resolver)
// @codeCoverageIgnoreEnd
};

$resolver->setDefaults(array(
$defaults = array(
'allow_add' => false,
'allow_delete' => false,
'prototype' => true,
'prototype_name' => '__name__',
'type' => 'text',
'add_button_text' => 'Add',
'delete_button_text' => 'Delete',
'sub_widget_col' => 10,
'button_col' => 2,
'options' => array(),
));
);


// map old class to new one using LegacyFormHelper
$defaults['type'] = LegacyFormHelper::getType('text');

$resolver->setDefaults($defaults);

$resolver->setNormalizer('options', $optionsNormalizer);
}
Expand All @@ -85,14 +92,24 @@ public function configureOptions(OptionsResolver $resolver)
*/
public function getParent()
{
return 'collection';
// map old class to new one using LegacyFormHelper
return LegacyFormHelper::getType('collection');
}

/**
* {@inheritDoc}
*/
public function getName()
public function getBlockPrefix()
{
return 'bootstrap_collection';
}

/**
* Backward compatibility for SF < 3.0
*
* @return null|string
*/
public function getName() {
return $this->getBlockPrefix();
}
}
11 changes: 10 additions & 1 deletion Form/Type/FormActionsType.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,17 @@ public function configureOptions(OptionsResolver $resolver)
/**
* {@inheritdoc}
*/
public function getName()
public function getBlockPrefix()
{
return 'form_actions';
}

/**
* Backward compatibility for SF < 3.0
*
* @return null|string
*/
public function getName() {
return $this->getBlockPrefix();
}
}
15 changes: 13 additions & 2 deletions Form/Type/FormStaticControlType.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

use Symfony\Component\Form\AbstractType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\TextType;

/**
* FormStaticControlType
Expand Down Expand Up @@ -37,13 +38,23 @@ public function configureOptions(OptionsResolver $resolver)
*/
public function getParent()
{
return 'text';
// map old class to new one using LegacyFormHelper
return LegacyFormHelper::getType('text');
}

/**
* Backward compatibility for SF < 3.0
*
* @return null|string
*/
public function getName() {
return $this->getBlockPrefix();
}

/**
* {@inheritdoc}
*/
public function getName()
public function getBlockPrefix()
{
return 'bs_static';
}
Expand Down
11 changes: 10 additions & 1 deletion Form/Type/MoneyType.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,20 @@ public function buildView(FormView $view, FormInterface $form, array $options)
/**
* {@inheritdoc}
*/
public function getName()
public function getBlockPrefix()
{
return 'money';
}

/**
* Backward compatibility for SF < 3.0
*
* @return null|string
*/
public function getName() {
return $this->getBlockPrefix();
}

/**
* Returns the pattern for this locale
*
Expand Down
8 changes: 4 additions & 4 deletions Resources/config/services/form.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@
</service>

<service id="braincrafted_bootstrap.form.extension.typesetter_extension" class="%braincrafted_bootstrap.form.extension.typesetter_extension.class%">
<tag name="form.type_extension" alias="form" />
<tag name="form.type_extension" extended_type="Symfony\Component\Form\Extension\Core\Type\FormType" alias="form" />
</service>

<service id="braincrafted_bootstrap.form.extension.form_action_button" class="%braincrafted_bootstrap.form.extension.button_extension.class%">
<tag name="form.type_extension" alias="button" />
<tag name="form.type_extension" extended_type="Symfony\Component\Form\Extension\Core\Type\ButtonType" alias="button" />
</service>
<service id="braincrafted_bootstrap.form.extension.static_control" class="%braincrafted_bootstrap.form.extension.static_control.class%">
<tag name="form.type_extension" alias="form" />
<tag name="form.type_extension" extended_type="Symfony\Component\Form\Extension\Core\Type\FormType" alias="form" />
</service>

<service id="braincrafted_bootstrap.form.extension.input_group_button" class="%braincrafted_bootstrap.form.extension.input_group_button.class%">
<tag name="form.type_extension" alias="text" />
<tag name="form.type_extension" extended_type="Symfony\Component\Form\Extension\Core\Type\TextType" alias="text" />
</service>

</services>
Expand Down
6 changes: 3 additions & 3 deletions Resources/views/Form/bootstrap.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@
{% set attr = attr|merge({ 'class': (attr.class|default('') ~ ' form-control')|trim }) %}

<select {{ block('widget_attributes') }}{% if multiple %} multiple="multiple"{% endif %}>
{% if empty_value is not none %}
<option {% if required %} disabled="disabled"{% if value is empty %} selected="selected"{% endif %}{% endif %} value="">{{ empty_value|trans({}, translation_domain) }}</option>
{% if placeholder is not none %}
<option {% if required %} disabled="disabled"{% if value is empty %} selected="selected"{% endif %}{% endif %} value="">{{ placeholder|trans({}, translation_domain) }}</option>
{% endif %}
{% if preferred_choices|length > 0 %}
{% set options = preferred_choices %}
Expand Down Expand Up @@ -893,7 +893,7 @@

{% block widget_attributes %}
{% spaceless %}
id="{{ id }}" name="{{ full_name }}"{% if read_only %} readonly="readonly"{% endif %}{% if disabled %} disabled="disabled"{% endif %}{% if required %} required="required"{% endif %}{% if max_length %} maxlength="{{ max_length }}"{% endif %}{% if pattern %} pattern="{{ pattern }}"{% endif %}
id="{{ id }}" name="{{ full_name }}" {% if disabled %} disabled="disabled"{% endif %}{% if required %} required="required"{% endif %}
{% for attrname, attrvalue in attr %}{% if attrname in ['placeholder', 'title'] %}{{ attrname }}="{{ attrvalue|trans({}, translation_domain) }}" {% elseif attrname in ['input_group'] %}{% else %}{{ attrname }}="{{ attrvalue }}" {% endif %}{% endfor %}
{% endspaceless %}
{% endblock widget_attributes %}
Expand Down
4 changes: 2 additions & 2 deletions Tests/Command/GenerateCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function testExecute()
'bootstrap_output' => __DIR__.'/bootstrap.less',
'bootstrap_template' => __DIR__.'/bootstrap.html.twig'
));
$this->container->shouldReceive('getParameter')->with('braincrafted_bootstrap.less_filter')->andReturn('less');
$this->container->shouldReceive('getParameter')->with('braincrafted_bootstrap.css_preprocessor')->andReturn('less');
$this->container->shouldReceive('getParameter')->with('braincrafted_bootstrap.assets_dir')->andReturn(__DIR__);

if (Kernel::VERSION_ID >= 20500) {
Expand Down Expand Up @@ -144,7 +144,7 @@ public function testExecuteNoLessFilter()
->shouldReceive('getParameter')
->with('braincrafted_bootstrap.customize')
->andReturn(array('variables_file' => __DIR__.'/x/variables.less'));
$this->container->shouldReceive('getParameter')->with('braincrafted_bootstrap.less_filter')->andReturn('none');
$this->container->shouldReceive('getParameter')->with('braincrafted_bootstrap.css_preprocessor')->andReturn('none');

// mock the Kernel or create one depending on your needs
$application = new Application($this->kernel);
Expand Down
Loading