Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0cf06e4

Browse filesBrowse files
committed
Feat twig field_id form helper
1 parent b28e597 commit 0cf06e4
Copy full SHA for 0cf06e4

File tree

2 files changed

+12
-0
lines changed
Filter options

2 files changed

+12
-0
lines changed

‎src/Symfony/Bridge/Twig/Extension/FormExtension.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/Extension/FormExtension.php
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public function getFunctions(): array
6262
new TwigFunction('csrf_token', [FormRenderer::class, 'renderCsrfToken']),
6363
new TwigFunction('form_parent', 'Symfony\Bridge\Twig\Extension\twig_get_form_parent'),
6464
new TwigFunction('field_name', $this->getFieldName(...)),
65+
new TwigFunction('field_id', $this->getFieldId(...)),
6566
new TwigFunction('field_value', $this->getFieldValue(...)),
6667
new TwigFunction('field_label', $this->getFieldLabel(...)),
6768
new TwigFunction('field_help', $this->getFieldHelp(...)),
@@ -93,6 +94,11 @@ public function getFieldName(FormView $view): string
9394
return $view->vars['full_name'];
9495
}
9596

97+
public function getFieldId(FormView $view): string
98+
{
99+
return $view->vars['id'];
100+
}
101+
96102
public function getFieldValue(FormView $view): string|array
97103
{
98104
return $view->vars['value'];

‎src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionFieldHelpersTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionFieldHelpersTest.php
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@ public function testFieldName()
119119
$this->assertTrue($this->view->children['username']->isRendered());
120120
}
121121

122+
public function testFieldId()
123+
{
124+
$this->assertSame('register_username', $this->rawExtension->getFieldId($this->view->children['username']));
125+
$this->assertSame('register_choice_multiple', $this->rawExtension->getFieldId($this->view->children['choice_multiple']));
126+
}
127+
122128
public function testFieldValue()
123129
{
124130
$this->assertSame('tgalopin', $this->rawExtension->getFieldValue($this->view->children['username']));

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.