zf2-twb-bundle icon indicating copy to clipboard operation
zf2-twb-bundle copied to clipboard

Add new element

Open guilherme-santos opened this issue 11 years ago • 15 comments

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?

guilherme-santos avatar Jan 30 '14 15:01 guilherme-santos

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.

neilime avatar Jan 31 '14 10:01 neilime

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..

guilherme-santos avatar Jan 31 '14 16:01 guilherme-santos

I'm sorry but the class TwbBundle\Form\Element\TwbBundleFormElement does not exist, are you talking about TwbBundle\Form\View\Helper\TwbBundleFormElement ?

neilime avatar Feb 03 '14 10:02 neilime

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...

guilherme-santos avatar Feb 03 '14 11:02 guilherme-santos

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..?

guilherme-santos avatar Feb 05 '14 13:02 guilherme-santos

You have to overwrite TwbBundle\Form\View\Helper\TwbBundleFormElement::render function : https://gist.github.com/neilime/8823655

neilime avatar Feb 05 '14 13:02 neilime

Sure, I ask why i would like to avoid duplicate all this logic, but It's ok, It was I image! Thanks ;)

guilherme-santos avatar Feb 05 '14 13:02 guilherme-santos

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...

guilherme-santos avatar Feb 05 '14 23:02 guilherme-santos

Yes you're right, I'll make changes to support custom view helpers

neilime avatar Feb 06 '14 17:02 neilime

It works for me.. what do you think?

https://gist.github.com/guilherme-santos/8849298

guilherme-santos avatar Feb 06 '14 17:02 guilherme-santos

I'll made a improvment asap with your suggestion

neilime avatar Mar 24 '14 21:03 neilime

The last version of Zend Framework 2 supports your request

neilime avatar May 11 '14 17:05 neilime

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?

fabiocarneiro avatar Oct 29 '14 16:10 fabiocarneiro

No, I'm using like I show you in gist...

guilherme-santos avatar Oct 29 '14 17:10 guilherme-santos

@guilherme-santos https://github.com/neilime/zf2-twb-bundle/pull/108

opinion?

fabiocarneiro avatar Oct 30 '14 15:10 fabiocarneiro