Add “own controller” to com_users Admin Component

For Joomla! 4.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
Post Reply
Kimball31
Joomla! Apprentice
Joomla! Apprentice
Posts: 18
Joined: Fri Jan 27, 2012 6:24 pm

Add “own controller” to com_users Admin Component

Post by Kimball31 » Mon Mar 11, 2024 6:21 pm

I'm following "How to change Joomla without Core Hacks"
Part #6 "Component with “own controller”"
https://www.jug010.nl/images/presentati ... ehacks.pdf

But, When I use my overridden form, the original controller executes, not my "own" controller. How to I get Joomla to use my "own" controller?

Below is what I have developed so far.
I have also put full copies of the 3 files on github, if you want to see the code, here: https://github.com/Kimball31/MassMail

I used the Joomla Create Template Overrides tools to override the /com_users/mail component.
That created the new file: /atum/html/com_users/mail/default.php

I made copies the controller and model, as unique filenames for my "own" controller and model.
The new files for that are:
/administrator/components/com_users/src/Model/MailIndividualModel.php
/administrator/components/com_users/src/Controller/MailIndividualController.php

I then update the "task" in the default.php form, and modified the class names and some of the methods in my "own" controller and module.

changed default.php:

Code: Select all

//from: 
<input type="hidden" name="task" value="">

//to:
<input type="hidden" name="task" value="MailIndividual">
changed /src/Model/MailIndividualModel.php:

Code: Select all

//from:
class MailModel extends AdminModel

//to:
class MailIndividualModel extends AdminModel
Changed /src/Controller/MailIndividualController.php

Code: Select all

//from:
class MailController extends BaseController

//to:
class MailIndividualController extends BaseController
I'm still missing something. The form does not execute the MailIndividualController.

User avatar
pe7er
Joomla! Master
Joomla! Master
Posts: 25010
Joined: Thu Aug 18, 2005 8:55 pm
Location: Nijmegen, Netherlands
Contact:

Re: Add “own controller” to com_users Admin Component

Post by pe7er » Mon Mar 11, 2024 8:15 pm

That's a vintage presentation! :-)
I would not use that method, that I explained in my presentation 12 years ago, anymore.

Nowadays I would create a system plugin,
copy a core Joomla Model or Controller and put that copy in my system plugin,
make the necessary changes in that copy
and load that before Joomla does (so Joomla does use your copy and does not load its own).

Note that future improvements in the Joomla core Model or Controller won't be used.
But updating Joomla won't overwrite your changes.

Another solution is to use
Obix Class Extender https://extensions.joomla.org/extension ... -extender/
for your Model or Controller overrides.
Kind Regards,
Peter Martin, Global Moderator
Company website: https://db8.nl/en/ - Joomla specialist, Nijmegen, Netherlands
The best website: https://the-best-website.com

Kimball31
Joomla! Apprentice
Joomla! Apprentice
Posts: 18
Joined: Fri Jan 27, 2012 6:24 pm

Re: Add “own controller” to com_users Admin Component

Post by Kimball31 » Mon Mar 11, 2024 9:45 pm

Thanks Peter.

Are there any tutorials on building a System Plugin you can recommend, that might be similar to what I am doing?

Is a Plugin and System Plugin the same thing?

User avatar
pe7er
Joomla! Master
Joomla! Master
Posts: 25010
Joined: Thu Aug 18, 2005 8:55 pm
Location: Nijmegen, Netherlands
Contact:

Re: Add “own controller” to com_users Admin Component

Post by pe7er » Tue Mar 12, 2024 7:45 am

Plugin is the extension group, System Plugin is a type of plugins. Those system plugins are triggered with every page request.

There are other plugin groups as well that listen to different events which are triggered when rendering a page:
https://docs.joomla.org/Special:MyLangu ... gin/Events

A tutorial of how to create a Plugin for Joomla 4:
https://docs.joomla.org/J4.x:Creating_a ... for_Joomla

The Joomla's core plugins might also give you some ideas how to write and trigger your own plugins.
Kind Regards,
Peter Martin, Global Moderator
Company website: https://db8.nl/en/ - Joomla specialist, Nijmegen, Netherlands
The best website: https://the-best-website.com


Post Reply

Return to “Joomla! 4.x Coding”