-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[5.x][6.x] Missing CurrentUser if model is created with MVCFactory #45700
Copy link
Copy link
Open
Labels
Description
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.
joomla-cms/libraries/src/MVC/Controller/BaseController.php
Lines 580 to 582 in 8868adc
| if ($model instanceof CurrentUserInterface && $this->app->getIdentity()) { | |
| $model->setCurrentUser($this->app->getIdentity()); | |
| } |
joomla-cms/libraries/src/MVC/Controller/BaseController.php
Lines 611 to 613 in 8868adc
| if ($view instanceof CurrentUserInterface && $this->app->getIdentity()) { | |
| $view->setCurrentUser($this->app->getIdentity()); | |
| } |
if you disabled this deprecated code
joomla-cms/libraries/src/User/CurrentUserTrait.php
Lines 43 to 49 in 8868adc
| 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
Reactions are currently unavailable