User tests: Successful: Unsuccessful:
All written by hand...
Add couple of methods to the Toolbar class which allow to easily add buttons at a specific position relative to an existing button.
new methods:
public function getButtonByName(string|array $names, $parent = self::GET_BUTTON_PARENT_ROOT, ?ToolbarButton $parentButton = null): ToolbarButton
public function insertButtons(int $offset, ToolbarButton $referenceButton, ToolbarButton ...$buttons): void
public function insertButtonsBefore(ToolbarButton $referenceButton, ToolbarButton ...$buttons): void
public function insertButtonBefore(ToolbarButton $referenceButton, ToolbarButton $button): ToolbarButton
public function insertButtonsAfter(ToolbarButton $referenceButton, ToolbarButton ...$buttons): void
public function insertButtonAfter(ToolbarButton $referenceButton, ToolbarButton $button): ToolbarButtonThis will not work if the reference button already added to the toolbar is not a ToolbarButton for example legacy code might used the plain array syntax which is deprecated since a long time and will be removed with 7.0
in your HTMLView of a list view add an override for the addToolbar() method
protected function addToolbar()
{
parent::addToolbar();
$toolbar = $this->getDocument()->getToolbar();
$button = new StandardButton('save-copy', 'JTOOLBAR_SAVE_AS_COPY');
$button
->listCheck(true)
->task('items.save2copy');
$toolbar->insertButtonAfter($toolbar->getButtonByName('save-group', $button));
// or as alternative add it into the action drop down
$toolbar->insertButtonAfter($toolbar->getButtonByName('unpublish', Toolbar::GET_BUTTON_PARENT_BUTTON), $button);
}Not possible to you need to create it by hand
Should add the button at the right position
Please select:
Documentation link for guide.joomla.org:
No documentation changes for guide.joomla.org needed
Pull Request link for manual.joomla.org:
No documentation changes for manual.joomla.org needed
| Status | New | ⇒ | Pending |
| Category | ⇒ | Libraries |
silly question - buttons are rendered in the order they are written in the code - so why would i put the code out of order and use these new methods instead?
If you have a Plugin for example or use the parent:: addtoolbar default toolbar and want to add additional buttons in your own component and in worse case in an override (not a good idea but who knows)
| Labels |
Added:
PR-6.3-dev
|
||
So would I be correct then that this could be used here
joomla-cms/libraries/src/Toolbar/ToolbarHelper.php
Lines 150 to 155 in 704b12d
so that inbstead of appending the button it could be placed in a specific place
So would I be correct then that this could be used here
joomla-cms/libraries/src/Toolbar/ToolbarHelper.php
Lines 150 to 155 in 704b12d
so that instead of appending the button it could be placed in a specific place
So would I be correct then that this could be used here
joomla-cms/libraries/src/Toolbar/ToolbarHelper.php
Lines 150 to 155 in 704b12d
so that instead of appending the button it could be placed in a specific place
yes, but in core we don't have a good example, maybe the guided tour, since it has a custom build toolbar in the view.
| Category | Libraries | ⇒ | Libraries Unit Tests |
| Labels |
Added:
Unit/System Tests
|
||
| Title |
|
||||||
silly question - buttons are rendered in the order they are written in the code - so why would i put the code out of order and use these new methods instead?