Override core ManageModel from com_installer J!4

130 views
Skip to first unread message

UWiX

unread,
Apr 2, 2019, 7:23:10 AM4/2/19
to Joomla! CMS Development
I cannot seem to figure out how to override a Model in J!4 - so I hope someone can help me out, here.

What I want to do is log the "publish" state for an Extension which can be toggled in the Extension Manager.
In J!3 this can be done using a system plugin and add the following code to the onAfterRoute() function:

JLoader::register('InstallerModelManage', JPATH_PLUGINS . '/system/myplugin/overrides/manage.php');

That manage.php file is an exact copy of the manage.php model from the com_installer directory in J!3. It only has a trigger added to it's publish() function. That works perfectly in J!3.

Now I want to accomplish the same for J!4 and did the same with the ManageModel.php file from the com_installer folder. But somehow the JLoader::register isn't enough:

JLoader::register('ManageModel', JPATH_PLUGINS . '/system/myplugin/overrides/ManageModel.php');

Above code should do the trick - that is in J!3 but not for J!4. I've already remarked the namespace for my override ManageModel.php file (I've read somewhere that is needed).
When I check the loaded ClassList using JLoader::getClassList() I see the override Model is loaded but it isn't used whatsoever.

At this moment I've tried everything from the require_once() to JLoader::import, JLoader::registerNamespace, etc. But nothing seems to load my override Model.

What am I missing here? Does anyone have a suggestion? Thanks!

Michael Babker

unread,
Apr 2, 2019, 8:23:11 AM4/2/19
to joomla-...@googlegroups.com
Depending on what the trigger is, why not just contribute the change to core?

When using JLoader::register(), you must pass the fully qualified class name as the first argument.  You aren't passing the namespace info in, that's why the autoloader won't pick up your class.  If you haven't already, I suggest taking a look at PHP's documentation for how namespaces work.

--
You received this message because you are subscribed to the Google Groups "Joomla! CMS Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-cm...@googlegroups.com.
To post to this group, send an email to joomla-...@googlegroups.com.
Visit this group at https://groups.google.com/group/joomla-dev-cms.
For more options, visit https://groups.google.com/d/optout.

UWiX

unread,
Apr 3, 2019, 4:28:36 AM4/3/19
to Joomla! CMS Development
Thank you for that quick response. I did a request for the trigger change but had no respons yeyt. If I can find some spare time I'll try to participate to the Joomla! project.

I've read up with the namespace documentation and read it once more to get the hang of it. Doesn't seem to be so difficult to understand but the Joomla! namespacing looks a bit different.I cannot wrap my head around it yet but for that I have to find some good documentation to read.
Do you hav an example for a JLoader::register() how it could be used correctly? Cannot find it in the Joomla! sources and it seems I'm staring blind for a good solution to solve this silly thing.

Thanks!

Op dinsdag 2 april 2019 14:23:11 UTC+2 schreef Michael Babker:
Depending on what the trigger is, why not just contribute the change to core?

When using JLoader::register(), you must pass the fully qualified class name as the first argument.  You aren't passing the namespace info in, that's why the autoloader won't pick up your class.  If you haven't already, I suggest taking a look at PHP's documentation for how namespaces work.

On Tue, Apr 2, 2019 at 6:23 AM UWiX <nva...@gmail.com> wrote:
I cannot seem to figure out how to override a Model in J!4 - so I hope someone can help me out, here.

What I want to do is log the "publish" state for an Extension which can be toggled in the Extension Manager.
In J!3 this can be done using a system plugin and add the following code to the onAfterRoute() function:

JLoader::register('InstallerModelManage', JPATH_PLUGINS . '/system/myplugin/overrides/manage.php');

That manage.php file is an exact copy of the manage.php model from the com_installer directory in J!3. It only has a trigger added to it's publish() function. That works perfectly in J!3.

Now I want to accomplish the same for J!4 and did the same with the ManageModel.php file from the com_installer folder. But somehow the JLoader::register isn't enough:

JLoader::register('ManageModel', JPATH_PLUGINS . '/system/myplugin/overrides/ManageModel.php');

Above code should do the trick - that is in J!3 but not for J!4. I've already remarked the namespace for my override ManageModel.php file (I've read somewhere that is needed).
When I check the loaded ClassList using JLoader::getClassList() I see the override Model is loaded but it isn't used whatsoever.

At this moment I've tried everything from the require_once() to JLoader::import, JLoader::registerNamespace, etc. But nothing seems to load my override Model.

What am I missing here? Does anyone have a suggestion? Thanks!

--
You received this message because you are subscribed to the Google Groups "Joomla! CMS Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-...@googlegroups.com.

Michael Babker

unread,
Apr 3, 2019, 8:15:00 AM4/3/19
to joomla-...@googlegroups.com
Any time you have to pass a class name as a string somewhere, it needs to be the fully qualified class name.  So you would call JLoader::register('Joomla\\Application\\AbstractApplication', '/path/to/file.php'); and not JLoader::register('AbstractApplication', '/path/to/file.php');.  That's how it works in PHP in general, there isn't any Joomla specific behavior around it.

To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-cm...@googlegroups.com.
To post to this group, send email to joomla-...@googlegroups.com.

UWiX

unread,
Apr 4, 2019, 3:47:59 AM4/4/19
to Joomla! CMS Development
Thank you Michael - I have got some training in namespacing to do. You've pointed me in the right direction so it's up to me to fix my JLoader issue :-)

Op woensdag 3 april 2019 14:15:00 UTC+2 schreef Michael Babker:
To post to this group, send email to joomla-...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages