Skip to content
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
10 changes: 8 additions & 2 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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()
Expand Down
5 changes: 4 additions & 1 deletion DependencyInjection/LifoTypeaheadExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down
12 changes: 4 additions & 8 deletions Resources/views/Form/typeahead.html.twig
Original file line number Diff line number Diff line change
@@ -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 #}
Expand Down Expand Up @@ -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 %}
<ul id="{{ id }}_list" class="lifo-typeahead-list" {% if 'input_group' in attr and attr.input_group is not empty %}style="display:none"{% endif %}>
{% for child in form.vars.data if child is not null %}
{{ block('entity_typeahead_list_widget') }}
{% for child in form.vars.data %}
{% if child is not null %}
{{ block('entity_typeahead_list_widget') }}
{% endif %}
{% endfor %}
</ul>
{% endspaceless %}
{% endblock %}

{% block entity_typeahead_list_widget %}
{% spaceless %}
{% if simple %}
{% set _id, _value, _render = child, child, child %}
{% else %}
Expand All @@ -65,5 +62,4 @@
<input{% if child is not null %} id="{{ id ~ '_' ~ _id }}" name="{{ full_name }}[]" value="{{ _value }}"{% endif %} type="hidden" />
<a href="" class="lifo-typeahead-item" title="{{ "Click to remove"|trans }}">{{ child is not null ? _render : '' }}</a>
</li>
{% endspaceless %}
{% endblock %}
9 changes: 4 additions & 5 deletions Twig/Extension/TypeaheadTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -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'))),
);
}

Expand Down