No Code Attached Yet bug
avatar PhocaCz
PhocaCz
3 Jul 2025

Steps to reproduce the issue

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:

Image

Actual result

if some part depends on getDispatcher() from BaseDatabaseModel.php, it was removed.

System information (as much as possible)

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.

avatar PhocaCz PhocaCz - open - 3 Jul 2025
avatar joomla-cms-bot joomla-cms-bot - change - 3 Jul 2025
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 3 Jul 2025
avatar PhocaCz PhocaCz - change - 3 Jul 2025
The description was changed
avatar PhocaCz PhocaCz - edited - 3 Jul 2025
avatar PhocaCz PhocaCz - change - 3 Jul 2025
The description was changed
avatar PhocaCz PhocaCz - edited - 3 Jul 2025
avatar PhocaCz PhocaCz - change - 3 Jul 2025
The description was changed
avatar PhocaCz PhocaCz - edited - 3 Jul 2025
avatar PhocaCz PhocaCz - change - 3 Jul 2025
The description was changed
avatar PhocaCz PhocaCz - edited - 3 Jul 2025
avatar HLeithner
HLeithner - comment - 3 Jul 2025

As already discussed on mattermost.

Your implementation of MVCFactory doesn't execute $model->setDispatcher(); when creating the model.

$this->setDispatcherOnObject($model);

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.

sprintf('Dispatcher for %s should be set through MVC factory. It will throw an exception in 6.0', __CLASS__),

avatar rdeutz
rdeutz - comment - 3 Jul 2025

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

avatar PhocaCz
PhocaCz - comment - 3 Jul 2025

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.

avatar joeforjoomla
joeforjoomla - comment - 19 Jul 2025

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.

avatar PhocaCz
PhocaCz - comment - 19 Jul 2025

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.

avatar Fedik
Fedik - comment - 19 Jul 2025

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.

avatar Fedik Fedik - change - 19 Jul 2025
Labels Added: bug
avatar Fedik Fedik - labeled - 19 Jul 2025
avatar Fedik
Fedik - comment - 19 Jul 2025

I set it as bug for now

avatar PhocaCz
PhocaCz - comment - 19 Jul 2025

@Fedik thank you for the info.

avatar HLeithner
HLeithner - comment - 19 Jul 2025

@PhocaCz Do you have an example component please?

avatar PhocaCz
PhocaCz - comment - 19 Jul 2025

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.

avatar joeforjoomla
joeforjoomla - comment - 20 Jul 2025

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

avatar PhocaCz
PhocaCz - comment - 20 Jul 2025

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

avatar Fedik
Fedik - comment - 2 Aug 2025

I think the PR need to be reverted,
And kept until we support Components that works without MVC factory.

avatar Fedik Fedik - change - 3 Aug 2025
Status New Closed
Closed_Date 0000-00-00 00:00:00 2025-08-03 08:35:12
Closed_By Fedik
avatar Fedik Fedik - close - 3 Aug 2025
avatar Fedik
Fedik - comment - 3 Aug 2025

There is a PR #45823 please test

Add a Comment

Login with GitHub to post a comment