Skip to content

Commit

Permalink
Fix form deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlo Forghieri committed Jun 9, 2016
1 parent 89ee3d5 commit f6a4a12
Show file tree
Hide file tree
Showing 9 changed files with 226 additions and 58 deletions.
28 changes: 24 additions & 4 deletions Form/Extension/DateTypeExtension.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php
namespace Mopa\Bundle\BootstrapBundle\Form\Extension;

use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

class DateTypeExtension extends AbstractTypeExtension
{
Expand All @@ -24,16 +25,35 @@ public function finishView(FormView $view, FormInterface $form, array $options)
}

}

public function setDefaultOptions(OptionsResolverInterface $resolver)

/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setOptional(array(
'datepicker'
));
}

/**
* {@inheritdoc}
*
* @deprecated Remove it when bumping requirements to SF 2.7+
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$this->configureOptions($resolver);
}

/**
* {@inheritdoc}
*/
public function getExtendedType()
{
return 'date';
return method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix')
? 'Symfony\Component\Form\Extension\Core\Type\DateType'
: 'date' // SF <2.8 BC
;
}
}
36 changes: 29 additions & 7 deletions Form/Extension/ErrorTypeFormTypeExtension.php
Original file line number Diff line number Diff line change
@@ -1,33 +1,55 @@
<?php
namespace Mopa\Bundle\BootstrapBundle\Form\Extension;

use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

class ErrorTypeFormTypeExtension extends AbstractTypeExtension
{
protected $error_type;
protected $errorType;

public function __construct(array $options)
{
$this->error_type = $options['error_type'];
$this->errorType = $options['error_type'];
}
public function buildView(FormView $view, FormInterface $form, array $options)
{
$view->vars['error_type'] = $options['error_type'];
$view->vars['error_delay'] = $options['error_delay'];
}

/**
* {@inheritdoc}
*
* @deprecated Remove it when bumping requirements to SF 2.7+
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$this->configureOptions($resolver);
}

/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'error_type' => $this->error_type,
'error_delay'=> false
));
'error_type' => $this->errorType,
'error_delay' => false,
));
}

/**
* {@inheritdoc}
*/
public function getExtendedType()
{
return 'form';
return method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix')
? 'Symfony\Component\Form\Extension\Core\Type\FormType'
: 'form' // SF <2.8 BC
;
}
}
30 changes: 25 additions & 5 deletions Form/Extension/HelpFormTypeExtension.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<?php
namespace Mopa\Bundle\BootstrapBundle\Form\Extension;

use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

class HelpFormTypeExtension extends AbstractTypeExtension
{
Expand All @@ -24,7 +25,7 @@ public function buildView(FormView $view, FormInterface $form, array $options)
$view->vars['help_inline'] = $options['help_inline'];
$view->vars['help_block'] = $options['help_block'];
$view->vars['help_label'] = $options['help_label'];

if (!isset($options['help_label_tooltip']['icon']) && !is_null($this->options['tooltip_icon'])) {
$options['help_label_tooltip']['icon'] = $this->options['tooltip_icon'];
}
Expand Down Expand Up @@ -65,7 +66,10 @@ public function buildView(FormView $view, FormInterface $form, array $options)
}
}

public function setDefaultOptions(OptionsResolverInterface $resolver)
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'help_inline' => null,
Expand All @@ -85,8 +89,24 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
));
}

/**
* {@inheritdoc}
*
* @deprecated Remove it when bumping requirements to SF 2.7+
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$this->configureOptions($resolver);
}

/**
* {@inheritdoc}
*/
public function getExtendedType()
{
return 'form';
return method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix')
? 'Symfony\Component\Form\Extension\Core\Type\FormType'
: 'form' // SF <2.8 BC
;
}
}
30 changes: 22 additions & 8 deletions Form/Extension/IconButtonExtension.php
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
<?php
namespace Mopa\Bundle\BootstrapBundle\Form\Extension;

use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\Form\Extension\Core\Type\ButtonType;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

class IconButtonExtension extends AbstractTypeExtension
{
/**
* {@inheritdoc}
*/
public function getExtendedType()
public function buildView(FormView $view, FormInterface $form, array $options)
{
return 'button';
$view->vars['icon'] = $options['icon'];
$view->vars['icon_color'] = $options['icon_color'];
}

/**
* {@inheritdoc}
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(
array(
Expand All @@ -33,10 +35,22 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)

/**
* {@inheritdoc}
*
* @deprecated Remove it when bumping requirements to SF 2.7+
*/
public function buildView(FormView $view, FormInterface $form, array $options)
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$view->vars['icon'] = $options['icon'];
$view->vars['icon_color'] = $options['icon_color'];
$this->configureOptions($resolver);
}

/**
* {@inheritdoc}
*/
public function getExtendedType()
{
return method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix')
? 'Symfony\Component\Form\Extension\Core\Type\ButtonType'
: 'button' // SF <2.8 BC
;
}
}
28 changes: 25 additions & 3 deletions Form/Extension/LegendFormTypeExtension.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php
namespace Mopa\Bundle\BootstrapBundle\Form\Extension;

use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

class LegendFormTypeExtension extends AbstractTypeExtension
{
Expand Down Expand Up @@ -35,7 +36,11 @@ public function buildView(FormView $view, FormInterface $form, array $options)
$view->vars['render_optional_text'] = $options['render_optional_text'];
$view->vars['errors_on_forms'] = $options['errors_on_forms'];
}
public function setDefaultOptions(OptionsResolverInterface $resolver)

/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'render_fieldset' => $this->render_fieldset,
Expand All @@ -47,8 +52,25 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
'errors_on_forms' => $this->errors_on_forms,
));
}

/**
* {@inheritdoc}
*
* @deprecated Remove it when bumping requirements to SF 2.7+
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$this->configureOptions($resolver);
}

/**
* {@inheritdoc}
*/
public function getExtendedType()
{
return 'form';
return method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix')
? 'Symfony\Component\Form\Extension\Core\Type\FormType'
: 'form' // SF <2.8 BC
;
}
}
52 changes: 33 additions & 19 deletions Form/Extension/TabbedFormTypeExtension.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<?php
namespace Mopa\Bundle\BootstrapBundle\Form\Extension;

use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Mopa\Bundle\BootstrapBundle\Form\Type\TabsType;

class TabbedFormTypeExtension extends AbstractTypeExtension
Expand All @@ -19,24 +20,6 @@ public function __construct(FormFactoryInterface $formFactory, array $options)
$this->options = $options;
}

/**
* {@inheritdoc}
*/
public function getExtendedType()
{
return 'form';
}

/**
* {@inheritdoc}
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'tabs_class' => $this->options['class'],
));
}

public function buildView(FormView $view, FormInterface $form, array $options)
{
$view->vars['tabbed'] = false;
Expand Down Expand Up @@ -76,4 +59,35 @@ public function finishView(FormView $view, FormInterface $form, array $options)
$view->vars['tabbed'] = true;
$view->vars['tabsView'] = $tabsForm->createView();
}

/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'tabs_class' => $this->options['class'],
));
}

/**
* {@inheritdoc}
*
* @deprecated Remove it when bumping requirements to SF 2.7+
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$this->configureOptions($resolver);
}

/**
* {@inheritdoc}
*/
public function getExtendedType()
{
return method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix')
? TabsType::class
: 'tabs' // SF <2.8 BC
;
}
}
Loading

0 comments on commit f6a4a12

Please sign in to comment.