User tests: Successful: Unsuccessful:
Currently we use JHtml
(HTMLHelper
) to make the action buttons in grid view.
But the interface and the number of arguments of JHtmlJGrid::published()
is horrible, it hard to use and extends, developers must read many code to understand how to make their own buttons.
ActionButton
I try to create a class that is configurable, this is a sample code:
<?php
// In View class
$button = (new ActionButton(['disabled' => !$canChange]))
->addState(0, 'articles.featured', 'icon-unfeatured', 'COM_CONTENT_UNFEATURED');
->addState(1, 'articles.unfeatured', 'icon-featured', 'COM_CONTENT_FEATURED');
$this->featuredButton = $button;
// In template table view loop
<?php foreach ($articles as $i => $article): ?>
...
<td><?php echo $this->featuredButton->render($article->featured, $i); ?></td>
...
<?php endforeach; ?>
It's simple and easy to learn, make developers days joy.
This class use Joomla layouts to render template. Also we can override layout:
$button->setLayout('my.action.button');
If an item has an unexpected state value, for example, I changed an article state to 5
, it will show Unknow State
icon:
PublishedButton
For standard Joomla content, I also created a PublishedButton
that can handle the publish time:
$button = new PublishedButton(
[
'diabled' => $canDoWhat,
'task_prefix' => 'articles.',
'checkbox_name' => 'cb'
]
);
echo $button->render($value, $i, $publish_up, $publish_down);
In this PR, I rewrite articles published
and featured
button to use this class as example, it works well.
If this concept accepted, I will continue finish the test and docblock.
Status | New | ⇒ | Pending |
Category | ⇒ | Administration com_content Layout Libraries External Library Composer Change |
Title |
|
I think it won't be conflict. We still must call PHP to do some configuration or translate string before we call any client-side functions. Just change the template to raise any HTML/JS handling. This class is just a PHP entry to help developers enable button actions.
So do you have any plan for the JToolbar
? I also have some idea similar to this concept.
$toolbar = JToolbar::getInstance('administrator')
->addButton(new AddNewButton)
->addButton(new PublishButton)
->addButton(new CustomButton($html, JText::_('XXX')));
$toolbar->render();
I've started some work like 3 months ago: https://github.com/joomla/joomla-cms/compare/4.0-dev...dgt41:ยง4.0-dev-toolbar-cleanup?expand=1
Actually right now I think that the toolbar should be utilising custom elements, which obviously the above link is not...
I take a look your PR, I think my code can get together with custom elements without any problem.
See https://github.com/joomla/joomla-cms/pull/17375/files#diff-cffc36facfda8c2f198b4f893dd21bbaR35
Custom elements still needs PHP code to render it, most of all, we use JHtml
to render HTML elements and include JS files. The main subject or this PR is to replace JHtml and make API interface configurable.
We can imagine the button layout integrated the custom element will look like:
<?php
JHtml::_('webcomponent', ['toolbar-button' => 'system/joomla-toolbar-button.min.js'], ['relative' => true, 'version' => 'auto']);
extract($displayData);
?>
<toolbar-button
id="<?php echo $id;?>"
class="<?php echo $class;?>"
onclick="<?php echo $click;?>"
color="success"
check-list="true"
check-list-warning="Please select an item.">
<?php echo $text;?>
</toolbar-button>
I like this :) It seems a lot more obvious than what we had before!
Labels |
Added:
?
?
|
Category | Administration com_content Layout Libraries External Library Composer Change | ⇒ | Administration com_content Language & Strings Layout Libraries External Library Composer Change |
Labels |
Added:
?
|
Title |
|
Category | Administration com_content Layout Libraries External Library Composer Change Language & Strings | ⇒ | Administration com_content Language & Strings Layout Libraries |
Status | Pending | ⇒ | Fixed in Code Base |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2017-11-26 22:46:44 |
Closed_By | ⇒ | wilsonge | |
Labels |
Removed:
?
|
Thankyou very much for this :)
Hmm, I have something different in my mind for j4: using custom elements and client side rendering...