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 |
|
||||||
I wonder why you decided to require passing $referenceButton instead of $buttonName to insert button/buttons method? From caller side, it will be much easier to just call $toolbar->insertButtonAfter('publish', $button); to insert the button after publish button than having to call additional method to find the reference button first
Further more, I guess I'm not the only one feel confused about the GET_BUTTON_PARENT_XXX constants use in the PR.
I wonder why you decided to require passing $referenceButton instead of $buttonName to insert button/buttons method? From caller side, it will be much easier to just call $toolbar->insertButtonAfter('publish', $button); to insert the button after publish button than having to call additional method to find the reference button first
Further more, I guess I'm not the only one feel confused about the GET_BUTTON_PARENT_XXX constants use in the PR.
And how do you think about having a additional method remove button in Toolbar api?
I wonder why you decided to require passing
$referenceButtoninstead of$buttonNameto insert button/buttons method? From caller side, it will be much easier to just call$toolbar->insertButtonAfter('publish', $button);to insert the button after publish button than having to call additional method to find the reference button firstFurther more, I guess I'm not the only one feel confused about the
GET_BUTTON_PARENT_XXXconstants use in the PR.And how do you think about having a additional method remove button in Toolbar api?
the reason why I use referenceButton is that I don't know where the developer takes the information about the button he or she likes to reference. maybe it's his own button, or it's provided by a plugin trigger, or you search for the button your self. it's also possible that the name is not unique.
true delete make sense and / or replace and move could make sense... good idea I will look when I finde the time to implement them.
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?