zf2-twb-bundle
zf2-twb-bundle copied to clipboard
Add new element
Hi, It's more like a help and about your opnion... Before I use TwbBundle when I added new element I created new class inherit from FormElement, but now you overwrite this class, what do you think it's the best way to create new element?
If I overwrite your class I will need to duplicate a lot of code when I only need change this line: https://github.com/neilime/zf2-twb-bundle/blob/master/src/TwbBundle/Form/View/Helper/TwbBundleFormElement.php#L51
What do you think?
I'm not sure I understand your question. You say that I overwrite \Zend\Form\Element
, it 's false.
TwbBundle\Form\Element\StaticElement
is just a new element wich represent Static control. So you don't have to extends your own element with this class.
No, I don't talk about TwbBundle\Form\Element\StaticElement
, I'm talking about TwbBundle\Form\Element\TwbBundleFormElement
I need to add new element for example Test\Form\Element\MyElement
I should inherit from Zend\Form\Element
for example... and I need to create a View Helper to that element, Test\Form\View\Helper\FormMyElement
what class do I should inherit from?
I image you say Zend\Form\View\Helper\Element
and add block of code to call formMyElement plugin... BUT If i do that, your TwbBundle\Form\Element\TwbBundleFormElement
won`t be called..
I'm sorry but the class TwbBundle\Form\Element\TwbBundleFormElement
does not exist, are you talking about TwbBundle\Form\View\Helper\TwbBundleFormElement
?
I'm sorry, and yes I'm talking about TwbBundle\Form\View\Helper\TwbBundleFormElement
The problem is... For my new element I need a new FormViewHelper to render it, but I don't know when and how can I call new form view helper to new element...
Let's try again...
I need to add an element called Test\Form\Element\MyElement
And I need also add its view helper Test\Form\View\Helper\MyElement
The problem is... How can I call view helper automatically? Without your module I will inherit from Zend\Form\View\Helper\FormElement
but your module already overwrite this class with a lot of logic...
Can you see what I'm saying..?
You have to overwrite TwbBundle\Form\View\Helper\TwbBundleFormElement::render
function : https://gist.github.com/neilime/8823655
Sure, I ask why i would like to avoid duplicate all this logic, but It's ok, It was I image! Thanks ;)
It doesn't work... Because when you call parent::render()
parent is TwbBundle\Form\View\Helper\TwbBundleFormElement
and everything is render twice, add-ons for example...
Yes you're right, I'll make changes to support custom view helpers
It works for me.. what do you think?
https://gist.github.com/guilherme-santos/8849298
I'll made a improvment asap with your suggestion
The last version of Zend Framework 2 supports your request
I'm also with this problem. @neilime Can you explain how this support was added to last version of zf2? is there any example?
@guilherme-santos Did you found another solution without overriding the twb form element?
No, I'm using like I show you in gist...
@guilherme-santos https://github.com/neilime/zf2-twb-bundle/pull/108
opinion?