Skip to content

Navigation Menu

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 5393f81

Browse filesBrowse files
Legendary4226chalasr
authored andcommitted
[TwigBridge] Add Twig field_id() form helper
1 parent b28e597 commit 5393f81
Copy full SHA for 5393f81

File tree

3 files changed

+13
-0
lines changed
Filter options

3 files changed

+13
-0
lines changed

‎src/Symfony/Bridge/Twig/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/CHANGELOG.md
+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
---
66

77
* Add `is_granted_for_user()` Twig function
8+
* Add `field_id()` Twig form helper function
89

910
7.2
1011
---

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

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/Extension/FormExtension.php
+6
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
+6
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.