Skip to content

Commit

Permalink
minor #12242 [Form] no need to add the url listener when it does not …
Browse files Browse the repository at this point in the history
…do anything (Tobion)

This PR was merged into the 2.3 branch.

Discussion
----------

[Form] no need to add the url listener when it does not do anything

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

In line with #11696

Commits
-------

7aea1c9 [Form] no need to add the url listener when it does not do anything
  • Loading branch information
webmozart committed Oct 20, 2014
2 parents e1d1832 + 7aea1c9 commit 91fde69
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion src/Symfony/Component/Form/Extension/Core/Type/UrlType.php
Expand Up @@ -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']));
}
}

/**
Expand Down

0 comments on commit 91fde69

Please sign in to comment.