Skip to content

Commit

Permalink
[Form] Fix place autocomplete resources
Browse files Browse the repository at this point in the history
  • Loading branch information
GeLoLabs committed Aug 16, 2016
1 parent 4ffd895 commit 75273f0
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 4 deletions.
47 changes: 47 additions & 0 deletions DependencyInjection/Compiler/RegisterFormResourcePass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

/*
* This file is part of the Ivory CKEditor package.
*
* (c) Eric GELOEN <geloen.eric@gmail.com>
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code.
*/

namespace Ivory\GoogleMapBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

/**
* @author GeLo <geloen.eric@gmail.com>
*/
class RegisterFormResourcePass implements CompilerPassInterface
{
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
{
if ($container->hasParameter($parameter = 'templating.helper.form.resources')) {
$container->setParameter(
$parameter,
array_merge(
['IvoryGoogleMapBundle:Form'],
$container->getParameter($parameter)
)
);
}

if ($container->hasParameter($parameter = 'twig.form.resources')) {
$container->setParameter(
$parameter,
array_merge(
['IvoryGoogleMapBundle:Form:place_autocomplete_widget.html.twig'],
$container->getParameter($parameter)
)
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
/**
* @author GeLo <geloen.eric@gmail.com>
*/
class LegacyRegisterHelperListenerPass extends RegisterListenersPass
class RegisterLegacyHelperListenerPass extends RegisterListenersPass
{
public function __construct()
{
Expand Down
8 changes: 5 additions & 3 deletions IvoryGoogleMapBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
namespace Ivory\GoogleMapBundle;

use Ivory\GoogleMapBundle\DependencyInjection\Compiler\CleanTemplatingPass;
use Ivory\GoogleMapBundle\DependencyInjection\Compiler\LegacyRegisterHelperListenerPass;
use Ivory\GoogleMapBundle\DependencyInjection\Compiler\RegisterFormResourcePass;
use Ivory\GoogleMapBundle\DependencyInjection\Compiler\RegisterLegacyHelperListenerPass;
use Ivory\GoogleMapBundle\DependencyInjection\Compiler\RegisterControlRendererPass;
use Ivory\GoogleMapBundle\DependencyInjection\Compiler\RegisterExtendableRendererPass;
use Ivory\GoogleMapBundle\DependencyInjection\Compiler\RegisterHelperListenerPass;
Expand All @@ -33,12 +34,13 @@ public function build(ContainerBuilder $container)
$container
->addCompilerPass(new CleanTemplatingPass())
->addCompilerPass(new RegisterControlRendererPass())
->addCompilerPass(new RegisterExtendableRendererPass());
->addCompilerPass(new RegisterExtendableRendererPass())
->addCompilerPass(new RegisterFormResourcePass());

if (class_exists(RegisterListenersPass::class)) {
$container->addCompilerPass(new RegisterHelperListenerPass());
} else {
$container->addCompilerPass(new LegacyRegisterHelperListenerPass());
$container->addCompilerPass(new RegisterLegacyHelperListenerPass());
}
}
}
22 changes: 22 additions & 0 deletions Tests/DependencyInjection/AbstractIvoryGoogleMapExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,28 @@ public function testTwigExtensions()
$this->assertTrue($this->container->has('ivory.google_map.twig.extension.place_autocomplete'));
}

public function testTemplatingFormResources()
{
$this->container->setParameter($parameter = 'templating.helper.form.resources', $resources = ['resource']);
$this->container->compile();

$this->assertSame(
array_merge(['IvoryGoogleMapBundle:Form'], $resources),
$this->container->getParameter($parameter)
);
}

public function testTwigFormResources()
{
$this->container->setParameter($parameter = 'twig.form.resources', $resources = ['resource']);
$this->container->compile();

$this->assertSame(
array_merge(['IvoryGoogleMapBundle:Form:place_autocomplete_widget.html.twig'], $resources),
$this->container->getParameter($parameter)
);
}

public function testFormatterDebug()
{
$this->loadConfiguration($this->container, 'debug');
Expand Down
10 changes: 10 additions & 0 deletions Tests/Form/Type/PlacesAutocompleteTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@ public function testComponents()
$this->assertSame($components, $autocomplete->getComponents());
}

public function testLibraries()
{
$form = $this->createForm(null, ['libraries' => $libraries = ['drawing']]);
$view = $form->createView();

$this->assertArrayHasKey('autocomplete', $view->vars);
$this->assertInstanceOf(Autocomplete::class, $autocomplete = $view->vars['autocomplete']);
$this->assertSame($libraries, $autocomplete->getLibraries());
}

public function testInitialValue()
{
$form = $this->createForm($value = 'foo');
Expand Down

0 comments on commit 75273f0

Please sign in to comment.