User tests: Successful: Unsuccessful:
This is a new toolbar interface design on PHP part. Related to #18392 and #19635
Currently we use JToolbarHelper to add buttons to component view. But there are some problems of this interface.
First, too many arguemnts on some methods, for instance:
public static function preferences($component, $height = '550', $width = '875', $alt = 'JToolbar_Options', $path = '')Second, hard to add a custom button, the Toolbar::appendButton() has no type hint, we must look every Button classes to learn how to use them.
$bar->appendButton('Standard', 'name', 'JTOOLBAR_BUTTON', 'item.new', true, false);Then, it is impossible to customize some standard buttons or add dropdown. All standard buttons are hard coded.
I try to create a fluent interface that provides a flexible Toolbar button definition process:
$toolbar = Toolbar::getInstance('toolbar');
// Use core button class or custom class.
$toolbar->appendButton(new StandardButton('new'))
->text('JTOOLBAR_NEW')
->task('article.add')
->icon('icon-plus');
// Use pre-defined megic methods
$toolbar->popupButton('preview')
->text('COM_FOO_TOOLBAR_PREVIEW')
->url(Route::_('...'))
->icon('icon-eye')
->listCheck(true)
->iframeWidth(640)
->iframeHeight(480)
->setOption('foo', 'bar');All arguments are options.
$button->task('item.save');
// Same as
$button->setOption('task', 'item.save');And IDE friendily
Buttons can override layout and HTML classes:
$toolbar->linkButton('back')
->text('COM_FOO_TOOLBAR_BACK')
->url(Route::_('...'))
->icon('fa fa-arrow-left') // If icon not set, will fallback to `icon-back` like original code
->buttonClass('btn btn-primary btn-sm')
->layout('com_foo.toolbar.link');Use callback to easily customize your dropdown buttons.
$toolbar->dropdownButton('group')
->text('Group')
->toggleSplit(false)
->icon('fa fa-globe')
->buttonClass('btn btn-success btn-sm')
->configure(
function (Toolbar $childBar)
{
$childBar->standardButton('ok', 'Button 1');
$childBar->standardButton('star', 'Button 2');
$childBar->divider('HEADER');
$childBar->standardButton('remove', 'Button 3');
$childBar->standardButton('folder', 'Button 4');
$childBar->divider();
$childBar->standardButton('trash', 'Button 5');
$childBar->standardButton('question', 'Button 6');
}
);$toolbar->confirmButton('clear')
->text('Clear')
->icon('fa fa-refresh')
->buttonClass('btn btn-sm btn-danger')
->message('Are you sure you want to clear all data?');$toolbar->addNew('articles.add')->listCheck(true);
$toolbar->publish('articles.publish')->listCheck(true);
$toolbar->unpublish('articles.unpublish')->listCheck(true);
$toolbar->archive('articles.archive')->listCheck(true);
$toolbar->checkin('articles.checkin')->listCheck(true);If a component was using ToolbarHelper or $bar->appendButton(), it should fully B/C.
This PR is WIP, I changed com_content component to use new Toolbar syntax, it works very well:
| Status | New | ⇒ | Pending |
| Category | ⇒ | Administration com_content Modules Layout Libraries |
| Labels |
Added:
?
?
|
||
| Category | Administration com_content Modules Layout Libraries | ⇒ | Administration com_content Modules Templates (admin) Layout Libraries |
@asika32764 Please take the time to correct the Codestyle items here. It will help with the overall consideration of your proposal.
http://ci.joomla.org/joomla/joomla-cms/3102/4
You can use the PHPCS codestyle autofixers to automatically fix a number of the items in your PR. Just remember to keep it to the files related to your PR.
Still Work in process, will fix all CS and docblock later.
| Title |
|
||||||
I applied this PR and all components have many notices - for example these are with com_banners so its not yet b/c
Notice: Undefined variable: hasChildren in C:\htdocs\cms4\layouts\joomla\toolbar\base.php on line 21
Notice: Undefined variable: htmlAttributes in C:\htdocs\cms4\layouts\joomla\toolbar\link.php on line 31
and the component you updated for the new toolbar com_content fails to load at all with
0 Call to undefined method Joomla\CMS\Toolbar\Toolbar::addNew()
It seems your Toolbar class not up to date but I don't know why, all codes are commit to this PR.
See
https://github.com/joomla/joomla-cms/pull/19670/files#diff-8f8f92469552f260a1c93e2223dd753fR85
And
https://github.com/joomla/joomla-cms/pull/19670/files#diff-8adf1d52f0a9432d0c831fb7e9abe680R42
The addNew() method is in CoreButtonsTrait and Joomla\CMS\Toolbar\Toolbar uses it. If there are not other class loading caches, it should work since the method is really exists there.
@brianteeman I updated the autoload files, could you try again?
It must have been an issue that Patchtester cant cope with as I still had the same problem but when using native git I was able to test almost successfully. Just one error when using com_content
Warning: count(): Parameter must be an array or an object that implements Countable in C:\htdocs\cms4\administrator\components\com_content\Model\ArticlesModel.php on line 307
@brianteeman Look like not belongs to this PR.
joomla-cms/administrator/components/com_content/Model/ArticlesModel.php
Lines 305 to 312 in 9b719ee
did you use patchtester to test it? Maybe is the same reason of #19670 (comment)
@asika32764 , yes. I used patch tester to test it
@asika32764 can we get this upto date with 4.0 please. I really like this concept and would like to get it in :)
OK. A little busy that I stop developing this PR. Well continue finish this maybe this weekend.
| Status | Pending | ⇒ | Fixed in Code Base |
| Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2018-05-14 11:40:19 |
| Closed_By | ⇒ | wilsonge |
OK I've fixed the conflicts myself and made the decision to merge this for now so we can all work on it in the main repo :)
Thanks for the hard work that went into this!!
Thank you, sorry for the delayed since there are some serious projects I must to complete in this month.
I still must write some documentation. If you need the doc, please tag me.
Don't worry :) Thankyou so much for doing what you could!
were docs ever created for this?
No. See #19670 (comment)
@asika32764 @Fedik can you please coordinate this task?
Just for reference @Fedik already proposed something for the client side: #19635