look near the top of the edit.php file we copied to our template, we'll find these two lines of code:
$editor = KunenaBbcodeEditor::getInstance();
$editor->initialize('id');
It's in the initialize method where the xml file is read and the buttons rendered. So why not create our own override of the KunenaBbcodeEditor class so we can use our own custom xml file?
First copy the xml file into the same folder as the earlier mentioned edit.php file:
/libraries/kunena/bbcode/editor.xml => /templates/<YOURTEMPLATE>/html/com_kunena/topic/cuseditor.xml
Then, create a new php file in this directory named cuseditor.php.
The cuseditor.php file is where we'll create our own version of the editor class, like so:
defined('_JEXEC') or die();
class CusBbcodeEditor extends KunenaBbcodeEditor {}
There are two methods we need to change for our purposes. First the ::getInstance() method. Copy the code from the original class using our new class name for the instance:
public static function getInstance($config = array()) {
static $instance = false;
if (!$instance) {
$instance = new CusBbcodeEditor($config);
}
return $instance;
}
Note the only change we're making is to return our new CusBbcodeEditor class object.
The method we really care about is the initialize method that reads in the xml button definitions. Again copy the code from the original and make one small change to load our copied version:
{codecitation width="650px"} public function initialize($identifier='class') { $js = "window.addEvent('domready', function() { kbbcode = new kbbcode('kbbcode-message', 'kbbcode-toolbar', { dispatchChangeEvent: true, changeEventDelay: 1000, interceptTab: true });\n"; $xml_file = simplexml_load_file(dirname(__FILE__).'/cuseditor.xml'); $this->editor_elements = self::parseXML($xml_file); //Hook to manipulate the Editor XML like adding buttons $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('kunena'); $dispatcher->trigger( 'onKunenaBbcodeEditorInit', array ( $this ) ); foreach ($this->editor_elements as $item) { $js .= $item->generateJs($identifier); } $js .= "});\n"; $template = KunenaTemplate::getInstance(); $template->addScript('js/editor.js'); JFactory::getDocument()->addScriptDeclaration( "// "); } {/codecitation}
Note again only one small change to read the renamed xml file from the same directory as our new cuseditor.php.
Our next to final step is to have the template override use our new class. In the edit.php template override, replace this line:
$editor = KunenaBbcodeEditor::getInstance();
With these two lines:
require_once __DIR__ . '/cuseditor.php';
$editor = CusBbcodeEditor::getInstance();
You are now using your own customized version of Kunena's BBCode editor with minimal changes and no core edits