Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use jqueryslider in Symfony 3.4 #447

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
12 changes: 6 additions & 6 deletions DependencyInjection/GenemuFormExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Genemu\Bundle\FormBundle\DependencyInjection;

use Symfony\Component\DependencyInjection\DefinitionDecorator;
use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\Reference;
Expand Down Expand Up @@ -227,19 +227,19 @@ private function registerImageConfiguration(array $configs, ContainerBuilder $co
private function registerAutocompleteConfiguration(array $configs, ContainerBuilder $container)
{
$serviceId = 'genemu.form.jquery.type.autocomplete';
$textDef = new DefinitionDecorator($serviceId);
$textDef = new ChildDefinition($serviceId);
$textDef->addArgument('text')->addTag('form.type', array('alias' => 'genemu_jqueryautocomplete_text'));
$container->setDefinition($serviceId . '.text', $textDef);

$doctrineDef = new DefinitionDecorator($serviceId);
$doctrineDef = new ChildDefinition($serviceId);
$doctrineDef
->addArgument('entity')
->addArgument(new Reference('doctrine', ContainerInterface::NULL_ON_INVALID_REFERENCE))
->addTag('form.type', array('alias' => 'genemu_jqueryautocomplete_entity'))
;
$container->setDefinition($serviceId . '.entity', $doctrineDef);

$mongoDef = new DefinitionDecorator($serviceId);
$mongoDef = new ChildDefinition($serviceId);
$mongoDef
->addArgument('document')
->addArgument(new Reference('doctrine_mongodb', ContainerInterface::NULL_ON_INVALID_REFERENCE))
Expand All @@ -254,7 +254,7 @@ private function registerSelect2Configuration(array $configs, ContainerBuilder $
{
$serviceId = 'genemu.form.jquery.type.select2';
foreach (array_merge($this->getChoiceTypeNames(), array('hidden')) as $type) {
$typeDef = new DefinitionDecorator($serviceId);
$typeDef = new ChildDefinition($serviceId);
$typeDef
->addArgument($type)
->addArgument($configs['configs'])
Expand All @@ -275,7 +275,7 @@ private function registerSelect2Configuration(array $configs, ContainerBuilder $
private function loadExtendedTypes($serviceId, $name, ContainerBuilder $container)
{
foreach ($this->getChoiceTypeNames() as $type) {
$typeDef = new DefinitionDecorator($serviceId);
$typeDef = new ChildDefinition($serviceId);
$typeDef->addArgument($type)->addTag('form.type', array('alias' => 'genemu_'.$name.'_'.$type));

$container->setDefinition($serviceId.'.'.$type, $typeDef);
Expand Down
36 changes: 30 additions & 6 deletions Form/JQuery/Type/SliderType.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
namespace Genemu\Bundle\FormBundle\Form\JQuery\Type;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
* SliderType
Expand All @@ -32,6 +34,11 @@ public function buildView(FormView $view, FormInterface $form, array $options)
}

public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$this->configureOptions($resolver);
}

public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'min' => 0,
Expand All @@ -40,26 +47,43 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
'orientation' => 'horizontal'
));

$resolver->setAllowedValues(array(
'orientation' => array(
'horizontal',
'vertical'
$resolver->setAllowedValues("orientation", ["horizontal", "vertical"]);
}

public function finishView(FormView $view, FormInterface $form, array $options)
{
parent::finishView($view, $form, $options);
$view->vars = array_replace(
$view->vars,
array(
'min' => $form->getConfig()->getAttribute('min'),
'max' => $form->getConfig()->getAttribute('max'),
'step' => $form->getConfig()->getAttribute('step'),
'orientation' => $form->getConfig()->getAttribute('orientation'),
)
));
);
}

/**
* {@inheritdoc}
*/
public function getParent()
{
return 'integer';
return IntegerType::class;
}

/**
* {@inheritdoc}
*/
public function getName()
{
return $this->getBlockPrefix;
}

/**
* {@inheritdoc}
*/
public function getBlockPrefix()
{
return 'genemu_jqueryslider';
}
Expand Down
6 changes: 3 additions & 3 deletions Twig/Extension/FormExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace Genemu\Bundle\FormBundle\Twig\Extension;

use Symfony\Component\Form\FormView;
use Symfony\Bridge\Twig\Form\TwigRendererInterface;
use Symfony\Component\Form\FormRenderer;

/**
* FormExtension extends Twig with form capabilities.
Expand All @@ -32,9 +32,9 @@ class FormExtension extends \Twig_Extension
/**
* Constructs.
*
* @param TwigRendererInterface $renderer
* @param FormRenderer $renderer
*/
public function __construct(TwigRendererInterface $renderer)
public function __construct(FormRenderer $renderer)
{
$this->renderer = $renderer;
}
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
],
"require": {
"php": ">=5.3.2",
"symfony/framework-bundle": "~2.8 || ^3.0",
"symfony/form": "~2.8 || ^3.0",
"twig/twig": "~1.14"
"symfony/framework-bundle": "~2.8 || ^3.0 || ^4.4",
"symfony/form": "*",
"twig/twig": "*"
},
"suggest": {
"symfony/twig-bridge": "For integration into Twig templates",
Expand Down