8000 minor #12242 [Form] no need to add the url listener when it does not … · symfony/symfony@91fde69 · GitHub
[go: up one dir, main page]

Skip to content

Commit 91fde69

Browse files
committed
minor #12242 [Form] no need to add the url listener when it does not 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
2 parents e1d1832 + 7aea1c9 commit 91fde69

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/Symfony/Component/Form/Extension/Core/EventListener/FixUrlProtocolListener.php

Lines changed: 5 additions & 0 deletions
< 8000 tr class="diff-line-row">
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ class FixUrlProtocolListener implements EventSubscriberInterface
2424
{
2525
private $defaultProtocol;
2626

27+
/**
28+
* Constructor.
29+
*
30+
* @param string|null $defaultProtocol The URL scheme to add when there is none or null to not modify the data
31+
*/
2732
public function __construct($defaultProtocol = 'http')
2833
{
2934
$this->defaultProtocol = $defaultProtocol;

src/Symfony/Component/Form/Extension/Core/Type/UrlType.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ class UrlType extends AbstractType
2323
*/
2424
public function buildForm(FormBuilderInterface $builder, array $options)
2525
{
26-
$builder->addEventSubscriber(new FixUrlProtocolListener($options['default_protocol']));
26+
if (null !== $options['default_protocol']) {
27+
$builder->addEventSubscriber(new FixUrlProtocolListener($options['default_protocol']));
28+
}
2729
}
2830

2931
/**

0 commit comments

Comments
 (0)
0