New plugin: dmAlternativeHelperPlugin
December 10, 2009 by annis
Following up from the last blog post announcing the release of Diem plugins, dmAlternativeHelperPlugin just joined the ranks.
What does it do?
The template helpers were designed to be very short. To create an (x)html tag with content, all you had to do was type £('tag', 'content') and you were done. The problem was that most keyboards do not contain the £ (pound) sign, making it difficult and long-winded to develop templates. dmAlternativeHelperPlugin comes to the rescue by providing you with a-little-bit-longer-but-easier-to-type method names to use in your Diem templates:
- _tag for £
- _tagO for £o
- _tagC for £c
- _link for £link
- _media for £media
- _table for £table
How do I get it?
Just update to the latest svn version of Diem, it's included in the core as it needs to be available at anytime. This is because plugins can also bundle templates and thus, can potentially use these alternative helpers.
For people not wanting to update to the latest svn version it is also available in the symfony SVN and has a dedicated symfony plugin page. The plugin has a solid unit test coverage but feel free to test it, ask your questions in the Diem Google group and of course, report any bugs you find in the symfony trac!
The documentation can be found directly on the plugin's page.
Now, a few technical details
Still with me? Good. As you'll hopefully soon be frantically developing your own Diem plugins, I want to quickly go over a few details on how this plugin was done. Believe me, this plugin is very, very simple!
Diem uses the symfony Dependency Injection component to handle extensibility. For this plugin I had to override the helper service and use my own. What I actually did, was simply create a class dmAlternativeHelper (my own helper service class) that extends dmHelper (Diem's default helper service class as declared in Diem core's services.yml) and just proxy our custom helper method calls to their corresponding method in Diem's default helper class. If all that sounds like voodoo to you, here's a glimpse inside the actual code:
dmAlternativeHelperPlugin/config/dm/services.yml
parameters:
helper.class: dmAlternativeHelper
So, we're just overriding the helper class with our own implementation, pretty simple.
dmAlternativeHelperPlugin/lib/view/dmAlternativeHelper.php
class dmAlternativeHelper extends dmHelper { public function _tagO($tagName, array $opt = array()) { return $this->£o($tagName, $opt); } public function _tagC($tagName) { return $this->£c($tagName); } ... }
See? Just proxying to Diem's default helper class methods. Using this approach you can clearly see why Diem is incredibly flexible and easy to extend or even bent and changed to your own requirements.
Write your own!
I think that more documentation needs to be written for the developers to really understand all the internals of Diem. I hope with this glimpse I made your mouth water for more. For now, just look at the plugin code that's already been written so far. You can find all available plugins on the plugins page.