Another post partially answered my question, but I want to know if and how would be possible to make use of addLayoutPath and setLayout in my editor-xtd plugin. Here's my plugin so far

defined('_JEXEC') or die;

class PlgButtonVimeo extends JPlugin

    protected $autoloadLanguage = true;

    public function onDisplay($name)
        $app = JFactory::getApplication();
        $input = $app->input;
        $user  = JFactory::getUser();

        // Can create in any category (component permission) or at least in one category
        $canCreateRecords = $user->authorise('core.create', 'com_content')
            || count($user->getAuthorisedCategories('com_content', 'core.create')) > 0;

        // Instead of checking edit on all records, we can use **same** check as the form editing view
        $values = (array) $app->getUserState('com_content.edit.article.id');
        $isEditingRecords = count($values);

        // This ACL check is probably a double-check (form view already performed checks)
        $hasAccess = $canCreateRecords || $isEditingRecords;
        if (!$hasAccess)

        // $this IS OUT OF CONTEXT
        // $root = $app->isSite() ? '' : '../';
        // $this->addLayoutPath($root.'plugins/editors-xtd/vimeo/tpl');
        // $this->setLayout('vimeo');

        JFactory::getDocument()->addScriptOptions('xtd-vimeo', array('editor' => $name));
        $link = 'index.php?option=com_content&view=article&layout=vimeo&tmpl=component&e_name=' . $name;

        $button          = new JObject;
        $button->modal   = true;
        $button->class   = 'btn';
        $button->link    = $link;
        $button->text    = JText::_('PLG_EDITORSXTD_VIMEO_BUTTON');
        $button->name    = 'palette';
        $button->options = "{handler: 'iframe', size: {x: 800, y: 500}}";

        return $button;

The view at vimeo.php is just a copy-paste of the pagebreak view in administrator/components/con_content/views/article/tmpl/pagebreak.php for now, it will be edited accordingly:

defined('_JEXEC') or die;

JHtml::_('behavior.polyfill', array('event'), 'lt IE 9');
JHtml::_('script', 'com_content/admin-article-pagebreak.min.js', array('version' => 'auto', 'relative' => true));

$document    = JFactory::getDocument();
$this->eName = JFactory::getApplication()->input->getCmd('e_name', '');
$this->eName = preg_replace('#[^A-Z0-9\-\_\[\]]#i', '', $this->eName);

<div class="container-popup">
    <form class="form-horizontal">

        <div class="control-group">
            <label for="title" class="control-label"><?php echo JText::_('COM_CONTENT_PAGEBREAK_TITLE'); ?></label>
            <div class="controls"><input type="text" id="title" name="title" /></div>

        <div class="control-group">
            <label for="alias" class="control-label"><?php echo JText::_('COM_CONTENT_PAGEBREAK_TOC'); ?></label>
            <div class="controls"><input type="text" id="alt" name="alt" /></div>

        <button onclick="insertPagebreak('<?php echo $this->eName; ?>');" class="btn btn-success pull-right">
            <?php echo JText::_('COM_CONTENT_PAGEBREAK_INSERT_BUTTON'); ?>


Thanks for any suggestion.

  • As an aside, I'll chime in to say that your pattern should be refined to #[^\w[\]-]+# because \w = [A-Za-z0-9_], - doesn't need to be escaped if it is at the beginning or end of the character class or if it immediately follows a range of characters (such as \w), the opening square brace does not require escaping because you cannot start a new character class from inside a character class, and the closing brace needs to remain escaped so that it does not prematurely close the character class. Test your patterns and learn what they ate doing at regex101.com May 5, 2019 at 15:45
  • Oh, and the plus sign is to match 1 or more consecutive characters in the chatacter class. This is a matter of efficiency. If I put a carton of 12 eggs at your feet and told you to pick up a dozen eggs ... it would be inefficient to perform 12 squads picking 1 egg at a time -- just pick up all 12 on the first squat. The Joomla core code fails to realize/apply this simple logic. (I am usually disappointed with the regex patterns within) May 5, 2019 at 15:48
  • Ha, I just realized that you linked to my question and my recommended pattern was already there. May 5, 2019 at 15:51
  • Thanks for joining the struggle! I was reading about JLayout but it seems to be something for front-end. I just need something similar but appropriate for my need. Also yours hopefully.
    – thednp
    May 5, 2019 at 15:55
  • Really hope to find a solution bcz I don't wanna revive stuff on every update :)
    – thednp
    May 5, 2019 at 16:06

1 Answer 1


Using com_ajax:

Rename PlgButtonVimeo class to PlgEditorsXtdVimeo.

Point button link to com_ajax:

$link = 'index.php?option=com_ajax&amp;plugin=vimeo&amp;group=editors-xtd&amp;format=html&amp;tmpl=component&amp;'
    . JSession::getFormToken() . '=1&amp;e_name=' . $name;

Add onAjaxVimeo method:

public function onAjaxVimeo()
    // Renders plugins/editors-xtd/vimeo/tmpl/default.php.
    include JPluginHelper::getLayoutPath($this->_type, $this->_name);
    return ob_get_clean();
  • @mickmackusa you can try this to make your editor-xtd button immortal. I tested and it's working fantastic.
    – thednp
    May 6, 2019 at 11:37
  • 1
    @thednp sometimes Sharky's answers need a little touching up. I am going to vote to approve your suggested edit, but in most scenarios you should not modify the code in an answer (often it is better to notify the poster and give them the chance to update it themselves or defend why they have written what they have written). May 6, 2019 at 23:25
  • 1
    @mickmackusa I implemented the solution into my code and noticed I didn't get the form name into the view. I specifically mentioned the code used was from pagebreak.php view, so I was expecting to be a value for e_name, but I will keep in mind in the future.
    – thednp
    May 7, 2019 at 4:43
  • Sadly this won't work with Joomla 4. With all the namespace updates I did and researched so far.
    – thednp
    May 17, 2019 at 22:29
  • UPDATE: the updated code that supposed to work on J4, works fine on J3.9.5.
    – thednp
    May 17, 2019 at 22:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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