Item action buttons are the buttons on an item and in lists of items: update, delete, download, add to playlist, buy, and so on. Any module can add a button to any other module's items, without template changes. Templates show them with {jrCore_item_list_buttons} and similar functions.
Master admins can choose who sees each button: a configure button appears next to the buttons on profile pages, where each button can be turned on or off for user groups and quotas.
Register the button function in _init(). There are three places a button can go:
$_tmp = array(
'title' => 'download audio button',
'icon' => 'download',
'active' => 'on',
'group' => 'user'
);
jrCore_register_module_feature('jrCore', 'item_list_button', 'jrAudio', 'jrAudio_item_download_button', $_tmp);
jrCore_register_module_feature('jrCore', 'item_detail_button', 'jrAudio', 'jrAudio_item_download_button', $_tmp);item_index_button: on a module's section of a profile (like the + create button)item_list_button: on each item in a listitem_detail_button: on an item's own pagetitle names the button in the configure screen, active sets whether it's on by default, and group who sees it by default.
It gets the module of the item being shown, the item, the template parameters, Smarty, and $test_only. It returns an array for the button, or false to show nothing:
function jrAudio_item_download_button($module, $_item, $_args, $smarty, $test_only = false)
{
if ($module != 'jrAudio') {
return false;
}
if ($test_only) {
return true; // yes, this button can appear on this module's items
}
if (jrUser_can_edit_item($_item)) {
$url = jrCore_get_module_url('jrAudio');
return array(
'url' => jrCore_get_base_url() . "/{$url}/download/audio_file/{$_item['_item_id']}",
'icon' => 'download',
'alt' => 'download'
);
}
return false;
}$test_only is true when the configure screen asks whether the button applies to a module: return true without building it.
The real version of this function, with its download checks, is in the Audio module's include.php. Read it for a complete example.