Merge pull request #17291 from mfb/tracking-default
[civicrm-core.git] / CRM / Core / Smarty / plugins / block.crmButton.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 * $Id$
17 *
18 */
19
20 /**
21 * Generate the html for a button-style link
22 *
23 * @param array $params
24 * Params of the {crmButton} call.
25 * @param string $text
26 * Contents of block.
27 * @param CRM_Core_Smarty $smarty
28 * The Smarty object.
29 *
30 * @return string
31 * The generated html.
32 */
33 function smarty_block_crmButton($params, $text, &$smarty) {
34 // Generate url (pass 'html' param as false to avoid double-encode by htmlAttributes)
35 if (empty($params['href'])) {
36 $params['href'] = CRM_Utils_System::crmURL($params + ['h' => FALSE]);
37 }
38 // Always add class 'button' - fixme probably should be crm-button
39 $params['class'] = empty($params['class']) ? 'button' : 'button ' . $params['class'];
40 // Any FA icon works
41 if (array_key_exists('icon', $params) && !$params['icon']) {
42 // icon=0 should produce a button with no icon
43 $iconMarkup = '';
44 }
45 else {
46 $icon = $params['icon'] ?? 'fa-pencil';
47 // Assume for now that all icons are Font Awesome v4.x but handle if it's
48 // specified
49 if (strpos($icon, 'fa-') !== 0) {
50 $icon = "fa-$icon";
51 }
52 $iconMarkup = "<i class='crm-i $icon'></i>&nbsp; ";
53 }
54 // All other params are treated as html attributes
55 CRM_Utils_Array::remove($params, 'icon', 'p', 'q', 'a', 'f', 'h', 'fb', 'fe');
56 $attributes = CRM_Utils_String::htmlAttributes($params);
57 return "<a $attributes><span>$iconMarkup$text</span></a>";
58 }