No Code Attached Yet
avatar aberenguer78
aberenguer78
4 Nov 2024

Steps to reproduce the issue

Use Joomla 5.2 with PHP 8.2
Only Fix the actual result error.

Expected result

No error

Actual result

Error 0:
Joomla\Plugin\System\Schemaorg\Extension\Schemaorg::onContentPrepareData(): Argument #1 ($event) must be of type Joomla\CMS\Event\Model\PrepareDataEvent, Joomla\Event\Event given, called in C:\xamppPHP8.2\htdocs\joomla5\libraries\vendor\joomla\event\src\Dispatcher.php on line 454

System information (as much as possible)

The error happens with Joomla 5.2 and PHP 8.2 but it seems an error in the core classes not related to a PHP version.

Additional comments

Please fix it as soon as possible

avatar aberenguer78 aberenguer78 - open - 4 Nov 2024
avatar joomla-cms-bot joomla-cms-bot - change - 4 Nov 2024
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 4 Nov 2024
avatar aberenguer78
aberenguer78 - comment - 4 Nov 2024

Solution: Check and Update the Event Class in the Method Signature
In Joomla 4 and later, many events are now represented by specific classes rather than the generic Joomla\Event\Event class. If you are writing or maintaining a custom plugin, you need to make sure that your event-handling method uses the correct event type in its signature.

Locate the onContentPrepareData Method in your Schemaorg plugin (Joomla\Plugin\System\Schemaorg\Extension\Schemaorg).

Update the Method Signature to Accept Joomla\CMS\Event\Model\PrepareDataEvent.

The signature should look something like this:

php
Copiar código
use Joomla\CMS\Event\Model\PrepareDataEvent; // Make sure to import the correct namespace

public function onContentPrepareData(PrepareDataEvent $event)
{
// Your code to handle the event
}

avatar Hackwar
Hackwar - comment - 4 Nov 2024

The Joomla code for these events is actually backwards compatible to legacy plugins. This rather points to some legacy third party extension which calls events in the wrong way. The Joomla core is very much compatible with all its own event calls.

avatar aberenguer78
aberenguer78 - comment - 4 Nov 2024

I can understand what you say but please be strict with the error, this message it's clear. The method is expecting another class as parameter PrepareDataEvent instead of Event.. I can search my own errors and try to find solutions if I call wrongly to the event but the message is clear and is not refering to that point.. I posted the possible solution, I think it's easy and can fix this issue.

avatar Hackwar Hackwar - change - 4 Nov 2024
Status New Closed
Closed_Date 0000-00-00 00:00:00 2024-11-04 15:34:17
Closed_By Hackwar
avatar Hackwar Hackwar - close - 4 Nov 2024
avatar Hackwar
Hackwar - comment - 4 Nov 2024

And I wrote to you, that the core code is fine in this regard. Something else is triggering the event and handing in the wrong event object or an update of your site failed. As you can see here, the code is correct: https://github.com/joomla/joomla-cms/blob/5.2-dev/plugins/system/schemaorg/src/Extension/Schemaorg.php#L76 and it has been like this since Joomla 5.0. Since this is not a bug in Joomla, I'm closing this issue.

avatar aberenguer78
aberenguer78 - comment - 4 Nov 2024

You are right I think I have found the error instead of Event i should use PrepareDataEvent.
I have this code:
PluginHelper::importPlugin('user');
$event = new Event('onContentPrepareData', array('com_users.profile', $this->data));
// Trigger the data preparation event.
$results = $dispatcher->dispatch('onContentPrepareData', $event);

I will try it tomorrow to see if I can fix debugging with visual studio code..
thanks

avatar aberenguer78
aberenguer78 - comment - 5 Nov 2024

I solved changing the previous code by this:
add in uses list:
use Joomla\CMS\Event\Model\PrepareDataEvent;

the new code to call the PrepareDataEvent;
$dispatcher = Factory::getApplication()->getDispatcher();

$event = new PrepareDataEvent('onContentPrepareData', [
'context' => 'com_users.profile',
'data' => $this->data,
'subject' => ''
]);

$results = $dispatcher->dispatch('onContentPrepareData', $event);

Add a Comment

Login with GitHub to post a comment