When you try to create custom plugin with name like "plg_MyPlugin" - it doesn't work in Joomla 4
But if you create plugin plgMyPlugin - it works
Plugin name can have name started with plg_
Joomla! Version | 4.1.5
PHP Version | 8.0.18
Labels |
Added:
No Code Attached Yet
|
Title |
|
Labels |
Added:
Information Required
|
Can't confirm this issue. I created a test plugin here: https://github.com/GHSVS-de/plg_mybaseplugin
As long as the mandatory attributes type
and group
are configured correctly in the mandatory manifest XML the name
of the plugin can be whatever you want.
See https://github.com/GHSVS-de/plg_mybaseplugin/blob/main/mybaseplugin.xml#L2-L3
You can also use a custom group (= folder in /plugins/) if you want.
The demo plugin can be installed, activated, opened, saved and uninstalled without any issues:
https://github.com/GHSVS-de/plg_mybaseplugin/raw/main/plg_mybaseplugin.zip
Same here, also checked with capital letters. So please @ZhukDmitry specify what exactly does not work - error message? How did you install your plugin? you also can append your manifestfile here.
Difference between : plg_myBasePlugin and plg_MyPlugin
After the underscore = starts with a capital letter = don't know if relevant?
It works in J3, I just trying convert to support J4
Here my test plugin
-- manifest
<languages>
<language tag="en-GB">language/en-GB/en-GB.plg_content_plg_zhosmmap.ini</language>
</languages>
<!-- UPDATESERVER DEFINITION -->
<updateservers>
<!-- Note: No spaces or linebreaks allowed between the server tags -->
<server type="extension" priority="1" name="Zh OSM Map Plugin Update Site">http://zhuk.cc/update/plg_zhosmmap/extension.xml</server>
</updateservers>
--- plugin code
defined('_JEXEC') or die('Restricted access');
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Plugin\CMSPlugin;
class plgContentplg_zhosmmap extends CMSPlugin
{
protected $app;
public function onContentPrepare($context, &$article, &$params, $page = 0)
{
$article->text = "Hello";
}
}
My plugin name
filename plugin="plg_zhosmmap"
and plugin class
class plgContentplg_zhosmmap extends CMSPlugin
it is not processed
if I change name and files to any other (for example plgzhosmmap), - it works
Probably I must to name my plugin without plg_, but I did it like the other extensions like rules for j3 (component = com_, module = mod_, and so on)
Just look at how all the core plugins are named and structured.
I think (don't know for sure) it's this line that is the reason that plugin base file/classes don't work any longer if they start with plg_
or (which is a bit harsh) contain plg_
https://github.com/joomla/joomla-cms/blob/4.2-dev/libraries/src/Extension/ExtensionManagerTrait.php#L87
Later in the chain loadPluginFromFilesystem() can't find the plugin base file, better: can't find the class:
https://github.com/joomla/joomla-cms/blob/4.2-dev/libraries/src/Extension/ExtensionManagerTrait.php#L192
That's new but expected from my point of view. Maybe the plugin lagacy mode works different??
Labels |
Added:
bug
|
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2023-02-27 12:39:01 |
Closed_By | ⇒ | richard67 |
Did that work in J3?
It surely works if you add the plugin group as in all other plugins: plg_content_nameoftheplugin.