Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[Form] set unique block prefix with any namespace#17874
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
Uh oh!
There was an error while loading.Please reload this page.
Conversation
enumag commentedMar 4, 2016
👍 I've just noticed similar error in my own application. The problem seems to occur when a prefix is repeated in the block_prefixes array. The exception is thrown too early - in the example from@andrey1s the block form_row certainly exists even though the exception says otherwise. |
webmozart commentedMar 7, 2016
Hi, thanks for reporting this problem :) How can it happen that a block name is repeated in the chain? Can you provide code that reproduces your problem? |
andrey1s commentedMar 7, 2016
for example //src/AppBundle/Controller/IndexController.php<?phpnamespaceAppBundle\Controller;useSensio\Bundle\FrameworkExtraBundle\Configuration\Route;useSymfony\Bundle\FrameworkBundle\Controller\Controller;useSymfony\Component\HttpFoundation\Request;useAppBundle\Form\Type\Other\SimpleType;class IndexControllerextends Controller{/** * @Route("/", name="homepage") */publicfunctionhomepageAction(Request$request) {$form =$this ->createFormBuilder() ->add('simple', SimpleType::class) ->getForm() ;return$this->render('@App/Index/homepage.html.twig', ['form' =>$form->createView()]); }} forms <?php//src/AppBundle/Form/Type/Other/SimpleType.phpnamespaceAppBundle\Form\Type\Other;useSymfony\Component\Form\AbstractType;useAppBundle\Form\Type\SimpleTypeasBaseType;class SimpleTypeextends AbstractType{publicfunctiongetParent() {return BaseType::class; }} <?php//src/AppBundle/Form/Type/SimpleType.phpnamespaceAppBundle\Form\Type;useSymfony\Component\Form\AbstractType;useSymfony\Component\Form\Extension\Core\Type\TextType;class SimpleTypeextends AbstractType{publicfunctiongetParent() {return TextType::class; }} when there are two blocks with the same name is an error. <?php//src/AppBundle/Form/Type/Other/SimpleType.phpnamespaceAppBundle\Form\Type\Other;useSymfony\Component\Form\AbstractType;useAppBundle\Form\Type\SimpleTypeasBaseType;class SimpleTypeextends AbstractType{publicfunctiongetParent() {return BaseType::class; }publicfunctiongetBlockPrefix() {return'text'; }} |
| // and tries to avoid execution of unnecessary checks in order to increase performance. | ||
| if (isset($this->resources[$cacheKey][$parentBlockName])) { | ||
| if (isset($this->resources[$cacheKey][$parentBlockName]) &&$this->resources[$cacheKey][$parentBlockName] !==false) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
This change is missing a corresponding test.
Also you are reducing the impact of a performance optimization here. Could you benchmark the result for big forms?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
i can't find any test for theSymfony\Component\Form\AbstractRendererEngine orSymfony\Component\Form\Extension\Templating\TemplatingRendererEngine, could you show where are they located?
could you show the current benchmark?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Should be the yoda style like:
false !==$this->resources[$cacheKey][$parentBlockName]
webmozart commentedMar 8, 2016
Thanks for the example, I understand your use case now. This conveys a bigger problem IMO. In a template, a block (e.g.
We should consider to recommend returning unique values from |
enumag commentedMar 8, 2016
@webmozart In that case we should modify the exception - if there is a duplicate in the array throw an exception about that instead of what is thrown currently. Probably only when a problem like this occurs to avoid unnecessary checking for non-unique prefixes for every field. |
andrey1s commentedMar 8, 2016
@webmozart if we need to use a unique template, then Yes, otherwise it's not necessary. or |
webmozart commentedMar 9, 2016
fabpot commentedJun 16, 2016
IIUC, this change should not be merged but a new exception should be added, is that correct? How do we moved forward? |
enumag commentedJun 19, 2016
fabpot commentedJun 21, 2016
@enumag Can you update this PR with the commit you mentioned above? Tests can be added later or by someone else if needed. |
enumag commentedJun 21, 2016
@fabpot I'm not the author of this PR so I'll have to create a new one instead. Wait a moment... |
xabbuh commentedJun 21, 2016
Does that mean we should close here in favour of#19127? |
fabpot commentedJun 21, 2016
Closing in favor of#19127 |
…k names (enumag)This PR was merged into the 2.7 branch.Discussion----------[Form] Add exception to FormRenderer about non-unique block names| Q | A| ------------- | ---| Branch? | 2.7| Bug fix? | yes| New feature? | no| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets |#17874| License | MIT| Doc PR |Commits-------c6db6f3 [Form] Add exception to FormRenderer about non-unique block names
if there is no block
hidden_locale_rowwhen error