Skip to content

Commit 2bc3527

Browse files
Merge branch '7.0' into 7.1
* 7.0: (21 commits) [ErrorHandler] Add missing self-closing tags on link elements Fix merge (bis) Fix merge Add missing return type [FrameworkBundle] ConfigBuilderCacheWarmer should be non-optional [HttpClient] Fix pausing responses before they start when using curl [Notifier] Updated the NTFY notifier to run without a user parameter [Translation] Fix constant domain resolution in PhpAstExtractor separate child and parent context in NotificationEmail on writes [Mailer] [Mailgun] Fix sender header encoding do not overwrite the cache key when it is false [Mailer] [Scaleway] Fix attachment handling [Mailer] Throw TransportException when unable to read from socket [Serializer] Rewrite `AbstractObjectNormalizer::createChildContext()` to use the provided `cache_key` from original context when creating child contexts Revert #47715 [HttpClient] Fix error chunk creation in passthru Adjusting and removing the 'review' attribute from the pt_br translation XML. [DependencyInjection] Fix loading all env vars from secrets when only a subset is needed Fix option filenameMaxLength to the File constraint (Image) [Serializer] Take unnamed variadic parameters into account when denormalizing ...
2 parents 20ec3df + c349f85 commit 2bc3527

13 files changed

+86
-18
lines changed

Mime/NotificationEmail.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,26 @@ public function getHtmlTemplate(): ?string
174174
return '@email/'.$this->theme.'/notification/body.html.twig';
175175
}
176176

177+
/**
178+
* @return $this
179+
*/
180+
public function context(array $context): static
181+
{
182+
$parentContext = [];
183+
184+
foreach ($context as $key => $value) {
185+
if (\array_key_exists($key, $this->context)) {
186+
$this->context[$key] = $value;
187+
} else {
188+
$parentContext[$key] = $value;
189+
}
190+
}
191+
192+
parent::context($parentContext);
193+
194+
return $this;
195+
}
196+
177197
public function getContext(): array
178198
{
179199
return array_merge($this->context, parent::getContext());

Resources/views/Form/form_div_layout.html.twig

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
{# Attribute "required" is not supported #}
1515
{%- set required = false -%}
1616
{%- endif -%}
17-
<input type="{{ type }}" {{ block('widget_attributes') }}{% if value is not empty %} value="{{ value }}"{% endif %}>
17+
<input type="{{ type }}" {{ block('widget_attributes') }} {% if value is not empty %}value="{{ value }}" {% endif %}/>
1818
{%- endblock form_widget_simple -%}
1919

2020
{%- block form_widget_compound -%}
@@ -95,11 +95,11 @@
9595
{%- endblock choice_widget_options -%}
9696

9797
{%- block checkbox_widget -%}
98-
<input type="checkbox" {{ block('widget_attributes') }}{% if value is defined %} value="{{ value }}"{% endif %}{% if checked %} checked="checked"{% endif %}>
98+
<input type="checkbox" {{ block('widget_attributes') }}{% if value is defined %} value="{{ value }}"{% endif %}{% if checked %} checked="checked"{% endif %} />
9999
{%- endblock checkbox_widget -%}
100100

101101
{%- block radio_widget -%}
102-
<input type="radio" {{ block('widget_attributes') }}{% if value is defined %} value="{{ value }}"{% endif %}{% if checked %} checked="checked"{% endif %}>
102+
<input type="radio" {{ block('widget_attributes') }}{% if value is defined %} value="{{ value }}"{% endif %}{% if checked %} checked="checked"{% endif %} />
103103
{%- endblock radio_widget -%}
104104

105105
{%- block datetime_widget -%}
@@ -406,7 +406,7 @@
406406
{%- endif -%}
407407
<form{% if name != '' %} name="{{ name }}"{% endif %} method="{{ form_method|lower }}"{% if action != '' %} action="{{ action }}"{% endif %}{{ block('attributes') }}{% if multipart %} enctype="multipart/form-data"{% endif %}>
408408
{%- if form_method != method -%}
409-
<input type="hidden" name="_method" value="{{ method }}">
409+
<input type="hidden" name="_method" value="{{ method }}" />
410410
{%- endif -%}
411411
{%- endblock form_start -%}
412412

@@ -444,7 +444,7 @@
444444
{%- endif -%}
445445

446446
{%- if form_method != method -%}
447-
<input type="hidden" name="_method" value="{{ method }}">
447+
<input type="hidden" name="_method" value="{{ method }}" />
448448
{%- endif -%}
449449
{% endif -%}
450450
{% endblock form_rest %}

Test/FormLayoutTestCase.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ protected function assertMatchesXpath($html, $expression, $count = 1): void
5252
{
5353
$dom = new \DOMDocument('UTF-8');
5454

55-
$html = preg_replace('/(<input [^>]+)(?<!\/)>/', '$1/>', $html);
56-
5755
try {
5856
// Wrap in <root> node so we can load HTML with multiple tags at
5957
// the top level

Tests/Extension/AbstractBootstrap3LayoutTestCase.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2797,7 +2797,7 @@ public function testWidgetAttributes()
27972797
$html = $this->renderWidget($form->createView());
27982798

27992799
// compare plain HTML to check the whitespace
2800-
$this->assertSame('<input type="text" id="text" name="text" disabled="disabled" required="required" readonly="readonly" maxlength="10" pattern="\d+" class="foobar form-control" data-foo="bar" value="value">', $html);
2800+
$this->assertSame('<input type="text" id="text" name="text" disabled="disabled" required="required" readonly="readonly" maxlength="10" pattern="\d+" class="foobar form-control" data-foo="bar" value="value" />', $html);
28012801
}
28022802

28032803
public function testWidgetAttributeNameRepeatedIfTrue()
@@ -2809,7 +2809,7 @@ public function testWidgetAttributeNameRepeatedIfTrue()
28092809
$html = $this->renderWidget($form->createView());
28102810

28112811
// foo="foo"
2812-
$this->assertSame('<input type="text" id="text" name="text" required="required" foo="foo" class="form-control" value="value">', $html);
2812+
$this->assertSame('<input type="text" id="text" name="text" required="required" foo="foo" class="form-control" value="value" />', $html);
28132813
}
28142814

28152815
public function testButtonAttributes()

Tests/Extension/AbstractLayoutTestCase.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2448,7 +2448,7 @@ public function testWidgetAttributes()
24482448
$html = $this->renderWidget($form->createView());
24492449

24502450
// compare plain HTML to check the whitespace
2451-
$this->assertSame('<input type="text" id="text" name="text" disabled="disabled" required="required" readonly="readonly" maxlength="10" pattern="\d+" class="foobar" data-foo="bar" value="value">', $html);
2451+
$this->assertSame('<input type="text" id="text" name="text" disabled="disabled" required="required" readonly="readonly" maxlength="10" pattern="\d+" class="foobar" data-foo="bar" value="value" />', $html);
24522452
}
24532453

24542454
public function testWidgetAttributeNameRepeatedIfTrue()
@@ -2460,7 +2460,7 @@ public function testWidgetAttributeNameRepeatedIfTrue()
24602460
$html = $this->renderWidget($form->createView());
24612461

24622462
// foo="foo"
2463-
$this->assertSame('<input type="text" id="text" name="text" required="required" foo="foo" value="value">', $html);
2463+
$this->assertSame('<input type="text" id="text" name="text" required="required" foo="foo" value="value" />', $html);
24642464
}
24652465

24662466
public function testWidgetAttributeHiddenIfFalse()
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{% block form_widget_simple %}
22
{%- set type = type|default('text') -%}
3-
<input type="{{ type }}" {{ block('widget_attributes') }} value="{{ value }}" rel="theme">
3+
<input type="{{ type }}" {{ block('widget_attributes') }} value="{{ value }}" rel="theme" />
44
{%- endblock form_widget_simple %}

Tests/Extension/Fixtures/templates/form/theme_extends.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
{% block form_widget_simple %}
44
{%- set type = type|default('text') -%}
5-
<input type="{{ type }}" {{ block('widget_attributes') }} value="{{ value }}" rel="theme">
5+
<input type="{{ type }}" {{ block('widget_attributes') }} value="{{ value }}" rel="theme" />
66
{%- endblock form_widget_simple %}

Tests/Extension/Fixtures/templates/form/theme_use.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
{% block form_widget_simple %}
44
{%- set type = type|default('text') -%}
5-
<input type="{{ type }}" {{ block('widget_attributes') }} value="{{ value }}" rel="theme">
5+
<input type="{{ type }}" {{ block('widget_attributes') }} value="{{ value }}" rel="theme" />
66
{%- endblock form_widget_simple %}

Tests/Extension/FormExtensionBootstrap3LayoutTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function testMoneyWidgetInIso()
7171
$this->assertSame(<<<'HTML'
7272
<div class="input-group">
7373
<span class="input-group-addon">&euro; </span>
74-
<input type="text" id="name" name="name" required="required" class="form-control"> </div>
74+
<input type="text" id="name" name="name" required="required" class="form-control" /> </div>
7575
HTML
7676
, trim($this->renderWidget($view)));
7777
}

Tests/Extension/FormExtensionBootstrap4LayoutTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function testMoneyWidgetInIso()
7676
$this->assertSame(<<<'HTML'
7777
<div class="input-group "><div class="input-group-prepend">
7878
<span class="input-group-text">&euro; </span>
79-
</div><input type="text" id="name" name="name" required="required" class="form-control"></div>
79+
</div><input type="text" id="name" name="name" required="required" class="form-control" /></div>
8080
HTML
8181
, trim($this->renderWidget($view)));
8282
}

Tests/Extension/FormExtensionBootstrap5LayoutTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function testMoneyWidgetInIso()
7575
->createView();
7676

7777
self::assertSame(<<<'HTML'
78-
<div class="input-group "><span class="input-group-text">&euro; </span><input type="text" id="name" name="name" required="required" class="form-control"></div>
78+
<div class="input-group "><span class="input-group-text">&euro; </span><input type="text" id="name" name="name" required="required" class="form-control" /></div>
7979
HTML
8080
, trim($this->renderWidget($view)));
8181
}

Tests/Extension/FormExtensionDivLayoutTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public function testMoneyWidgetInIso()
156156
->createView()
157157
;
158158

159-
$this->assertSame('&euro; <input type="text" id="name" name="name" required="required">', $this->renderWidget($view));
159+
$this->assertSame('&euro; <input type="text" id="name" name="name" required="required" />', $this->renderWidget($view));
160160
}
161161

162162
public function testHelpAttr()

Tests/Mime/NotificationEmailTest.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,54 @@ public function testPublicMailSubject()
128128
$headers = $email->getPreparedHeaders();
129129
$this->assertSame('Foo', $headers->get('Subject')->getValue());
130130
}
131+
132+
public function testContext()
133+
{
134+
$email = new NotificationEmail();
135+
$email->context(['some' => 'context']);
136+
137+
$this->assertSame([
138+
'importance' => NotificationEmail::IMPORTANCE_LOW,
139+
'content' => '',
140+
'exception' => false,
141+
'action_text' => null,
142+
'action_url' => null,
143+
'markdown' => false,
144+
'raw' => false,
145+
'footer_text' => 'Notification email sent by Symfony',
146+
'some' => 'context',
147+
], $email->getContext());
148+
149+
$context = $email->getContext();
150+
$context['foo'] = 'bar';
151+
$email->context($context);
152+
153+
$this->assertSame([
154+
'importance' => NotificationEmail::IMPORTANCE_LOW,
155+
'content' => '',
156+
'exception' => false,
157+
'action_text' => null,
158+
'action_url' => null,
159+
'markdown' => false,
160+
'raw' => false,
161+
'footer_text' => 'Notification email sent by Symfony',
162+
'some' => 'context',
163+
'foo' => 'bar',
164+
], $email->getContext());
165+
166+
$email->action('Action Text', 'Action URL');
167+
168+
$this->assertSame([
169+
'importance' => NotificationEmail::IMPORTANCE_LOW,
170+
'content' => '',
171+
'exception' => false,
172+
'action_text' => 'Action Text',
173+
'action_url' => 'Action URL',
174+
'markdown' => false,
175+
'raw' => false,
176+
'footer_text' => 'Notification email sent by Symfony',
177+
'some' => 'context',
178+
'foo' => 'bar',
179+
], $email->getContext());
180+
}
131181
}

0 commit comments

Comments
 (0)