Jordan Ramstad
Jordan Ramstad

Reputation: 179

Joomla com_user extending similar to com_categories and com_content

Ok this is just something I feel I should ask as I could not find any reference to this in any kind of documentation, and reading through the actual code to figure out the best way to accomplish this would take far longer then hope to spend.

When you enter the Article manager you have a navigation link to the Category manager and vice versa. I would like to do something similar with my component and the default User manager.

I already have a profile plugin to extend the users to suit my needs, but I would like the configuration of it seamless so adjusting the com_user component to integrate better with my component is what I am looking for.

So my question is with the com_content and com_categories they use the "extension" parameter. Is it possible to add similar functionality without a full core override of the com_users? If I do a full override there is a chance of some extensions not working due to reliance on the users.

I am willing to clarify if anything does not make sense, this question is more to see the extent you can "extend" Joomla without overrides.

UPDATE:

I have found a cool technique, not quite an answer though. You can override just the list controller/model/view in your component, and if you based it off of the current com_users component you can make it look like a direct integration. The only edits you need to do is making sure any routes to the users view instead pass to your component.

There is one issue with this however, when you add a new user or edit one, once you finish it will direct you to the main user manager. A system plugin may help with this but only if there is a reliable way to detect when the user was edited through your component, rather then the users manager.

Note: The problem with adding an override to the user view is that it has 5-6 other MVC components it relies on, so in the interest of making it easy to update with core com_users updates it is best to avoid that if at all possible.

Another thing needed is to make sure to find the language file for com_users and add all entries to your component.

I feel there may still be a better answer out there, but doing it this way does not impact the core much, and would be easy to update with updates to com_users.

I am opening a bounty on this, I feel of every question I ever asked this is one that will have the most benefit to the community. So here is a condensed version of the question.

What would be an easy way to integrate a core component into a custom component and have it route through that component seamlessly with the least edits to the core component.

Upvotes: 3

Views: 809

Answers (1)

Craig
Craig

Reputation: 9330

I'm not exactly clear on what you want but if you're talking about the toolbar submenu's like this in com_content:

com_content submenu

The example you give of Categories (i.e. com_categories) is specific support added where you can pass in a link to com_catgories with your extension identifier (the extension=com_mycomponent) and it will load the sidebar menu for your extension. This is so core categories can be shared amongst various components [see Add Categories].

You may already be aware of the following, but, if you want to know how to add a sidebar menu to your components manager view you can call JHtmlSidebar::addEntry($title, $link, $active);

Typically this is put in your extensions primary helper file in a function called addSubmenu($vName) (which is what & where com_categories will look for to display your toolbar sub-menu). Its called addSubmenu() because the sidebar morphed from being the toolbar submenu in previous versions of Joomla.

e.g. this is the addSubmenu() method in the ContentHelper class defined in administrator/com_content/helpers/content.php

/**
 * Configure the Linkbar.
 *
 * @param   string  $vName  The name of the active view.
 *
 * @return  void
 * @since   1.6
 */
public static function addSubmenu($vName)
{
    JHtmlSidebar::addEntry(
        JText::_('JGLOBAL_ARTICLES'),
        'index.php?option=com_content&view=articles',
        $vName == 'articles'
    );
    JHtmlSidebar::addEntry(
        JText::_('COM_CONTENT_SUBMENU_CATEGORIES'),
        'index.php?option=com_categories&extension=com_content',
        $vName == 'categories');
    JHtmlSidebar::addEntry(
        JText::_('COM_CONTENT_SUBMENU_FEATURED'),
        'index.php?option=com_content&view=featured',
        $vName == 'featured'
    );
}

By comparison the com_categories helper class CategoriesHelper has a very different addSubmenu() method which looks for the calling extensions core helper class (if one isn't found it defaults to com_content).

There isn't any support like that in com_users so you will probably have to create a system plugin that fires onAfterRoute and adds your submenu item based whether or not your component has provided a suitable parameter, like the extension=com_myextension. It would be a bit of a swizzle but it should work — the only thing is as you would be adding a submenu item before the component is dispatched your new submenu item would like always be the first item in the com_users submenu. It wouldn't be a complete replacement like com_categories supports.

Unfortunately there aren't any triggers in com_users that I can find that would be of any help in swizzling the entire sidebar menu.

The next option is to use something like Donald Gilbert's gist to create a system plugin that allows you to override any core class by creating a substitute version of your own — obviously this will have issues with any significant updates but if you're careful you could limit the override to your specific situation.

If thats not enough/overkill you may want to try a system plugin that responds to onAfterDispatch at which point you would have the page before its returned to browser and you could hack the HTML, but thats very ugly and be prone to breaking if users change their admin template.

Of course, I could be completely wrong and theres a better way to do it in 3.x. Maybe someone else will chime in.

Upvotes: 1

Related Questions