Override Joomla view logic class through plugin

On previous post, I wrote about overriding AcyMailing’s archive view class with the purpose of adding a custom field. It was done through alteration of component core file since layout-override only applies to view-output files. Later, I found a more sensible way to override the view class through plugin. In its simplest term, the plugin is used to include the modified view-class thus the original view-class never gets declared. This is possible because when the system instantiates the view class, it uses class_exists to load the respective class. When a class gets declared, the subsequent declaration will simply be ignored.

The following code demonstrates this possiblity. The code gets executed during onAfterRoute event and it does so by including archive.view.html.php

On a side note, the plugin xml file now accepts install and sql tag but does’t seem to accept uninstall tag. During the plugin installation, the sql runs okay but not during uninstallation. Otherwise, this AcyMailing field extender could be packaged into an installable plugin and that the alteration of database, view-logic files inclusion and output override can be seamless and automatic through plugin installer.

Reference : http://community.joomla.org/blogs/community/521-did-you-know-overrides-are-not-just-for-html.html

Extend AcyMailing : add custom newsletter field

Recently, I worked on a Joomla based website where one of the requirements was to add a custom field and display it in front-end newsletter archive list, next to the default subject and date. This additional field contains multi-line short descriptions and would act as a summary to each newsletter. And there has to be an extra corresponding textarea in the back-end for the editing of this custom field during creation or updating of newsletters.

In back-end, by default, I see no option to just add the custom field, which means field addition to newsletter table isn’t supported out of the box. So one way to do is to alter the newsletter table and edit a few component files.

I posted the following steps in the hope that this might be of help to other users who are trying to achieve the same thing. Before that, please back-up database and Joomla files just in case.

  1. Add the custom field after ‘altbody’ to the newsletter table. Note that my table prefix is ‘jos’, if you have a different prefix, change it to whatever you’ve set during the installation.
  2. Add an editable textarea to the newsletter back-end form. Edit administrator/components/com_acymailing/views/newsletter/tmpl/form.php, add the following code after line 22:
  3. Alter newsletter archive’s view logic to include custom field query to the newsletter table. Edit components/com_acymailing/views/archive.view.html.php, replace line 98:

    with the following:
  4. Alter newsletter archive listing to show another table header and also the custom field. Multiple lines contained in this custom field would be outputted as unordered list. Edit components/com_acymailing/views/archive/tmpl/listing_newsletters.php, add the following code after line 33:

    and add after line 78 the following code:
  5. On step 4, we used JText::_( 'SUMMARY' ) to output its heading to table header. This entry is retrieved from the current active component’s language file. Since this is a new language entry, we need to add it to the language file. Edit language/en-GB/en-GB.com_acymailing.ini, add the following code after line 25:

Steps above are the minimum to get the custom field working. By now, the summary field should show up below the text version on the same form in the newsletter back-end. We can type summaries of the newsletter into that textarea and it will be saved into newsletter table. And once saved, it will be displayed on the archive list of the front-end as unordered list.

Last thing you might be concerned about is how the newer update of the component is going to affect the above alteration. We can technically put our altered view files under html folder of our current active template and leave the core view logic files untouched as these files will override those inside the component during execution of view logic. But this applies only to step 2 and 4 but not step 3 which contains the archive view logic. Because as of Joomla! 1.6, only component and module view output files can be overridden but not view logic files. So for now, we need to keep track of what has been changed and re-apply again on the next update.

Joomla Files and Classes Inclusion Graph

This is another repost from my other blog which doesn't exist any longer. I am retaining it for reference.

Federico of PhpImpact posted a few graphs showing class dependencies and files inclusion of various open source frameworks such as WordPress, MediaWiki, CodeIgniter and CakePHP. These graphs provides an overview of files and classes inclusion during the initial load of a system. These graphs also show which files and classes are being referenced or called from the root controller, showing dependency structure of the said system.

There isn't any graph for Joomla! 1.5 yet which I use fairly often so I created one using Inclued and Graphviz utility. The following 2 graphs are generated from Joomla! 1.5.7 running default frontpage controller.