Enable Easier Overrides of Core Components by Using JLoader

25 views
Skip to first unread message

Rafael Diaz-Tushman

unread,
Mar 13, 2010, 11:57:53 AM3/13/10
to joomla-...@googlegroups.com
Would there be any interest in making it easier to override core components?

Currently, the entry point files for core components use require_once to load the component's controller

For example: See line 12 of /components/com_users/users.php, which looks like:

require_once JPATH_COMPONENT.'/controller.php';


If instead we used something like:

if (!JLoader::load("UsersController")) { JLoader::register( "UsersController", JPATH_COMPONENT.'/controller.php' ); }

it would allow 3pd to override logic in core components without hacks or hackish workarounds.


I apologize if this has already been posted/requested in here and I missed it in my search.

Cheers.

--
Rafael Diaz-Tushman, President & CEO
Dioscouri Design: Form and Function
www.dioscouri.com
www.twitter.com/dioscouri

Hannes Papenberg

unread,
Mar 13, 2010, 2:45:38 PM3/13/10
to joomla-...@googlegroups.com
This is already implemented in trunk for quite some time. See
JController::getInstance().

Hannes

> www.dioscouri.com <http://www.dioscouri.com>
> www.twitter.com/dioscouri <http://www.twitter.com/dioscouri>
> --
> You received this message because you are subscribed to the Google
> Groups "Joomla! CMS Development" group.
> To post to this group, send an email to joomla-...@googlegroups.com.
> To unsubscribe from this group, send email to
> joomla-dev-cm...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/joomla-dev-cms?hl=en-GB.

Rafael Diaz-Tushman

unread,
Mar 13, 2010, 3:59:34 PM3/13/10
to joomla-...@googlegroups.com
Hannes, I think I may not have made myself clear enough.

Line 12 of /components/com_users/users.php causes PHP to blow up if you have already included a file that defines UsersController.

If I were to write a system plugin that (when com_users is accessed) loads a customized version of the UsersController class, line 12 of /components/com_users/users.php causes PHP to blow up.

Have you tried this?  Do you see what I am seeing?

--
Rafael Diaz-Tushman, President & CEO
Dioscouri Design: Form and Function
www.dioscouri.com

Sam Moffatt

unread,
Mar 13, 2010, 10:23:30 PM3/13/10
to joomla-...@googlegroups.com
What happens if you comment that line out and then add a
jimport('joomla.application.component.controller') in its place?

As Hannes said, we should already have it. Individual components might
need fixes to bring them up to scratch but it should be working
already with some tweaks. Check out
/libraries/joomla/application/component/controller.php

Sam Moffatt
http://pasamio.id.au

Hannes Papenberg

unread,
Mar 14, 2010, 5:32:08 AM3/14/10
to joomla-...@googlegroups.com
Please take a look at the code in trunk. It already uses the
JController::getInstance() in com_users in the current SVN version.

Hannes

Am 13.03.2010 21:59, schrieb Rafael Diaz-Tushman:
> Hannes, I think I may not have made myself clear enough.
>
> Line 12 of /components/com_users/users.php causes PHP to blow up if
> you have already included a file that defines UsersController.
>
> If I were to write a system plugin that (when com_users is accessed)
> loads a customized version of the UsersController class, line 12
> of /components/com_users/users.php causes PHP to blow up.
>
> Have you tried this? Do you see what I am seeing?
>
> --
> Rafael Diaz-Tushman, President & CEO
> Dioscouri Design: Form and Function

> <mailto:joomla-...@googlegroups.com>.


> > To unsubscribe from this group, send email to
> > joomla-dev-cm...@googlegroups.com

> <mailto:joomla-dev-cms%2Bunsu...@googlegroups.com>.


> > For more options, visit this group at
> > http://groups.google.com/group/joomla-dev-cms?hl=en-GB.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Joomla! CMS Development" group.
> To post to this group, send an email to
> joomla-...@googlegroups.com

> <mailto:joomla-...@googlegroups.com>.


> To unsubscribe from this group, send email to
> joomla-dev-cm...@googlegroups.com

> <mailto:joomla-dev-cms%2Bunsu...@googlegroups.com>.

Sam Moffatt

unread,
Mar 14, 2010, 6:12:42 AM3/14/10
to joomla-...@googlegroups.com
The issue is that the users.php file for the front end component
directly calls require_once to load the file instead of letting
JController::getInstance() do it. This appears to be due to a
dependence from all of the subcontrollers extending from
UsersControllerUser not from JController or similar. In the backend
parts of Comments, Content and Media have subcontrollers that extend
from a main controller or another subcontroller. Perhaps someone more
familiar with those components can say that this approach has been
taken and if it is still appropriate.

Sam Moffatt
http://pasamio.id.au

Rafael Diaz-Tushman

unread,
Mar 14, 2010, 12:42:48 PM3/14/10
to joomla-...@googlegroups.com
Yes, exactly, Sam.  That's what I pointed out in my first post in this thread, along with a potential solution that uses JLoader.  

Hannes, the use of JController::getInstance() in the trunk on Line 16 of /components/com_users/users.php
is something I'm aware of (my multiple references to Line 12 have all been references to the trunk).  However, the use of JController::getInstance() in the trunk on Line 16 of /components/com_users/users.php doesn't respond to or address the issue I've actually brought up, which is the potential conflict caused by the require_once on Line 12.  It doesn't feel like you're actually responding to the words I'm writing, but rather to some other question that nobody asked.

Cheers,
Rafael

--
Rafael Diaz-Tushman, President & CEO
Dioscouri Design: Form and Function
www.dioscouri.com

Hannes Papenberg

unread,
Mar 14, 2010, 5:06:06 PM3/14/10
to joomla-...@googlegroups.com
I did respond to your words/proposal, but you described something that
is already implemented in Joomla, which is why i might have not given
it the highest attention. Now i know that you are reporting a bug,
since the code in users.php is effectively broken. Hannes

>> >> joomla-dev-cm...@googlegroups.com<joomla-dev-cms%2Bunsu...@googlegroups.com>
>> >>
>> >> <mailto:joomla-dev-cms%2Bunsu...@googlegroups.com<joomla-dev-cms%252Buns...@googlegroups.com>


>> >.
>> >> > For more options, visit this group at
>> >> > http://groups.google.com/group/joomla-dev-cms?hl=en-GB.
>> >>
>> >> --
>> >> You received this message because you are subscribed to the Google
>> >> Groups "Joomla! CMS Development" group.
>> >> To post to this group, send an email to
>> >> joomla-...@googlegroups.com
>> >> <mailto:joomla-...@googlegroups.com>.
>> >> To unsubscribe from this group, send email to
>> >>

>> >> joomla-dev-cm...@googlegroups.com<joomla-dev-cms%2Bunsu...@googlegroups.com>
>> >>
>> >> <mailto:joomla-dev-cms%2Bunsu...@googlegroups.com<joomla-dev-cms%252Buns...@googlegroups.com>


>> >.
>> >> For more options, visit this group at
>> >> http://groups.google.com/group/joomla-dev-cms?hl=en-GB.
>> >>
>> >>
>> >> --
>> >> You received this message because you are subscribed to the Google
>> >> Groups "Joomla! CMS Development" group.
>> >> To post to this group, send an email to joomla-...@googlegroups.com

>> .
>> >> To unsubscribe from this group, send email to

>> >> joomla-dev-cm...@googlegroups.com<joomla-dev-cms%2Bunsu...@googlegroups.com>


>> .
>> >> For more options, visit this group at
>> >> http://groups.google.com/group/joomla-dev-cms?hl=en-GB.
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups
>> "Joomla! CMS Development" group.
>> > To post to this group, send an email to joomla-...@googlegroups.com.
>> > To unsubscribe from this group, send email to

>> joomla-dev-cm...@googlegroups.com<joomla-dev-cms%2Bunsu...@googlegroups.com>


>> .
>> > For more options, visit this group at
>> http://groups.google.com/group/joomla-dev-cms?hl=en-GB.
>> >
>> >
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Joomla! CMS Development" group.
>> To post to this group, send an email to joomla-...@googlegroups.com.
>> To unsubscribe from this group, send email to

>> joomla-dev-cm...@googlegroups.com<joomla-dev-cms%2Bunsu...@googlegroups.com>

Rafael Diaz-Tushman

unread,
Mar 14, 2010, 5:49:26 PM3/14/10
to joomla-...@googlegroups.com
Hannes,

If you look back at my initial post, I described a require_once JPATH_COMPONENT.'/controller.php';
that prevents many of the core components from actually being overridden.  So when you say I described something that is already implemented in Joomla, you're right!  The require_once is right there in the trunk!

The problem is not isolated to com_users, however, as you will see the same problem in many of the front-end entry point files (these are all references to the current trunk), so you may also want to look here:
  • Line 14 of /com_contact/contact.php
  • Lines 15 & 16 of /com_content/content.php 
  • Line 15 of /com_mailto/mailto.php
  • Lines 32 & 35 of /com_media/media.php
  • Lines 14 & 15 of /com_newsfeeds/newsfeeds.php
  • Line 14 of /com_search/search.php
  • Lines 13 & 14 of /com_weblinks/weblinks.php
Since only 2 out of 10 of the front-end components are actually overridable in the trunk, it didn't seem like a bug so much as an architectural decision, so I framed my initial post as a feature request rather than a bug report.

Cheers.
--
Rafael Diaz-Tushman, President & CEO
Dioscouri Design: Form and Function
www.dioscouri.com

Hannes Papenberg

unread,
Mar 14, 2010, 6:36:10 PM3/14/10
to joomla-...@googlegroups.com
Create a patch that removes the require once (remember that
jcontroller allready does the include if necessary) and i'll be happy
to put it into trunk.


On 3/14/10, Rafael Diaz-Tushman <rdiazt...@dioscouri.com> wrote:
> Hannes,
>
> If you look back at my initial post, I described a require_once
> JPATH_COMPONENT.'/controller.php';
> that prevents many of the core components from actually being
> overridden. So when you say I described something that is already
> implemented in Joomla, you're right! The require_once is right there in the
> trunk!
>
> The problem is not isolated to com_users, however, as you will see the same
> problem in many of the front-end entry point files (these are all references
> to the current trunk), so you may also want to look here:
>

> - Line 14 of /com_contact/contact.php
> - Lines 15 & 16 of /com_content/content.php
> - Line 15 of /com_mailto/mailto.php
> - Lines 32 & 35 of /com_media/media.php
> - Lines 14 & 15 of /com_newsfeeds/newsfeeds.php
> - Line 14 of /com_search/search.php
> - Lines 13 & 14 of /com_weblinks/weblinks.php

>> <joomla-dev-cms%2Bunsu...@googlegroups.com<joomla-dev-cms%252Buns...@googlegroups.com>
>> >
>> >> >>
>> >> >> <mailto:joomla-dev-cms%2Bunsu...@googlegroups.com<joomla-dev-cms%252Buns...@googlegroups.com>
>> <joomla-dev-cms%252Buns...@googlegroups.com<joomla-dev-cms%25252Bun...@googlegroups.com>


>> >
>> >> >.
>> >> >> > For more options, visit this group at
>> >> >> > http://groups.google.com/group/joomla-dev-cms?hl=en-GB.
>> >> >>
>> >> >> --
>> >> >> You received this message because you are subscribed to the
>> Google
>> >> >> Groups "Joomla! CMS Development" group.
>> >> >> To post to this group, send an email to
>> >> >> joomla-...@googlegroups.com
>> >> >> <mailto:joomla-...@googlegroups.com>.
>> >> >> To unsubscribe from this group, send email to
>> >> >>
>> >> >> joomla-dev-cm...@googlegroups.com<joomla-dev-cms%2Bunsu...@googlegroups.com>

>> <joomla-dev-cms%2Bunsu...@googlegroups.com<joomla-dev-cms%252Buns...@googlegroups.com>
>> >
>> >> >>
>> >> >> <mailto:joomla-dev-cms%2Bunsu...@googlegroups.com<joomla-dev-cms%252Buns...@googlegroups.com>
>> <joomla-dev-cms%252Buns...@googlegroups.com<joomla-dev-cms%25252Bun...@googlegroups.com>


>> >
>> >> >.
>> >> >> For more options, visit this group at
>> >> >> http://groups.google.com/group/joomla-dev-cms?hl=en-GB.
>> >> >>
>> >> >>
>> >> >> --
>> >> >> You received this message because you are subscribed to the Google
>> >> >> Groups "Joomla! CMS Development" group.
>> >> >> To post to this group, send an email to
>> joomla-...@googlegroups.com
>> >> .
>> >> >> To unsubscribe from this group, send email to
>> >> >> joomla-dev-cm...@googlegroups.com<joomla-dev-cms%2Bunsu...@googlegroups.com>

>> <joomla-dev-cms%2Bunsu...@googlegroups.com<joomla-dev-cms%252Buns...@googlegroups.com>
>> >
>> >> .
>> >> >> For more options, visit this group at
>> >> >> http://groups.google.com/group/joomla-dev-cms?hl=en-GB.
>> >> >
>> >> > --
>> >> > You received this message because you are subscribed to the Google
>> >> > Groups
>> >> "Joomla! CMS Development" group.
>> >> > To post to this group, send an email to

>> <joomla-dev-cms%2Bunsu...@googlegroups.com<joomla-dev-cms%252Buns...@googlegroups.com>
>> >
>> >> .
>> >> > For more options, visit this group at
>> >> http://groups.google.com/group/joomla-dev-cms?hl=en-GB.
>> >> >
>> >> >
>> >>
>> >> --
>> >> You received this message because you are subscribed to the Google
>> Groups
>> >> "Joomla! CMS Development" group.
>> >> To post to this group, send an email to joomla-...@googlegroups.com
>> .
>> >> To unsubscribe from this group, send email to
>> >> joomla-dev-cm...@googlegroups.com<joomla-dev-cms%2Bunsu...@googlegroups.com>

>> <joomla-dev-cms%2Bunsu...@googlegroups.com<joomla-dev-cms%252Buns...@googlegroups.com>
>> >
>> >> .
>> >> For more options, visit this group at
>> >> http://groups.google.com/group/joomla-dev-cms?hl=en-GB.
>> >>
>> >>
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups
>> > "Joomla! CMS Development" group.

Sam Moffatt

unread,
Mar 15, 2010, 1:43:32 AM3/15/10
to joomla-dev-cms
As I noted, merely removing the line will actually break the user
component because of the dependence on the file being included by the
subcontrollers - as is the case in the extensions that I listed in my
previous email. Not all extensions will break and you will also need
to ensure that you include a
"jimport('joomla.application.component.controller');" line as well to
get jcontroller included into scope if such a line isn't there
already.


Sam Moffatt
http://pasamio.id.au

Rafael Diaz-Tushman

unread,
Mar 16, 2010, 9:16:17 AM3/16/10
to joomla-...@googlegroups.com
Hey guys, sorry for the delay - this email got lost in my Monday flood of emails...

Thanks for the offer to submit a patch for the trunk, but I would be more comfortable remaining in the role of Reporter for the Joomla project. 

In my first email in this thread, I listed a potential change that could resolve the issue in each of the files mentioned in my most recent email.  This would resolve the issue for at least the front-end of each of the components.  If someone with the time or commit access would like to do the rest (including admin-side controllers), that would be great.

Cheers!
--
Rafael Diaz-Tushman, President & CEO
Dioscouri Design: Form and Function
www.dioscouri.com
www.twitter.com/dioscouri


Reply all
Reply to author
Forward
0 new messages