In Joomla 6 Alpha 2 these functions were removed:
public function getDispatcher()
protected function dispatchEvent(EventInterface $event)
from BaseDatabaseModel.php and from AbstractView.php
#45431
dispatchEvent function was marked as deprecated, everything OK here, but function getDispatcher() was not marked as deprecated - either in Joomla 5 nor in Joomla 6 Alpha 1
See IDE:
if some part depends on getDispatcher() from BaseDatabaseModel.php, it was removed.
Joomla 6 Alha 2
Example:
In J5 or J6Alpha1, if setDispatcher() is not set, it is automatically set in the BaseModel using the getDispatcher() function, which wasn't marked as deprecated.
To understand it correctly, setDispatcher() function should produce warning in Joomla 6 about deprecated using, but itself is not marked as deprecated.
The problem is, when the setDispatcher is not set, in Joomla 5 or Joomla 6 Alpha 1, it is set in BaseModel, in Joomla 6 Alpha 2 not more.
Labels |
Added:
No Code Attached Yet
|
As said a couple of times already getDispatcher() is just moved to a trait in the event package https://github.com/joomla-framework/event/blob/4.x-dev/src/DispatcherAwareTrait.php
I understand, but this cannot be considered as a ‘move’ because the two methods are significantly different. The one in trait does not set the dispatcher if it does not exist, the one in BaseDatabaseModel does.
Again, this is a technical issue where it may happen that Joomla 5 extensions working without problem on Joomla 5 and Joomla 6 Alpha 1 will no longer work with or without Backward compatibility plugin, so at least this should be somehow addressed in the plugin.
I'm not addressing an ideological question here, about what is correct, how to load a component correctly, etc., I'm addressing a technical question. The difference between Joomla 5 (Joomla 6 Alpha 1) and Joomla 6 Alpha 2.
It just happened in reality that thanks to BaseDatabaseModel, which took care of the dispatcher when it didn't exist, everything worked, now it doesn't care anymore.
So the question is why the trait doesn't set the dispatcher if it doesn't exist. If the core component doesn't need it, nothing happens, this code is not executed, if it does, the dispatcher is set.
Same issue happened to one extension of mine, using:
$this->preprocessData ( 'com_mycomponent.page', $data );
Fatal error as dispatcher is not set, this should not happen.
The question is whether this is intentional or a bug.
There are often requirements for extension developers to test development versions and report problems. I did this and reported the problem, unfortunately it was not or did not want to be understood.
So, if it is:
a) a bug - it should be fixed in the next version (however, there it is necessary for core developers to remember that Joomla extensions exist)
b) if this is intentional, then the component needs to load its own dispatcher in the model, e.g. via a trait
public function getDispatcher()
{
if (!$this->dispatcher) {
return Factory::getContainer()->get(DispatcherInterface::class);
}
return $this->dispatcher;
}
or use the newest boot.
If those three lines remained part of Joomla core, I think it would not hurt the core, but on the other hand it would save many extensions.
To avoid misunderstandings and aggravation of the discussion, this is not about me and my situation, I load the dispatcher in my own extensions, this is about the possible salvation of many other extensions and serve Joomla end users well.
Similar situation is with:
// File
public static function exists($file)
{
return is_file(Path::clean($file));
}
// Folder
public static function exists($path)
{
return is_dir(Path::clean($path));
}
for File and Folder classes. I understand that it can be written cleanly in PHP, even if we have Path::clean here, but by removing a few lines from the core, the Joomla project will lose a lot of extensions. Low-cost, miniature gestures of friendliness towards older extensions wouldn't hurt.
It is intentional, it is what @HLeithner already wrote #45682 (comment)
The removed code #45431 were added back in 4.4 for legacy compatibility #41371
The idea that MVC factory should set the dispatcher (see Harald's comment).
I do not remember what the state about the legacy components in Joomla 6, if they still should working then probably the changes should be reverted, and deprecation extended to 7. or 8.
Labels |
Added:
bug
|
I set it as bug for now
Not really at the moment, I either have old ones that don't work in J6 at all or new ones, but with their own dispatcher loading, or completely new ones that use boot. This is not the case with the latter, it's with extensions that don't use boot, but also don't use legacy methods.
In my extension i've noticed that the issue happens in particular whenever a model calls
->loadFormData
->preprocessForm
->preprocessData
that are methods dealing and requiring the dispatcher object
It can be tested when you call a model from outside, for example:
use Joomla\Component\Content\Administrator\Model\ArticleModel;
...
$articleModel = new ArticleModel();
$ids = [1,2,3];
$articleModel->delete($ids);
will produce:
An error occurred during article deletion: Dispatcher not set in Joomla\CMS\MVC\Model\BaseDatabaseModel
I think the PR need to be reverted,
And kept until we support Components that works without MVC factory.
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2025-08-03 08:35:12 |
Closed_By | ⇒ | Fedik |
As already discussed on mattermost.
Your implementation of MVCFactory doesn't execute
$model->setDispatcher();
when creating the model.joomla-cms/libraries/src/MVC/Factory/MVCFactory.php
Line 164 in 8868adc
This has been deprecated in Joomla 4.4 while adding it as b/c code in #41371
In this line we throw a deprecation notice which says if you continue to use the code as you are an exception will be thrown starting with joomla 6 which is the case now.
joomla-cms/libraries/src/MVC/Controller/BaseController.php
Line 1101 in 8849898