I'm working on a plugin which should provide support for plugins. But I don't get it to call (and execute) its own plugins - and I have read the doc forward and backward and for the life of me am not seeing the problem.
So I build a simple example to understand the mechanism - and fortunately the example fails as well, so at least my (mis)-understanding is consistent...
The main-plugin is this (mainplugin.php).
<?php
jimport('joomla.plugin.plugin');
class plgContentMainplugin extends JPlugin
{
function onAfterRender()
{
JPluginHelper::importPlugin('mainplugin_plugin');
$dispatcher = JDispatcher::getInstance();
$a="collecting calls\n";
$data = array("Hello", &$a);
$res = $dispatcher->trigger('onmainiscalling', $data);
$tmp="res of trigger: " . nl2br(print_r($res,true));
echo '<div style="border: 3px black solid; background-color: yellow; color: black;">';
echo '<h1>Here is the result of "onmainiscalling"</h1>' . $tmp;
echo '</div>';
}
function onmainiscalling($data) {
$r="own fn was called";
return $r;
}
}
?>
And it is installed with mainplugin.xml:
<?xml version="1.0" encoding="utf-8"?>
<extension type="plugin" version="1.6" method="upgrade" group="content">
<name>Content - mainplugin</name>
<creationDate>2013-08-07</creationDate>
<version>1</version>
<releaseDate>2013-08-07 22:00:21</releaseDate>
<releaseType>First public release!</releaseType>
<author>Michael Baas</author>
<authorEmail>mb@mbaas.de</authorEmail>
<authorUrl>mbaas.de</authorUrl>
<copyright>(c) 2005-2013 Michael Baas</copyright>
<description>Testing the plugins-for-plugins-concept</description>
<license>free free free</license>
<files>
<filename plugin="mainplugin">mainplugin.php</filename>
</files>
<config />
</extension>
Here is a plugin for mainplugin of type mainplugin_plugin and it is called mainplugin_plugin.php:
<?php
class plgContentMainplugin_plugin extends plgContentMainplugin // or should it be JPlugin? Tried both, nothing worked.
{
function onmainiscalling($data) {
$r="Mainplugin_plugin->onmainiscalling was called";
return $r;
}
}
?>
and its installer (mainplugin_plugin.xml):
<?xml version="1.0" encoding="utf-8"?>
<extension type="plugin" version="1.6" method="upgrade" group="mainplugin_plugin">
<name>Content - mainplugin_plugin</name>
<creationDate>2013-08-07</creationDate>
<version>1</version>
<releaseDate>2013-08-07 22:00:21</releaseDate>
<releaseType>First public release!</releaseType>
<author>Michael Baas</author>
<authorEmail>mb@mbaas.de</authorEmail>
<authorUrl>mbaas.de</authorUrl>
<copyright>(c) 2005-2013 Michael Baas</copyright>
<description>Testing the plugins-for-plugins-concept</description>
<license>free free free</license>
<files>
<filename plugin="mainplugin_plugin">mainplugin_plugin.php</filename>
</files>
<config />
</extension>