Hi Gez,
Here's what i have so far - its not 100% finished or fully tested really its just a work in progress... but its a start i will continue to update this post.
Most of the areas where you need to add the custom button code i have used [custombutton] or [CUSTOMBUTTON] to highlight where the "custombutton" name needs to be defined DONT include the braces [ ]
Some of the below may not be needed - you may get away with just creating the task behind the button and registering the task but it depends on your needs
Before you start
To find what may already be possible without reinventing the wheel, have a look at the Standard tool bar icons in your standard bluestork template there are many predefined buttons and methods in the core for standard operations such as upload, forward, back...
Search for "toolbar icon styles" (or scroll to about line 2095) there you will find a list of button icons used for the toolbars
/administrator/templates/bluestork/css/template.css
TASKBAR ICONS - create your taskbar icon
BACKEND => administrator/templates/[YOUR SITE TEMPLATE]/images...
(there may be specific directory for toolbar icons)
create your icons and place them in the images file of your site template such as
icon-32-[custombutton].png
TASKBAR ICON CSS - Add icon details to your site template css
You maybe able to create template overrides but I prefer to create the icon and place in the relative template file and modify the template css - the choice is yours
BACKEND => administrator/templates/[YOUR TEMPLATE]/css/template.css
add icon details to your template css file such as
.icon-32-[custombutton] { background-image: url('../images/icon-32-[custombutton].png'); }
LANGUAGE FILES - Add custom button name
FRONTEND => \language\en-GB\en-GB.com_yourcomponentname.ini
BACKEND => \administrator\language\en-GB\en-GB.com_yourcomponentname.ini
//such as
[YOURCOMPONENTNAME]_JTOOLBAR_[CUSTOMBUTTON]="Custom Button"
VIEW.HTML.PHP - Define the custom button in the view.html.php file of respective view
NOTE: notice the difference between collection and item layouts when checking view access
COLLECTION LAYOUTS - use if($model->canEdit())
ITEM LAYOUTS - use if ($item->params->get('access-edit'))
FOR ITEM LAYOUTS - look for similar and define custom button
REMEMBER - use if ($item->params->get('access-edit'))
TAKE NOTE - The "TASK" is the same for both custom button definitions!
what to do when the button is pressed is determined by the switch function in the custombutton function of the item controller
//Toolbar initialization
JToolBarHelper::title(JText::_('YOURCOMPONENTNAME_LAYOUT_NAME_ITEM'), 'yourcomponentname_yourviewname');
......
......
// Custom button
if ($item->params->get('access-edit'))
JToolBarHelper::custom('tableitem.[custombutton]', '[custombutton].png', '[custombutton].png', JText::_("[YOURCOMPONENTNAME]_JTOOLBAR_[CUSTOMBUTTON]"), false, false);
// ANOTHER Custom button
// Take Note the "TASK" is the same for both custom button definitions!
if ($item->params->get('access-edit'))
JToolBarHelper::custom('tableitem.[custombutton]', '[anothercustombutton].png', '[anothercustombutton].png', JText::_("[YOURCOMPONENTNAME]_JTOOLBAR_[ANOTHERCUSTOMBUTTON]"), false, false);
FOR COLLECTION LAYOUTS
REMEMBER - use $model->canEdit() to determine view access
// CUSTOM BUTTON
if ($model->canEdit())
JToolBarHelper::custom('tableitem.[custombutton]', '[custombutton].png', '[custombutton].png', JText::_("[YOURCOMPONENTNAME]_JTOOLBAR_[CUSTOMBUTTON]"), false, false);
For reference on how to define custom buttons
From Joomla Docs -
docs.joomla.org/How_to_create_a_custom_button/**
* Writes a custom option and task button for the button bar
* @param string The task to perform (picked up by the switch($task) blocks
* @param string The image to display
* @param string The image to display when moused over
* @param string The alt text for the icon image
* @param boolean True if required to check that a standard list item is checked
* @param boolean True if required to include callinh hideMainMenu()
*/
JToolBarHelper::custom( 'task', 'icon', 'icon over', 'alt', boolean, boolean );
ALSO - Found this tutorial today has good how create custom toolbar buttons
www.tutsforu.com/adding-toolbar-at-backe...oomla-component.html
ITEM CONTROLLER - Create the task function and redirect in the respective item controller
(at present i believe that all of the redirects are defined in the item controller)
public function [custombutton]()
{
JRequest::checkToken() or JRequest::checkToken('get') or jexit(JText::_('JINVALID_TOKEN'));
//Check the ACLs
$model = $this->getModel();
$item = $model->getItem();
if (!$model->canEdit($item))
return false;
//Catch the initializated JModel trough postSaveHook()
$model = $this->model;
//Define the redirections
switch($this->getLayout() .'.'. $this->getTask())
{
case 'yourviewname.[custombutton]':
$this->applyRedirection($result, array(
'com_yourcomponentname.yourviewname.yourcurrentlayoutname',
'com_yourcomponentname.redirecttoyourviewname.redirecttolayoutname'
), array(
'cid[]' => null,
'filter_some_id' => $model->getState('yourcurrentlayoutname.id')
));
break;
// add additional custom button redirects here such as
case 'yourviewname.[anothercustombutton]':
$this->applyRedirection($result, array(
'com_yourcomponentname.yourviewname.yourcurrentlayoutname',
...........
...........
));
break;
}
}
CREATE THE SUBMIT - in administrator/components/com_yourcomponent/dom/html/toolbar/button.php
switch ($this->getTaskExec())
{
case 'save':
case 'apply':
if (!defined('JQUERY'))
$submitAction = "return document.formvalidator.submitform (document.adminForm, '" . $taskCtrl . "', function(pressbutton){return " . $jsSubmitForm . "(pressbutton);});";
$cmd = "javascript:" . $submitAction;
break;
case '[custombutton]';
if (!defined('JQUERY'))
$submitAction = "return document.formvalidator.submitform (document.adminForm, '" . $taskCtrl . "', function(pressbutton){return " . $jsSubmitForm . "(pressbutton);});";
$cmd = "javascript:" . $submitAction;
break;
TASK SWITCH - create case for the custom button
in administrator/components/com_yourcomponent/dom/dom.php
function accessTask($task)
{
$aclAccess = $this->getOption('aclAccess');
if ($aclAccess)
return $this->access();
switch ($task)
{
case 'new':
$access = 'core.create';
break;
case '[custombutton]':
$access = 'core.edit';
break;
case 'edit':
...........
...........