No Code Attached Yet
avatar heelc29
heelc29
7 Jul 2025

Steps to reproduce the issue

If a Model, View, Table with the MVCFactory not all (required) options are injected to the objects eg. CurrentUserInterface because its injected by BaseController and not by the factory itself.

if ($model instanceof CurrentUserInterface && $this->app->getIdentity()) {
$model->setCurrentUser($this->app->getIdentity());
}

if ($view instanceof CurrentUserInterface && $this->app->getIdentity()) {
$view->setCurrentUser($this->app->getIdentity());
}

if you disabled this deprecated code

if (!$this->currentUser) {
@trigger_error(
\sprintf('User must be set in %s. This will not be caught anymore in 6.0', __METHOD__),
E_USER_DEPRECATED
);
$this->currentUser = Factory::getApplication()->getIdentity() ?: Factory::getUser();
}

Expected result

no additional injects necessary if model/view/table etc. is created with MVCFactory

Actual result

you get problems with this code

$articles = $factory->createModel('Articles', 'Site', ['ignore_request' => true]);

$items = $articles->getItems();

ping @laoneo

avatar heelc29 heelc29 - open - 7 Jul 2025
avatar joomla-cms-bot joomla-cms-bot - change - 7 Jul 2025
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 7 Jul 2025
avatar laoneo
laoneo - comment - 7 Jul 2025

The MVCFactory per se is not created in a context where a user is available. So where should this user come from?

avatar heelc29
heelc29 - comment - 7 Jul 2025

The MVCFactory per se is not created in a context where a user is available. So where should this user come from?

I have no idea, that's why I asked for advice. This means that every time you boot a different model in a plugin/module etc. you would have to inject the user separately - this will be a few places and the 3rd party developers will not be happy about it either.

That's how I've always understood it so far: If the model/view/table is created via the MVCFactory, you are on the safe side.

avatar HLeithner
HLeithner - comment - 7 Jul 2025

The MVC doens't know the current User context, only the calling code knows what's the current user is. It would be more intuitive to provide a container with everything the model might need in the current context but that's not the design here...

avatar laoneo
laoneo - comment - 7 Jul 2025

This is what dependency injection is about. You need a context where it is running in

avatar HLeithner
HLeithner - comment - 8 Jul 2025

MVCFactory doesn't allow you to provide a container...

Add a Comment

Login with GitHub to post a comment