Commit | Line | Data |
---|---|---|
c7454848 CW |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
c7454848 | 5 | | | |
bc77d7c0 TO |
6 | | This work is published under the GNU AGPLv3 license with some | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
c7454848 CW |
9 | +--------------------------------------------------------------------+ |
10 | */ | |
11 | ||
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
c7454848 CW |
16 | */ |
17 | ||
c7454848 CW |
18 | /** |
19 | * Generate the html for a button-style link | |
20 | * | |
21 | * @param array $params | |
22 | * Params of the {crmButton} call. | |
23 | * @param string $text | |
24 | * Contents of block. | |
25 | * @param CRM_Core_Smarty $smarty | |
26 | * The Smarty object. | |
27 | * | |
28 | * @return string | |
29 | * The generated html. | |
30 | */ | |
31 | function smarty_block_crmButton($params, $text, &$smarty) { | |
79a18c21 | 32 | // Generate url (pass 'html' param as false to avoid double-encode by htmlAttributes) |
aeb97cc1 | 33 | if (empty($params['href'])) { |
be2fb01f | 34 | $params['href'] = CRM_Utils_System::crmURL($params + ['h' => FALSE]); |
aeb97cc1 | 35 | } |
c7454848 | 36 | // Always add class 'button' - fixme probably should be crm-button |
d0870700 | 37 | $params['class'] = empty($params['class']) ? 'button' : 'button ' . $params['class']; |
089c8593 | 38 | // Any FA icon works |
82f040de AH |
39 | if (array_key_exists('icon', $params) && !$params['icon']) { |
40 | // icon=0 should produce a button with no icon | |
41 | $iconMarkup = ''; | |
42 | } | |
43 | else { | |
44 | $icon = $params['icon'] ?? 'fa-pencil'; | |
45 | // Assume for now that all icons are Font Awesome v4.x but handle if it's | |
46 | // specified | |
47 | if (strpos($icon, 'fa-') !== 0) { | |
48 | $icon = "fa-$icon"; | |
49 | } | |
3eb86289 | 50 | $iconMarkup = "<i class='crm-i $icon' aria-hidden=\"true\"></i> "; |
82f040de | 51 | } |
c7454848 CW |
52 | // All other params are treated as html attributes |
53 | CRM_Utils_Array::remove($params, 'icon', 'p', 'q', 'a', 'f', 'h', 'fb', 'fe'); | |
79a18c21 | 54 | $attributes = CRM_Utils_String::htmlAttributes($params); |
82f040de | 55 | return "<a $attributes><span>$iconMarkup$text</span></a>"; |
c7454848 | 56 | } |