I have created a custom installable component for Joomla. I need to add editor on a textarea.

How can I use Joomla editor into custom component??


If you are not using JForm you can always do this with a bit of PHP code:

$editor = JEditor::getInstance(JFactory::getConfig()->get('editor'));
echo $editor->display($name, $contents, $width, $height, $cols, $rows, $buttons, $id, $asset, $author, $params);


$name is the name of the editor field on your form. This will be they key used for the content in your form's POST.

$contents is the HTML contents of the editor, presumably fetched from the database. That's what the user is editing.

$width and $height are the width and height of the editor, formatted for inclusion in a CSS statement. So this could be something like '100%', '10em' or '100px'. Based on my experience, width best works as a percentage (of the field's container) whereas height is usually best set in pixels and no less than 400 of them. I usually test the layout with JCE, using a profile with all editor buttons shown since that's the most interface-heavy configuration I have come across.

$cols and $rows is the number of columns and rows in the textarea displayed if the browser does not support rich text editing or, simply, JavaScript is disabled. Remember that this is given in absolute number corresponding to number of characters and lines respectively. Something like 50 columns and 10 rows should be enough as a minimum (and it shouldn't matter if you're using some CSS to style the textarea anyway).

This is the end of the mandatory parameters. Everything beyond that is optional and rarely used.

$buttons is a boolean, telling Joomla whether to render the buttons defined by editor-xtd plugins such as pagebreak, read more and so on. By default it's true. Depending on the editor they might be rendered in the editor's toolbar or below the editor area. TinyMCE, Joomla's default editor, renders them in the toolbar. Most other editors render them below the editor.

$id is the HTML id attribute. Leave null to use the same value as $name.

$asset is the asset ID of the content you are editing. If you are not using asset tracking for your content or don't know what it is pass null.

$author is the user's ID. In most cases you can pass null and let Joomla figure it out.

$params is an associative array of editor parameters. It only makes sense using it if you know what the editor is and have some special reason to pass parameters to it. In all practical cases I've run across I just skip the field.

The biggest caveat is that you need to filter the POSTed content in your Controller yourself. But since you're not explicitly asking about handling content I leave that up to you.

| improve this answer | |

Add editor type field to your form:


You can learn more about the Editor form field and see its available attributes here: https://docs.joomla.org/Editor_form_field_type

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.