Skip to content
This repository has been archived by the owner on Jul 10, 2020. It is now read-only.

Add new element #50

Open
guilherme-santos opened this issue Jan 30, 2014 · 15 comments
Open

Add new element #50

guilherme-santos opened this issue Jan 30, 2014 · 15 comments
Assignees

Comments

@guilherme-santos
Copy link
Contributor

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?

@neilime
Copy link
Owner

neilime commented Jan 31, 2014

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.

@guilherme-santos
Copy link
Contributor Author

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

@neilime
Copy link
Owner

neilime commented Feb 3, 2014

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

@guilherme-santos
Copy link
Contributor Author

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
Copy link
Contributor Author

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

@neilime
Copy link
Owner

neilime commented Feb 5, 2014

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

@guilherme-santos
Copy link
Contributor Author

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

@guilherme-santos
Copy link
Contributor Author

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

@neilime
Copy link
Owner

neilime commented Feb 6, 2014

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

@guilherme-santos
Copy link
Contributor Author

It works for me.. what do you think?

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

@neilime
Copy link
Owner

neilime commented Mar 24, 2014

I'll made a improvment asap with your suggestion

@neilime
Copy link
Owner

neilime commented May 11, 2014

The last version of Zend Framework 2 supports your request

@fabiocarneiro
Copy link
Contributor

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?

@guilherme-santos
Copy link
Contributor Author

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

@fabiocarneiro
Copy link
Contributor

@guilherme-santos #108

opinion?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants