Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

[TwigBridge] Add Twigfield_id() form helper#59842

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
chalasr merged 1 commit intosymfony:7.3fromLegendary4226:feature-1
Mar 5, 2025

Conversation

Legendary4226
Copy link
Contributor

QA
Branch?7.3
Bug fix?no
New feature?yes
Deprecations?no
IssuesN/A
LicenseMIT

Hello, I thought it would be nice to have a twigfield_id(form.myField) helper instead of using the{{ form.task.vars.id }} as stated in the official documentation.https://symfony.com/doc/current/form/form_customization.html#form-rendering-variables

chapterjason reacted with thumbs up emoji
@Legendary4226Legendary4226 marked this pull request as ready for reviewFebruary 23, 2025 11:26
@carsonbotcarsonbot added this to the7.3 milestoneFeb 23, 2025
@chalasr
Copy link
Member

Please add a proper title to your PR also

Legendary4226 reacted with thumbs up emoji

@Legendary4226Legendary4226 changed the titleFeature 1Feat: Add twig field_id form helperFeb 24, 2025
@carsonbotcarsonbot changed the titleFeat: Add twig field_id form helper[TwigBridge] Feat: Add twig field_id form helperFeb 24, 2025
@symfonysymfony deleted a comment fromcarsonbotFeb 24, 2025
@symfonysymfony deleted a comment fromcarsonbotFeb 24, 2025
@nicolas-grekasnicolas-grekas changed the title[TwigBridge] Feat: Add twig field_id form helper[TwigBridge] Add twig field_id() form helperFeb 24, 2025
@Legendary4226
Copy link
ContributorAuthor

Legendary4226 commentedFeb 24, 2025
edited
Loading

I have a question relating to this PR: the FormView objects and the underlying data. Why aren't they available in the Twig context ?

For example, on a project for my company Onyl Rocks, I declared a form type based on a ViewModel that contains some entities like Organizations (as an array).
Users can belong to multiple organizations, so I have a form to handle the switch between them.
My Organizations have an image, so I wan't to display their image, assuming it's a base64 string for simplicity.
But I cannot access the underlying data on what the FormView objects are based on.

Do you think it's possible to add such a feature ? In another PR of course ^^
In my opinion, it is one of the most blocking elements when working with Twig forms to easily design great UI. Because you don't have the corresponding data close at hand. The only way is to use the "form.child.vars.value" and pass to the Twig and array of the data mapped by value used to construct the form. In twig it ends up to have some code like this:

{% for child in form.field.vars %}    {% set myFormData = myArrayMapped[child.vars.value] %}    ...{% endfor %}

Without talking about the code structure, for example a global form you pass to every page like my previous example. Not hard or impossible but not pleasant for everyday use.

@OskarStarkOskarStark changed the title[TwigBridge] Add twig field_id() form helper[TwigBridge] Add Twigfield_id() form helperFeb 25, 2025
@chalasr
Copy link
Member

chalasr commentedMar 5, 2025
edited by welcoMattic
Loading

Please consider opening a new issue or PR for the feature you suggest.

@chalasr
Copy link
Member

Thank you for this nice first contribution@Legendary4226.

Legendary4226 reacted with laugh emoji

@chalasrchalasr merged commit6a029ec intosymfony:7.3Mar 5, 2025
11 checks passed
@Legendary4226Legendary4226 deleted the feature-1 branchMarch 6, 2025 18:08
@fabpotfabpot mentioned this pull requestMay 2, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@fabpotfabpotfabpot approved these changes

@xabbuhxabbuhxabbuh approved these changes

@mtarldmtarldmtarld approved these changes

@chalasrchalasrchalasr approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
7.3
Development

Successfully merging this pull request may close these issues.

7 participants
@Legendary4226@chalasr@fabpot@xabbuh@mtarld@nicolas-grekas@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp