?
avatar wilsonge
wilsonge
24 Aug 2017

There's many places in the system using JTable::getInstance to get component table objects, that have broken since namespacing. Especially of importance is the multilanguage install in Joomla 3.x - but there several other places. Not sure what the best way to solve this is - the MVC Helper???

avatar wilsonge wilsonge - open - 24 Aug 2017
avatar joomla-cms-bot joomla-cms-bot - change - 24 Aug 2017
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - labeled - 24 Aug 2017
avatar wilsonge
wilsonge - comment - 24 Aug 2017

I believe @laoneo is going to work on this next week :)

avatar franz-wohlkoenig franz-wohlkoenig - change - 24 Aug 2017
Category Code style
avatar laoneo
laoneo - comment - 28 Aug 2017

To make all the legacy code JTable::getInstance work again in 4, the extension classmap needs to be extended with all core tables as we already did in #16435 here https://github.com/joomla/joomla-cms/blame/4.0-dev/libraries/extensions.classmap.php#L16.

By the way we have the same issue with models JModelLegacy::getInstance does also not work anymore.

avatar franz-wohlkoenig franz-wohlkoenig - change - 1 Sep 2017
Status New Discussion
avatar laoneo
laoneo - comment - 27 Nov 2017

A quick update on this issue here. It all comes down to the question to what degree we want to make it possible to let the model and table objects instanciation being overrideable. At the moment the getInstance calls of JModelLegacy::getInstance has been replaced by direct creating the object, for example here https://github.com/joomla/joomla-cms/blob/4.0-dev/administrator/modules/mod_latest/mod_latest.php#L15. If we want to go more the service way, then it needs a bigger rewrite of the MVCFactory.

avatar mbabker
mbabker - comment - 27 Nov 2017

We shouldn't be direct instantiating anything in the MVC layer except for inside factories. The current getInstance() methods allow a semi-clean way to overload component classes and the direct instantiation method basically means that the only way to accomplish it is with autoloader manipulation. As much as I disagree with the concept of class overloading, I do agree with being able to override the logic to load objects (I'd rather people be able to subclass things and put their customizations in place versus encouraging core classes to be overloaded since at that point you can't rely on the API being stable and that's where you get the bug reports about missing methods in core classes after an upgrade) so we should try our hardest to make use of the factories and only go to a direct instantiation model if we can't make it work.

avatar laoneo
laoneo - comment - 28 Nov 2017

Lets take the example of the sample data blog plugin which needs models from different extensions. To properly fix it, I see two possible ways:

  1. A global factory which creates the MVCFactories:
$container->get(MVCFactoryFactoryInterface::class)->createFactory('Joomla\\Component\\Content')->createModel('Articles', 'Administrator');
$container->get(MVCFactoryFactoryInterface::class)->createFactory('Joomla\\Component\\Categories\')->createModel('Category', 'Administrator');
  1. Extend the MVC factory that it can load models, views and tables from different extensions, by passing the full class name (the MVCFactory should get properly injected or loaded from the container on some point):
$factory = new MVCFactory('', $app);
$factory->createModel(ArticlesModel::class);
$factory->createModel(CategoryModel::class);
avatar laoneo
laoneo - comment - 12 Feb 2018

Decision with @mbabker, @wilsonge and @laoneo:
We go with $container->get(MVCFactoryFactoryInterface::class)->createFactory('com_content')->createModel('Articles', 'Administrator');.

avatar laoneo
laoneo - comment - 5 Mar 2018

Guess we can close this one as we have a pr #19835.

avatar joomla-cms-bot joomla-cms-bot - change - 5 Mar 2018
Closed_Date 2018-03-05 11:02:27 2018-03-05 11:02:28
Closed_By franz-wohlkoenig joomla-cms-bot
avatar joomla-cms-bot joomla-cms-bot - close - 5 Mar 2018
avatar franz-wohlkoenig franz-wohlkoenig - change - 5 Mar 2018
Status Discussion Closed
Closed_Date 0000-00-00 00:00:00 2018-03-05 11:02:27
Closed_By franz-wohlkoenig
avatar joomla-cms-bot
joomla-cms-bot - comment - 5 Mar 2018
avatar franz-wohlkoenig
franz-wohlkoenig - comment - 5 Mar 2018

closed as having Pull Request #19835

Add a Comment

Login with GitHub to post a comment