Merge pull request #15938 from civicrm/5.20
[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 $icon = CRM_Utils_Array::value('icon', $params, 'pencil');
42 // All other params are treated as html attributes
43 CRM_Utils_Array::remove($params, 'icon', 'p', 'q', 'a', 'f', 'h', 'fb', 'fe');
44 $attributes = CRM_Utils_String::htmlAttributes($params);
45 return "<a $attributes><span><i class='crm-i fa-$icon'></i>&nbsp; $text</span></a>";
46 }