diff --git a/DependencyInjection/Compiler/RegisterFormResourcePass.php b/DependencyInjection/Compiler/RegisterFormResourcePass.php new file mode 100644 index 00000000..192444ca --- /dev/null +++ b/DependencyInjection/Compiler/RegisterFormResourcePass.php @@ -0,0 +1,47 @@ + + * + * 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 + */ +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) + ) + ); + } + } +} diff --git a/DependencyInjection/Compiler/LegacyRegisterHelperListenerPass.php b/DependencyInjection/Compiler/RegisterLegacyHelperListenerPass.php similarity index 91% rename from DependencyInjection/Compiler/LegacyRegisterHelperListenerPass.php rename to DependencyInjection/Compiler/RegisterLegacyHelperListenerPass.php index 9ae4a210..1fdfab50 100644 --- a/DependencyInjection/Compiler/LegacyRegisterHelperListenerPass.php +++ b/DependencyInjection/Compiler/RegisterLegacyHelperListenerPass.php @@ -16,7 +16,7 @@ /** * @author GeLo */ -class LegacyRegisterHelperListenerPass extends RegisterListenersPass +class RegisterLegacyHelperListenerPass extends RegisterListenersPass { public function __construct() { diff --git a/IvoryGoogleMapBundle.php b/IvoryGoogleMapBundle.php index b2a82a86..e12cbf9c 100644 --- a/IvoryGoogleMapBundle.php +++ b/IvoryGoogleMapBundle.php @@ -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; @@ -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()); } } } diff --git a/Resources/views/Form/places_autocomplete_widget.html.php b/Resources/views/Form/place_autocomplete_widget.html.php similarity index 100% rename from Resources/views/Form/places_autocomplete_widget.html.php rename to Resources/views/Form/place_autocomplete_widget.html.php diff --git a/Resources/views/Form/places_autocomplete_widget.html.twig b/Resources/views/Form/place_autocomplete_widget.html.twig similarity index 100% rename from Resources/views/Form/places_autocomplete_widget.html.twig rename to Resources/views/Form/place_autocomplete_widget.html.twig diff --git a/Tests/DependencyInjection/AbstractIvoryGoogleMapExtensionTest.php b/Tests/DependencyInjection/AbstractIvoryGoogleMapExtensionTest.php index 0474d4e0..7328c8f2 100644 --- a/Tests/DependencyInjection/AbstractIvoryGoogleMapExtensionTest.php +++ b/Tests/DependencyInjection/AbstractIvoryGoogleMapExtensionTest.php @@ -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'); diff --git a/Tests/Form/Type/PlacesAutocompleteTypeTest.php b/Tests/Form/Type/PlacesAutocompleteTypeTest.php index 357cff7a..5d8f9293 100644 --- a/Tests/Form/Type/PlacesAutocompleteTypeTest.php +++ b/Tests/Form/Type/PlacesAutocompleteTypeTest.php @@ -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');