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)
{
return;
}
// I DON'T KNOW HOW TO SET THIS CODE HERE
// $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.core');
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);
$document->setTitle(JText::_('COM_CONTENT_PAGEBREAK_DOC_TITLE'));
?>
<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>
<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>
</div>
<button onclick="insertPagebreak('<?php echo $this->eName; ?>');" class="btn btn-success pull-right">
<?php echo JText::_('COM_CONTENT_PAGEBREAK_INSERT_BUTTON'); ?>
</button>
</form>
</div>
Thanks for any suggestion.
#[^\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 – mickmackusa♦ May 5 '19 at 15:45revive
stuff on every update :) – thednp May 5 '19 at 16:06