User tests: Successful: Unsuccessful:
Pull Request for Issue #38555 .
setMVCFactory
and getMVCFactory
public methods to the BaseController\Joomla\CMS\MVC\Factory\MVCFactoryWrapper
class for wrapping the MVCFactory service to extend it.Without the patch: Install the component https://github.com/nikosdion/com_example/commit/06f43fde850b79673500697e41c4945602fa34152.
With the patch: Install the component https://github.com/nikosdion/com_example/commit/4413a9a399e0634cc7d37967188210a8185cc35d
You get an error.
That's because the custom MVCFactoryWrapper of the component cannot force itself as the MVCFactory service of the Controller. As a result, when the Controller calls its getModel
or getView
methods it uses the undecorated MVCFactory object which, of course, is blissfully unaware of our custom service. Therefore the Model which wants to use this service breaks.
It works!
Our custom MVCFactoryWrapper extends from \Joomla\CMS\MVC\Factory\MVCFactoryWrapper
which means that the created Controller and Model objects use our decorated wrapper as their MVCFactory instead of the undecorated service. Our decorated wrapper is aware of our custom service, therefore it can push it to the created models, even if they are created through the Controller's createModel
method.
I will be documenting that in the developer's docs as there is currently nothing of the sort.
Status | New | ⇒ | Pending |
Category | ⇒ | Libraries |
Labels |
Added:
?
|
The core components are one trick ponies. That's why it being practically impossible (unless you forked a big ol' chunk of code) to push custom services to models was not caught until I started writing documentation.
That's why I insist on writing documentation for the code I write. Trying to teach someone else how what I wrote works usually leads to identifying problems I couldn't think of when I was focused on the code in front of me. The guys writing Rector said pretty much the same. When they started writing the book on Rector they figured out problems they had never thought of and updated Rector.
Status | Pending | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2022-12-07 12:24:44 |
Closed_By | ⇒ | nikosdion |
Status | Closed | ⇒ | New |
Closed_Date | 2022-12-07 12:24:44 | ⇒ | |
Closed_By | nikosdion | ⇒ |
Status | New | ⇒ | Pending |
I am not going to be contributing to this project anymore. I won't be replying to any questions or making any changes until then. I will close any outstanding PRs and delete their code on December 31st, 2022. Merge whatever you want until then.
I tried to fix an obvious architectural issue, nobody cared. Oh, well, you can't say I didn't try. I'm closing this PR.
Status | Pending | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2023-03-05 17:26:57 |
Closed_By | ⇒ | nikosdion |
Would be good to find an usage for this pr in the core, that extension devs would see how this can actually be used. But I couldn't find one.