Question

I'm working on a Joomla! 2.5/3.x editor-xtd button and I have a problem loading a layout from file on button click.

I have tried this method:

$link = 'plugins/editors-xtd/myplugin/myplugin.layout.php?name='.$name;

$button = new JObject;
$button->modal = true;
$button->class = 'btn';
$button->link  = $link;
$button->text  = 'Insert something';
$button->name  = 'myplugin';
$button->options = "{handler: 'iframe', size: {x: 500, y: 300}}";

... but the full generated link in admin looks like http://my.local.host/mywebsite/administrator/plugins/editor-xtd/link-etc.. and it doesn't work. I also have tried including JURI::base in my $link, but the administrator path is still loaded.

I'm new in plugin dev with Joomla! and I have search a lot but no solution found.

** I also tried a link like this index.php?folder=plugins.editors-xtd.myplugin&file=myplugin.layout.php&name=$name but still nothing. Is there a workout for this or I'll have to create&use a javascript function to run on button click?

Was it helpful?

Solution

Solution

Modify link variable like this (if application is admin):

$link = '../plugins/editors-xtd/myplugin/myplugin.layout.php?name='.$name;

... and delete button options (this means that file contents will be loaded via ajax inside modal)

Further more, in myplugin.layout.php we can add a little security check and we can import Joomla! framework library and defines so that we can make use of Joomla! framework in our file (things like language load for eg.) This is my actual header of file:

<?php

// No direct access
define('IS_AJAX', isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'); 
if( ! IS_AJAX) die;

// Include J!Framework for later use
define( '_JEXEC', 1 );
define( 'JPATH_BASE', realpath(dirname(__FILE__).'/../../..'));
define( 'DS', DIRECTORY_SEPARATOR );
require_once ( JPATH_BASE.DS.'includes'.DS.'defines.php');
require_once ( JPATH_BASE.DS.'includes'.DS.'framework.php');

//more magic goes here...

OTHER TIPS

Unfortunately there is a bit of a gotcha here in that the JED checker process requires that ALL php files start with defined('_JEXEC') or die; on the very first line of code so if you want to share it on extensions.joomla.org then you are stymied...

Back on the OP you can detect whether you are in the Admin or Site before generating the link:

    $app = JFactory::getApplication();
    // ...
    if ($app->isAdmin()) {
        $root = '../';  // Joomla expects a relative path, leave site folder "administrator"
    } else {
        $root = '';
    }
    $button->link = $root.'/plugins/editors-xtd/myplugin/myplugin.layout.php?name='.$name;

Also, as you may already know the $button->name = 'myplugin'; needs to be the name of the icon from the Joomla icomoon set - you can see them here https://ma.tvtmarine.com/en/blog/112-joomla-icomoon-icons-directory The name needs to be the icon name without the .icon- bit eg: $button->name = 'warning-2';

code block doesn't seem to be working properly...sorry about the formatting

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top