0

As a sort of newbie developer with php/Joomla, I created a content plugin for Joomla 3 which pretty much did what I wanted and expected...

I then decided to migrate it to Joomla 4 following the very few examples that I could google here and there and nothing works. In fact, the plugin doesn't even seem to load.

So, I decided to get back to a very simple sort of helloworld type thing test and even this test doesn't do anything. I should add that install and activation work and no error message is ever displayed when setting to Maximum.

Here's the very simple thing I tried:

<?php
defined('_JEXEC') or die; 
use Joomla\CMS\Plugin\CMSPlugin; 
class PlgContentTest extends CMSPlugin 
{ 
    public function onContentPrepare($context, &$article, &$params, $page = 0) 
    { 
        if ($context !== 'com_content.article') 
        { 
            echo 'Wrong!'; 
            return; 
        } 
        echo 'Here!'; 
    }
}
?>

I cannot figure out what I've done wrong here, except maybe something about file naming?

My xml:

<?xml version="1.0" encoding="utf-8"?>
<extension type="plugin" version="4.0" method="upgrade" group="content">
<name>Test</name>
<author></author>
<creationDate>January 2022</creationDate>
<copyright>Copyright (C) 2022+ . All rights reserved.</copyright>
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
<version>1.5</version>
<description>PLG_CONTENT_TEST_DESCRIPTION</description>
<files>
<filename plugin="Test">Test.php</filename>
<filename>index.html</filename>
</files>
<languages folder="administrator/language">
<language tag="en-GB">language/en-GB/en-GB.plg_content_Test.ini</language>
<language tag="en-GB">language/en-GB/en-GB.plg_content_Test.sys.ini</language>
<language tag="fr-FR">language/fr-FR/fr-FR.plg_content_Test.ini</language>
<language tag="fr-FR">language/fr-FR/fr-FR.plg_content_Test.sys.ini</language>
<languages>
</extension>
1
  • Welcome to JSE, Phil. Please take our tour. Commented Mar 4, 2022 at 22:49

1 Answer 1

1

Why do you use a capital in your filename? It's something you questioned yourself already.

Could you rename the file from Test.php to test.php?

And change

<filename plugin="Test">Test.php</filename>

to

<filename plugin="test">test.php</filename>

And do the same with language files.

btw: not related to your issue, but two thing to make it a bit easier:

  1. you don't need to add the language in the file name:
language/en-GB/en-GB.plg_content_test.ini

can become

language/en-GB/plg_content_test.ini

and you can make it yourself easier: add

<folder>language</folder>

and remove the whole <languages folder="administrator/language"> [..] <languages> part

edit: Could you try changing your xml manifest to:

<?xml version="1.0" encoding="utf-8"?>
<extension version="4.0" type="plugin" group="content" method="upgrade">

    <name>plg_content_test</name>
    
    <files>
        <filename plugin="test">test.php</filename>
        <folder>language</folder>
    </files>

</extension>

and create a /language/en-GB/ in your plugin folder with files:

  • plg_content_test.ini
  • plg_content_test.sys.ini
3
  • Well, I obviously tried what you recommend but there's absolutely no change whatsoever...Thanks for the other suggestions by the way.
    – Phil91
    Commented Mar 5, 2022 at 13:29
  • I've added an XML manifest file. Could you test if those settings work for you?
    – pe7er
    Commented Mar 5, 2022 at 14:00
  • Hello @pe7er, sorry but I was out for a while. Yes, with this change it now seems to be working. Thanks for helping out on this. Will try to keep it in mind...Cheers. Philippe
    – Phil91
    Commented Mar 14, 2022 at 11:57

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.