Skip to content

[5.x][6.x] Missing CurrentUser if model is created with MVCFactory #45700

@heelc29

Description

@heelc29

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions