Cannot insert text into Editor in Joomla 5 Editors XTD Button Plugin

I want to add a button in Joomla 5 WYSIWYG Article Editor. The function is rather simple. I want to add a Pinterest Feed to the source of article not inside the normal text of the editor at cursor position like so…

Upon clicking the button, a prompt will be displayed for entry of board URL like above example.

I want to also add to the source the following JS from official Pinterest to display feeds. I also want to place a check that it is added only once so that it is not repeated again and again in the code if multiple boards are inserted.

To be honest, I’m new to Joomla CMS, So I tried accessing the samples online for this purpose. None worked for me. I tried ChatGPT to create one. It did not even added the button. After a little lookup online, I found a working example that adds a button and asks for a prompt but fails at code insert part. Below is the code I’m using.

plg_editor_test.xml

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code><?xml version="1.0" encoding="utf-8"?>
<extension version="2.5" type="plugin" method="upgrade" group="editors-xtd">
<name>Editor XTD Button Test</name>
<author>Ghost</author>
<creationDate>April 2024</creationDate>
<copyright>Ghost. All rights reserved.</copyright>
<license>CC0</license>
<authorEmail>[email protected]</authorEmail>
<authorUrl>none.com</authorUrl>
<version>1.0.0</version>
<description>
"Adds a test button to the Editor"
</description>
<files>
<filename plugin="test">test.php</filename>
</files>
</extension>
</code>
<code><?xml version="1.0" encoding="utf-8"?> <extension version="2.5" type="plugin" method="upgrade" group="editors-xtd"> <name>Editor XTD Button Test</name> <author>Ghost</author> <creationDate>April 2024</creationDate> <copyright>Ghost. All rights reserved.</copyright> <license>CC0</license> <authorEmail>[email protected]</authorEmail> <authorUrl>none.com</authorUrl> <version>1.0.0</version> <description> "Adds a test button to the Editor" </description> <files> <filename plugin="test">test.php</filename> </files> </extension> </code>
<?xml version="1.0" encoding="utf-8"?>
<extension version="2.5" type="plugin" method="upgrade" group="editors-xtd">
        <name>Editor XTD Button Test</name>
        <author>Ghost</author>
        <creationDate>April 2024</creationDate>
        <copyright>Ghost. All rights reserved.</copyright>
        <license>CC0</license>
        <authorEmail>[email protected]</authorEmail>
        <authorUrl>none.com</authorUrl>
        <version>1.0.0</version>
        <description>
            "Adds a test button to the Editor"
        </description>
        <files>
            <filename plugin="test">test.php</filename>
        </files>
</extension>

test.php

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code><?php
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport( 'joomla.plugin.plugin' );
class plgButtonTest extends JPlugin {
function plgButtonTest(& $subject, $config)
{
parent::__construct($subject, $config);
}
function onDisplay($name)
{
$js = "
function buttonTestClick(editor) {
txt = prompt('Please enter something', '123');
if (!txt) return;
jInsertEditorText('{test '+txt+'}', editor);
}";
$css = ".button2-left .testButton {
font-weight: bold;
}";
$doc = JFactory::getDocument();
$doc->addScriptDeclaration($js);
$doc->addStyleDeclaration($css);
$button = new JObject();
$button->set('modal', false);
$button->set('onclick', 'buttonTestClick(''.$name.'');return false;');
$button->set('text', JText::_('Test'));
$button->set('name', 'testButton');
$button->set('link', '#');
return $button;
}
}
?>
</code>
<code><?php // no direct access defined( '_JEXEC' ) or die( 'Restricted access' ); jimport( 'joomla.plugin.plugin' ); class plgButtonTest extends JPlugin { function plgButtonTest(& $subject, $config) { parent::__construct($subject, $config); } function onDisplay($name) { $js = " function buttonTestClick(editor) { txt = prompt('Please enter something', '123'); if (!txt) return; jInsertEditorText('{test '+txt+'}', editor); }"; $css = ".button2-left .testButton { font-weight: bold; }"; $doc = JFactory::getDocument(); $doc->addScriptDeclaration($js); $doc->addStyleDeclaration($css); $button = new JObject(); $button->set('modal', false); $button->set('onclick', 'buttonTestClick(''.$name.'');return false;'); $button->set('text', JText::_('Test')); $button->set('name', 'testButton'); $button->set('link', '#'); return $button; } } ?> </code>
<?php

 // no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

jimport( 'joomla.plugin.plugin' );

class plgButtonTest extends JPlugin {

    function plgButtonTest(& $subject, $config)
    {
        parent::__construct($subject, $config);
    }
    function onDisplay($name)
    {

        $js = "
        function buttonTestClick(editor) {
                        txt = prompt('Please enter something', '123');
                        if (!txt) return;                       
                        jInsertEditorText('{test '+txt+'}', editor);
                        
            }";

        $css = ".button2-left .testButton {
                    font-weight: bold;
                }";
        $doc = JFactory::getDocument();
        $doc->addScriptDeclaration($js);
        $doc->addStyleDeclaration($css);
        $button = new JObject();
        $button->set('modal', false);
        $button->set('onclick', 'buttonTestClick(''.$name.'');return false;');
        $button->set('text', JText::_('Test'));
        $button->set('name', 'testButton');
        $button->set('link', '#');
        return $button;
    }
}
?>

When I click the button a prompt is displayed. Clicking OK does nothing and I get the following in console.

Uncaught ReferenceError: jInsertEditorText is not defined

The help pages of Joomla really go over my head as I can not find any beginner friendly documentation regarding this.

New contributor

Annonymous Mailer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật