Hi folks,
during the christmas holidays in 2018 I wondered if it would be possible to use the symfony/form
component in extbase controllers. For those who don't know: extbase is the extension framework of TYPO3.
tldr;
It worked! Here is a demo:
https://github.com/alexanderschnitzler/extbase-with-symfony-forms-demo
So, why did I do it anyway?
There are dozens of solutions for rendering forms in TYPO3. Extensions like powermail, formhandler, formz and many more. And on top of that, there is the core extension called form. And guess what, that's right. But I never aimed for a fully fletched competitor. All I have to offer is a proof of concept.
I got the idea when I upgraded a client's website and there were compatible versions for all extensions but for that one form extension. And when I realised that the form couldn't be more simple, I thought: It's so easy to build forms with symfony/form
, can I have that in TYPO3?
And what do you do if you ask yourself such things? You google.
First thing I tried was symfony/form standalone
and I had an instant hit:
https://github.com/lostedboy/symfony-form-standalone
Well, the example code was a bit outdated and that's where most of the work went into. I tried to use the code with symfony version 4.2 but it turned out that the api changed. So I had to reverse engineer and try thing and eventually understand things. Until I came up with a working setup.
As mentioned earlier, I put the proof of concept in a demo repository on github and if you are interested to see code, check it out. If you want to see the thing in action, read the README.md
, follow the install instructions and you're good to go.
The good parts
If you check out the code you'll see that there is not only a simple form but a few more features that come in quite handy if dealing with forms.
First of all, you almost alway want validation. Well, it's in there. However, the shown solution doesn't support validation via doctrine/annotation
annotations, buuuut, that would be possible to achieve as well.
Then, you might want to have a working solution against CSRF. Guess what? It's in there! symfony/security-csrf
does a great job!
What else? Well, some might want to use twig and its form helpers. Guess what? Yes, it's in there! Ok, it's not that awesome but still, it's nice to have, isn't it?
The bad parts
Where there's light, there's shadow.
Not always true but in this case, well, there is a downside. First of all you need to setup your TYPO3 installation with composer. Yes, unfortunately it's still possible to just grab a tar ball and extensions with dependencies to other packages are worthless. But maybe all this might help raise a little awareness for how great it is to use composer to setup TYPO3.
Another downside is the initialization of all components that take place in the controller itself. Of course, a proper solution would look different. But, maybe, this is a blueprint for future developers that want to bring that into the TYPO3 core.
Well, that's it for the bad parts.
Thanks for reading and until the next one.
Top comments (0)