? ? Pending

User tests: Successful: Unsuccessful:

avatar asika32764
asika32764
13 Feb 2018

This is a new toolbar interface design on PHP part. Related to #18392 and #19635

  • Complete Dropdown buttons logic
  • Add Toolbar class to service provider
  • Sync php code with #19635
  • Code style and docblock
  • Test
  • Write a guide about how to us new interfaces.

Introduction

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.

The Changes

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

p-2018-02-14-004

Layout

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');

Button Group

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');
		}
	);

p-2018-02-14-003

Confirm Button

$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?');

p-2018-02-14-002

Pre-Defined Buttons

$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);

No B/C break

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:

avatar asika32764 asika32764 - open - 13 Feb 2018
avatar asika32764 asika32764 - change - 13 Feb 2018
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 13 Feb 2018
Category Administration com_content Modules Layout Libraries
avatar asika32764 asika32764 - change - 13 Feb 2018
The description was changed
avatar asika32764 asika32764 - edited - 13 Feb 2018
avatar asika32764 asika32764 - change - 13 Feb 2018
The description was changed
avatar asika32764 asika32764 - edited - 13 Feb 2018
avatar asika32764 asika32764 - change - 13 Feb 2018
Labels Added: ? ?
avatar joomla-cms-bot joomla-cms-bot - change - 13 Feb 2018
Category Administration com_content Modules Layout Libraries Administration com_content Modules Templates (admin) Layout Libraries
avatar asika32764 asika32764 - change - 13 Feb 2018
The description was changed
avatar asika32764 asika32764 - edited - 13 Feb 2018
avatar asika32764 asika32764 - change - 13 Feb 2018
The description was changed
avatar asika32764 asika32764 - edited - 13 Feb 2018
avatar dgt41
dgt41 - comment - 13 Feb 2018

@asika32764 @Fedik can you please coordinate this task?
Just for reference @Fedik already proposed something for the client side: #19635

avatar asika32764 asika32764 - change - 13 Feb 2018
The description was changed
avatar asika32764 asika32764 - edited - 13 Feb 2018
avatar asika32764
asika32764 - comment - 13 Feb 2018

I think the php side still need much discussion (Since it is a big change). If the concept of this PR accepted, I can try to integrate @Fedik 's code into my PR or merge #19635 first then I sync the code base.

What do you think @Fedik ?

avatar asika32764 asika32764 - change - 13 Feb 2018
The description was changed
avatar asika32764 asika32764 - edited - 13 Feb 2018
avatar photodude
photodude - comment - 13 Feb 2018

@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.

avatar asika32764
asika32764 - comment - 13 Feb 2018

Still Work in process, will fix all CS and docblock later.

avatar asika32764 asika32764 - change - 14 Feb 2018
Title
[4.0][RFC] New Toolbar Interface (for PHP)
[4.0][RFC][WIP] New Toolbar Interface (for PHP)
avatar asika32764 asika32764 - edited - 14 Feb 2018
avatar brianteeman
brianteeman - comment - 14 Feb 2018

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()

avatar asika32764
asika32764 - comment - 14 Feb 2018

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.

avatar asika32764
asika32764 - comment - 14 Feb 2018

@brianteeman I updated the autoload files, could you try again?

avatar brianteeman
brianteeman - comment - 14 Feb 2018

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

avatar Fedik
Fedik - comment - 14 Feb 2018

What do you think @Fedik ?

I think it is good idea ?

I can wait when you finish it, then I can rework javascript part in #19635. It mainly the layout changes.
And it even better to finish PHP part first.

#19635 has only 2 extra thing I changed in Toolbar:

  • prevent ID duplication. like here
  • allow to pass validate marker, and add form to pass a form selector, there
avatar asika32764 asika32764 - change - 15 Feb 2018
The description was changed
avatar asika32764 asika32764 - edited - 15 Feb 2018
avatar asika32764 asika32764 - change - 15 Feb 2018
The description was changed
avatar asika32764 asika32764 - edited - 15 Feb 2018
avatar asika32764 asika32764 - change - 15 Feb 2018
The description was changed
avatar asika32764 asika32764 - edited - 15 Feb 2018
avatar asika32764
asika32764 - comment - 15 Feb 2018

@brianteeman Look like not belongs to this PR.

}
// Case: Using both categories filter and by level filter
if (count($categoryId))
{
$categoryId = ArrayHelper::toInteger($categoryId);
$categoryTable = \JTable::getInstance('Category', 'JTable');
$subCatItemsWhere = array();

avatar asika32764 asika32764 - change - 16 Feb 2018
The description was changed
avatar asika32764 asika32764 - edited - 16 Feb 2018
avatar asika32764 asika32764 - change - 16 Feb 2018
The description was changed
avatar asika32764 asika32764 - edited - 16 Feb 2018
avatar asika32764 asika32764 - change - 16 Feb 2018
The description was changed
avatar asika32764 asika32764 - edited - 16 Feb 2018
avatar Samgithub1997
Samgithub1997 - comment - 22 Mar 2018

After applying the patch , I am getting this error when i tried creating "New Article"

workspace 1_029

avatar asika32764
asika32764 - comment - 23 Mar 2018

did you use patchtester to test it? Maybe is the same reason of #19670 (comment)

avatar Samgithub1997
Samgithub1997 - comment - 23 Mar 2018

@asika32764 , yes. I used patch tester to test it

avatar wilsonge
wilsonge - comment - 11 Apr 2018

@asika32764 can we get this upto date with 4.0 please. I really like this concept and would like to get it in :)

avatar asika32764
asika32764 - comment - 12 Apr 2018

OK. A little busy that I stop developing this PR. Well continue finish this maybe this weekend.

avatar wilsonge wilsonge - close - 14 May 2018
avatar wilsonge wilsonge - merge - 14 May 2018
avatar wilsonge wilsonge - change - 14 May 2018
Status Pending Fixed in Code Base
Closed_Date 0000-00-00 00:00:00 2018-05-14 11:40:19
Closed_By wilsonge
avatar wilsonge
wilsonge - comment - 14 May 2018

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 :)

avatar wilsonge
wilsonge - comment - 14 May 2018

Thanks for the hard work that went into this!!

avatar asika32764
asika32764 - comment - 14 May 2018

Thank you, sorry for the delayed since there are some serious projects I must to complete in this month.

avatar asika32764
asika32764 - comment - 14 May 2018

I still must write some documentation. If you need the doc, please tag me.

avatar wilsonge
wilsonge - comment - 14 May 2018

Don't worry :) Thankyou so much for doing what you could!

avatar wilsonge wilsonge - change - 19 Jul 2018
The description was changed
avatar wilsonge wilsonge - edited - 19 Jul 2018
avatar N6REJ
N6REJ - comment - 31 Jul 2020

were docs ever created for this?

avatar Quy
Quy - comment - 31 Jul 2020

Add a Comment

Login with GitHub to post a comment