diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 439baf6..8394647 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -4,6 +4,7 @@ use Symfony\Component\Config\Definition\Builder\TreeBuilder; use Symfony\Component\Config\Definition\ConfigurationInterface; +use Symfony\Component\HttpKernel\Kernel; class Configuration implements ConfigurationInterface { @@ -18,8 +19,13 @@ class Configuration implements ConfigurationInterface */ public function getConfigTreeBuilder() { - $treeBuilder = new TreeBuilder(); - $rootNode = $treeBuilder->root('lifo_typeahead'); + if (Kernel::VERSION_ID < 40000) { + $treeBuilder = new TreeBuilder(); + $rootNode = $treeBuilder->root('lifo_typeahead'); + } else { + $treeBuilder = new TreeBuilder('lifo_typeahead'); + $rootNode = $treeBuilder->getRootNode(); + } $rootNode ->children() diff --git a/DependencyInjection/LifoTypeaheadExtension.php b/DependencyInjection/LifoTypeaheadExtension.php index 6caecdf..b6f0071 100644 --- a/DependencyInjection/LifoTypeaheadExtension.php +++ b/DependencyInjection/LifoTypeaheadExtension.php @@ -83,7 +83,10 @@ protected function configureTwigBundle(ContainerBuilder $container, array $confi { if ($container->hasExtension('twig')) { $resources = array('LifoTypeaheadBundle:Form:typeahead.html.twig'); - if (Kernel::VERSION_ID >= '20600') { + if (Kernel::VERSION_ID >= 40000) { + $resources = array('@LifoTypeahead/Form/typeahead.html.twig'); + $container->prependExtensionConfig('twig', array('form_themes' => $resources)); + } elseif (Kernel::VERSION_ID >= 20600) { $container->prependExtensionConfig('twig', array('form_themes' => $resources)); } else { $container->prependExtensionConfig('twig', array('form' => array('resources' => $resources))); diff --git a/Resources/views/Form/typeahead.html.twig b/Resources/views/Form/typeahead.html.twig index 0523927..e59939d 100644 --- a/Resources/views/Form/typeahead.html.twig +++ b/Resources/views/Form/typeahead.html.twig @@ -1,5 +1,4 @@ {% block entity_typeahead_widget %} -{% spaceless %} {% set main_full_name, main_id, main_value, main_attr = full_name, id, value, attr %} {# create visible autocomplete input #} @@ -41,21 +40,19 @@ {% set id, full_name = main_id, main_full_name %} {{ block('entity_typeahead_multiple_widget') }} {% endif %} -{% endspaceless %} {% endblock %} {% block entity_typeahead_multiple_widget %} -{% spaceless %} -{% endspaceless %} {% endblock %} {% block entity_typeahead_list_widget %} -{% spaceless %} {% if simple %} {% set _id, _value, _render = child, child, child %} {% else %} @@ -65,5 +62,4 @@ {{ child is not null ? _render : '' }} -{% endspaceless %} {% endblock %} diff --git a/Twig/Extension/TypeaheadTwigExtension.php b/Twig/Extension/TypeaheadTwigExtension.php index 85b372d..b593f1a 100644 --- a/Twig/Extension/TypeaheadTwigExtension.php +++ b/Twig/Extension/TypeaheadTwigExtension.php @@ -2,12 +2,11 @@ namespace Lifo\TypeaheadBundle\Twig\Extension; -use Assetic\Asset\AssetCollection; -use Assetic\Asset\StringAsset; -use Assetic\Filter\Yui\JsCompressorFilter; use Lifo\TypeaheadBundle\Form\Type\TypeaheadType; +use Twig\Extension\AbstractExtension; +use Twig\TwigFunction; -class TypeaheadTwigExtension extends \Twig_Extension +class TypeaheadTwigExtension extends AbstractExtension { public function getName() { @@ -17,7 +16,7 @@ public function getName() public function getFunctions() { return array( - new \Twig_SimpleFunction('lifo_typeahead_init', array($this, 'initTypeaheadFunction'), array('needs_environment' => true, 'is_safe' => array('html'))), + new TwigFunction('lifo_typeahead_init', array($this, 'initTypeaheadFunction'), array('needs_environment' => true, 'is_safe' => array('html'))), ); }