11

Is it possible to add a custom button (with a custom action, of course) to the JToolbar of a standard Joomla 3 component (com_contents) without modifying the original source code?

Background: I need to add a button to the com_contents main screen (the list of all the articles) to create a massive mail function. I can, of course, modify the standard Joomla files, but if I modify it, when I upgrade Joomla to a new version I'll lose my customization. But, if somehow I can add the button, I won't lose any change when updating...

And if it's possible to do this, how can it be done? Creating a plugin? Is there any tutorial to guide me thru the creation of this addon?

2 Answers 2

11

Here is a draft idea using a plugin:

You need to create a system plugin (I am not getting into that) and to use the event onBeforeRender. Inside you get an instance of your Toolbar and append the button.

class PlgSystemCustomtoolbar extends JPlugin
{
    public function onBeforeRender()
    {
        // Get the application object
        $app = JFactory::getApplication();

        // Run in backend
        if ($app->isAdmin() === true)
        {
            // Get the input object
            $input = $app->input;

            // Append button just on Articles
            if ($input->getCmd('option') === 'com_content' && $input->getCmd('view', 'articles') === 'articles')
            {
                // Get an instance of the Toolbar
                $toolbar = JToolbar::getInstance('toolbar');

                // Add your custom button here
                $url = JRoute::_('index.php?option=com_example&task=massemail&format=raw');
                $toolbar->appendButton('Link', 'export', 'Mass Email', $url);
            }
        }
    }
}
2
  • Great! It works like a charm! Only a little question: How can I pass the selected items to my controller? AFAIK, if I use the standard Joomla JS functions they will call the com_content controller, isn't it?
    – mHouses
    Nov 11, 2014 at 8:26
  • 1
    Please ask this as a new question. Nov 11, 2014 at 15:14
5

Working in an external way, you can create an Administrator module, an editors-xtd plug-in, or a system plugin. In both cases, when your code is executed, you can add some Javascript code to inject the button in the required location.

  • Administrator module, it is going to be shown in a position, for instance menu. It can add anything to all pages.
  • editors-xtd plug-in, it is going to be shown only as a button under the text editor. It can open a full view from your component.
  • system plugin, it can do anything, but it does not have an User Interface by itself, like the previous cases.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.