How to Add an HTML Text Editor Field to an Extension in Joomla 1.5

We have explained a long time ago how to add an HTML Text Editor field to an extension in Joomla 2.5 – and we have stated that the method described in that post only works on Joomla 2.5. Back then, we thought that we’ll never have to do this on Joomla 1.5 – and we also assumed that none of our readers will have to as well. We have to admit we were wrong.

Today, one of our very important clients asked us to modify one of his custom modules to include an HTML text editor field in the backend – this would’ve been a 5 minute job had he been using Joomla 2.5 (we just use the editor type) – but, to our regret, he was using Joomla 1.5 and he wanted the work done on Joomla 1.5. Oops!

We spent literally hours trying to see if Joomla had an official guide to this, but all we could find was some half-baked/incomplete solutions that’ll address the problem but only after jumping through many, many hoops! But on the bright side, after this long research, we were able to create our own workable solution.

Here’s how it should be done:

Step 1 – Create a new element of type RichEditor

The first thing that you need to do is to create a new custom element. An element (OK – we won’t italicize it anymore) in Joomla is like a field type. For example, a calendar is an element, a category is an element, a textarea is an element, a text is an element, etc… (You can find the full list of standard elements here – Joomla refers to them as “form field and parameter types”).

As the title states, our new custom element should be called RichEditor, so you’ll need to create a file called RichEditor.php and place it under the elements folder under the module’s directory. So, if your module is called mod_listing, you will need to create the file RichEditor.php under the folder modules/mod_listing/elements.

The file RichEditor.php should consit of the below code:

<?php
class JElementRichEditor extends JElement{
    var $_name = 'RichEditor';
    function fetchElement($name, $value, &$node, $control_name){
        return JFactory::getEditor()->display($control_name.'['.$name.']', htmlspecialchars($value, ENT_QUOTES), $node->attributes('width'), $node->attributes('height'), $node->attributes('col'), $node->attributes('row'));
    }
}
?>

Step 2- Integrate the HTML text editor into your module

This can easily be done in just two steps:

  1. Tell the module where to find your newly created element

    Joomla modules (and all other extensions) are merely aware of the Joomla standard elements – they know absolutely nothing about the custom ones unless they are told about them. This can be easily done by replacing the <params> line in the module’s manifest (XML) file (which is mod_listing.xml in our case) with the following line:

    <params addpath=”/modules/mod_listing/elements”>

    (of course, we are assuming that you’re adding the HTML text editor to a module and that module’s name is mod_listing).

  2. Use the HTML text editor element!

    Yes – you’re right – you are done! All you need to do right now is just use that element you have just created. This can be easily done by adding the following line (under the <params addpath=”/modules/mod_listing/elements”> line in the manifest file):

    <param name=”my_html_editor” width=”350″ height=”150″ type=”RichEditor” label=”Text” description=”Please enter the text here.”/>

That’s it! Try the above on a Joomla 1.5 website and it should work! If you need help with the implementation, then we’re just a call or an email away! Oh, and don’t worry about our fees, they’re quite affordable!

Note: The above method will display Joomla’s default editor. So, if your Joomla’s default editor is JCE, then it’ll be displayed.

No comments yet.

Leave a comment