From 7aea1c9808a852b09c2444423c04ad1ac5f51517 Mon Sep 17 00:00:00 2001 From: Tobias Schultze Date: Fri, 17 Oct 2014 01:39:03 +0200 Subject: [PATCH] [Form] no need to add the url listener when it does not do anything --- .../Extension/Core/EventListener/FixUrlProtocolListener.php | 5 +++++ src/Symfony/Component/Form/Extension/Core/Type/UrlType.php | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Form/Extension/Core/EventListener/FixUrlProtocolListener.php b/src/Symfony/Component/Form/Extension/Core/EventListener/FixUrlProtocolListener.php index e25dacf237d02..4a5a1df6af212 100644 --- a/src/Symfony/Component/Form/Extension/Core/EventListener/FixUrlProtocolListener.php +++ b/src/Symfony/Component/Form/Extension/Core/EventListener/FixUrlProtocolListener.php @@ -24,6 +24,11 @@ class FixUrlProtocolListener implements EventSubscriberInterface { private $defaultProtocol; + /** + * Constructor. + * + * @param string|null $defaultProtocol The URL scheme to add when there is none or null to not modify the data + */ public function __construct($defaultProtocol = 'http') { $this->defaultProtocol = $defaultProtocol; diff --git a/src/Symfony/Component/Form/Extension/Core/Type/UrlType.php b/src/Symfony/Component/Form/Extension/Core/Type/UrlType.php index b79809259f7cb..5c414afc932b7 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/UrlType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/UrlType.php @@ -23,7 +23,9 @@ class UrlType extends AbstractType */ public function buildForm(FormBuilderInterface $builder, array $options) { - $builder->addEventSubscriber(new FixUrlProtocolListener($options['default_protocol'])); + if (null !== $options['default_protocol']) { + $builder->addEventSubscriber(new FixUrlProtocolListener($options['default_protocol'])); + } } /**