. */ namespace Alledia\Framework\Joomla\Toolbar; use Alledia\Framework\Factory; use Joomla\CMS\HTML\HTMLHelper; use Joomla\CMS\Toolbar\Toolbar; use Joomla\CMS\Utility\Utility; use Joomla\CMS\Version; defined('_JEXEC') or die(); abstract class ToolbarHelper extends \Joomla\CMS\Toolbar\ToolbarHelper { /** * @var bool */ protected static $exportLoaded = false; /** * Create a button that links to an external page * * @param string $url * @param string $title * @param ?string $icon * @param ?mixed $attributes * * @return void */ public static function externalLink(string $url, string $title, ?string $icon = null, $attributes = []) { if (is_string($attributes)) { $attributes = Utility::parseAttributes($attributes); } $icon = $icon ?: 'link'; $attributes['target'] = $attributes['target'] ?? '_blank'; $attributes['class'] = join( ' ', array_filter( array_merge( explode(' ', $attributes['class'] ?? ''), [ 'btn', 'btn-small' ] ) ) ); $button = HTMLHelper::_( 'link', $url, sprintf(' %s', $icon, $title), $attributes ); if (Version::MAJOR_VERSION > 3) { $button = sprintf('%s', $button); } $bar = Toolbar::getInstance(); $bar->appendButton('Custom', $button, $icon); } /** * Create a button that links to documentation * * @param string $url * @param string $title * * @return void */ public static function shackDocumentation(string $url, string $title) { static::externalLink($url, $title, 'support', ['class' => 'btn-info', 'target' => 'shackdocs']); } /** * Export button that ensures the task input field is cleared if * the export does not return to refresh the page * * @param string $task * @param string $alt * @param string $icon * * @return void * @throws \Exception */ public static function exportView(string $task, string $alt, string $icon = 'download') { static::custom($task, $icon, null, $alt, false); if (static::$exportLoaded == false) { Factory::getApplication()->getDocument()->addScriptDeclaration(<<