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

[Form] add a convenience method to get the parent form in Twig templates#28812

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
fabpot merged 1 commit intosymfony:masterfromxabbuh:issue-28686
Feb 13, 2019

Conversation

@xabbuh
Copy link
Member

@xabbuhxabbuh commentedOct 11, 2018
edited
Loading

QA
Branch?master
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets#28686
LicenseMIT
Doc PRsymfony/symfony-docs#10999

@ro0NL
Copy link
Contributor

it's a BC break no? also ref#19492 (comment)

@xabbuh
Copy link
MemberAuthor

Why would that be a BC break?

@xabbuh
Copy link
MemberAuthor

Taking into account#19492 (comment) we could of course think about adding a Twig function instead if we do not want to add this method to theFormView class.

@ro0NL
Copy link
Contributor

the order changes right? before a child named parent might be returned first, whereas now it's always the parent form

@ro0NL
Copy link
Contributor

alternatively, getting rid of arrayaccess in formview would also do it towards consistent accessors in php as well as twig, but that's a bigger step :)

@xabbuh
Copy link
MemberAuthor

If you refer toform.parent, this still returns the child form as Twig considersArrayAccess methods before looking at actually implemented methods. Andform.getParent() just is not usable without this change.

alternatively, getting rid of arrayaccess in formview would also do it towards consistent accessors in php as well as twig, but that's a bigger step :)

I don't think that's a good idea DX wise. Being able to useform.child_name is quite convenient.

@yceruto
Copy link
Member

yceruto commentedOct 11, 2018
edited
Loading

@xabbuh could we deprecatingtwig_is_root_form() test func then? I guess it wouldn't useful anymore, replacing it by{% form.getParent() is null %}.


In the other hand, I think the solution should be done in Twig context, because having a getter for a public property seems odd.

What about adding a new Twig function for access to theFormView public properties? Something like this:

publicfunctiongetPropertyValue($object,string$propertyName){return$object->$propertyName;}

for cases where the public property matches the name of the child form (ArrayAccess ambiguity in Twig context):

{# $formView->parent#}{%if property_value(form,'parent')isnull %}{# $formView->vars#}{%if property_value(form,'vars').attr.classisdefined %}

even, otherArrayAccess objects (in userland) with a composition similar toFormView can benefit from it, too.

@xabbuh
Copy link
MemberAuthor

I have rewritten this solution to add a newparent_form() Twig function instead. I would not deprecate the filter for now. Both the filter and the new function serve their own use cases.

@javiereguiluz
Copy link
Member

@xabbuh please, create an issue in Symfony Docs to not forget about this. Also, please add some usage examples and if this improves an existing feature add a before/after example. Finally, please check if this fixes something that the current docs say it's not possible to do or buggy. Thanks!

@fabpot
Copy link
Member

Thank you@xabbuh.

@fabpotfabpot merged commitcb60642 intosymfony:masterFeb 13, 2019
fabpot added a commit that referenced this pull requestFeb 13, 2019
… in Twig templates (xabbuh)This PR was merged into the 4.3-dev branch.Discussion----------[Form] add a convenience method to get the parent form in Twig templates| Q             | A| ------------- | ---| Branch?       | master| Bug fix?      | no| New feature?  | yes| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets |#28686| License       | MIT| Doc PR        |Commits-------cb60642 add a convenience method to get the parent form in Twig templates
@xabbuhxabbuh deleted the issue-28686 branchFebruary 13, 2019 09:41
@xabbuh
Copy link
MemberAuthor

@javiereguiluz it took me some time, but here we go now:symfony/symfony-docs#10999

javiereguiluz reacted with heart emoji

javiereguiluz added a commit to symfony/symfony-docs that referenced this pull requestFeb 16, 2019
This PR was merged into the master branch.Discussion----------document the parent_form() Twig functiondocumentssymfony/symfony#28812Commits-------2ea9797 document the parent_form() Twig function
@nicolas-grekasnicolas-grekas modified the milestones:next,4.3Apr 30, 2019
@fabpotfabpot mentioned this pull requestMay 9, 2019
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@fabpotfabpotfabpot approved these changes

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

@ycerutoycerutoyceruto approved these changes

+1 more reviewer

@ro0NLro0NLro0NL approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

4.3

Development

Successfully merging this pull request may close these issues.

7 participants

@xabbuh@ro0NL@yceruto@javiereguiluz@fabpot@nicolas-grekas@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp