Quantcast
Channel: Joomla! Forum - community, help and support
Viewing all articles
Browse latest Browse all 1904

Joomla! 5.x Coding • Help with Custom Plugin

$
0
0
Hey guys,
to keep this short... I've been working on a simple Custom button for the Editor. All of this code I got and modified from existing plugins.

So far, this works to Add the button to the editor, and Opens a modal window when clicked.

The problem is, the modal window is always empty. None of the $button->content is in the page source. I am at a complete loss here, even tried ChatGPT for help with no luck.

Code below: Can anyone shed some light on this please?

Code:

use Joomla\CMS\Language\Text;use Joomla\CMS\Object\CMSObject;use Joomla\CMS\Plugin\CMSPlugin;jimport( 'joomla.plugin.plugin' );class PlgEditorsXtdMacrosButton extends CMSPlugin{protected $autoloadLanguage = true;function onDisplay($name)    {$db = JFactory::getDBO();$query = $db->getQuery(true);$query->select($db->quoteName('template'));$query->from($db->quoteName('#__template_styles'));$query->where($db->quoteName('client_id') . ' = 0');$query->order($db->quoteName('home') . ' DESC');$db->setQuery($query);$template = $db->loadResult();        $filePath = JPATH_ROOT . '/templates/' . $template . '/html/shortcodes.ini';        $fileContent = file_get_contents($filePath);preg_match_all('/\[([^\]]+)\]/', $fileContent, $matches);$keys = $matches[1];$keyList = implode('<br>', $keys);$button = new CMSObject();        $button->modal   = true;        //$button->content = '<div class="macros-list">' . $keyList . '</div>';        $button->content = '<div class="macros-list"><h1>Static Content</h1></div>';        $button->text    = Text::_('PLG_EDITORS-XTD_MACROSBUTTON_BUTTON_TEXT');        $button->name    = $this->_type . '_' . $this->_name;        $button->icon    = 'file';        $button->iconSVG = '<svg width="24px" height="24px" viewBox="0 0 100 100"><polygon fill="#1cc3ed" points="89.189,12.197 64.033,12.197 45.632,43.797 27.231,12.197 2.074,12.197 45.571,87.803 45.632,87.693 45.692,87.803"><animate attributeName="fill" values="#1cc3ed;pink;orange;yellow;#1cc3ed" dur="10s" repeatCount="indefinite" /></polygon><polygon fill="#FFFFFF" points="97.926,12.197 72.77,12.197 54.368,43.797 35.967,12.197 10.81,12.197 54.307,87.803 54.368,87.693 54.43,87.803"/></svg>';$button->options = [        'height' => '300px',        'width'  => '800px',        'bodyHeight'  => '70',        'modalWidth'  => '80',        ];return $button;    }}

-------- Plugin explanation if you want it ------------

I use EasyShortcodes on most websites, and I want to add an Editor button that opens a modal window with the macros available. The user can click any of them and they will be added to the editor window.

I havent got to that last part yet. Im stuck on getting "anything" to show in the modal at all. Even static content doesn't show, and none of it ever appears in the page source.
But $button->text does indeed get put in the Modal Title... so this means it's ok right?

Statistics: Posted by joom-rookie — Sat Apr 20, 2024 6:50 am



Viewing all articles
Browse latest Browse all 1904

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>