So there is this deprecated message that pops up when using:

$toolbar = Toolbar::getInstance('toolbar');


4.0 will be removed in 6.0 Use the ToolbarFactoryInterface instead 
Example: Factory::getContainer()->get(ToolbarFactoryInterface::class)->createToolbar($name)

So when using:

$toolbar = Factory::getContainer()->get(ToolbarFactoryInterface::class)->createToolbar('toolbar')

and then add (for example)


it shows just the error that Button() could not been loaded. Anyone gets an example Code on how to use the ToolbarFactoryInterface class?

Another option would be to use the ToolbarHelper class but there I do not see a way to create "dropdowns" as used until now like so:

$toolbar = Toolbar::getInstance();
$dropdown = $toolbar->dropdownButton('status-group')
                ->icon('fa fa-ellipsis-h')
                ->buttonClass('btn btn-action')

            $childBar = $dropdown->getChildToolbar();

At least to create such dropdownButtons we have to use the "old fashioned" way right now, correct?

1 Answer 1


Yes, just use the old way using getInstance for now.

I came across this when I was updating the Joomla MVC tutorial component to Joomla4 and wrote up the issue here.

The reason is that all the other Joomla code currently uses getInstance('toolbar') to access the Toolbar class, including the code in administrator/modules/mod_toolbar/mod_toolbar.php which renders the toolbar. The getInstance method keeps track of the Toolbar instances in a local static variable $instances, and returns the same Toolbar instance on repeated invocations.

So if you use the approach of getting Toolbar via the Dependency Injection Container then you will get a Toolbar instance, but it won't be the same Toolbar instance as is stored in the $instances variable. It won't then be picked up by the Toolbar module, and so won't be rendered on the form.

(The Toolbar instance is created in libraries/src/Toolbar/ContainerAwareToolbarFactory.php::createToolbar() using new Toolbar(..), so if you can that createToolbar function twice you'll get 2 different Toolbar instances).

I've the Joomla 5 beta version downloaded, and in it com_content is still using getInstance, and the comment against the function includes:

"@todo Needs a proper replacement before removal as ToolbarFactoryInterface alone does not share the object everywhere"

Your Answer

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

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