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