From deae896d60c340ae3bd722cf1db57bda2799eeb7 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Tue, 6 Jan 2015 13:31:44 -0500 Subject: [PATCH] CRM-15789 - Add icons to submit buttons --- CRM/Core/Form.php | 13 ++++- .../Smarty/plugins/function.crmAttributes.php | 3 +- .../plugins/function.crmGetAttribute.php | 49 ++++++++++++++++ css/civicrm.css | 57 ++++++++++--------- js/crm.ajax.js | 2 +- templates/CRM/common/formButtons.tpl | 6 +- 6 files changed, 99 insertions(+), 31 deletions(-) create mode 100644 CRM/Core/Smarty/plugins/function.crmGetAttribute.php diff --git a/CRM/Core/Form.php b/CRM/Core/Form.php index 336dc5e776..a155cc4447 100644 --- a/CRM/Core/Form.php +++ b/CRM/Core/Form.php @@ -496,8 +496,7 @@ class CRM_Core_Form extends HTML_QuickForm_Page { * */ public function addButtons($params) { - $prevnext = array(); - $spacing = array(); + $prevnext = $spacing = array(); foreach ($params as $button) { $js = CRM_Utils_Array::value('js', $button); $isDefault = CRM_Utils_Array::value('isDefault', $button, FALSE); @@ -512,8 +511,11 @@ class CRM_Core_Form extends HTML_QuickForm_Page { $attrs = array_merge($js, $attrs); } + $defaultIcon = 'check'; + if ($button['type'] === 'cancel') { $attrs['class'] .= ' cancel'; + $defaultIcon = 'close'; } if ($button['type'] === 'reset') { @@ -521,6 +523,9 @@ class CRM_Core_Form extends HTML_QuickForm_Page { } else { if (!empty($button['subName'])) { + if ($button['subName'] == 'new') { + $defaultIcon = 'plus'; + } $buttonName = $this->getButtonName($button['type'], $button['subName']); } else { @@ -530,6 +535,10 @@ class CRM_Core_Form extends HTML_QuickForm_Page { if (in_array($button['type'], array('next', 'upload', 'done')) && $button['name'] === ts('Save')) { $attrs = array_merge($attrs, (array('accesskey' => 'S'))); } + $icon = CRM_Utils_Array::value('icon', $button, $defaultIcon); + if ($icon) { + $attrs['crm-icon'] = $icon; + } $prevnext[] = $this->createElement('submit', $buttonName, $button['name'], $attrs); } if (!empty($button['isDefault'])) { diff --git a/CRM/Core/Smarty/plugins/function.crmAttributes.php b/CRM/Core/Smarty/plugins/function.crmAttributes.php index e2652f0b1a..39ddadb70b 100644 --- a/CRM/Core/Smarty/plugins/function.crmAttributes.php +++ b/CRM/Core/Smarty/plugins/function.crmAttributes.php @@ -34,12 +34,13 @@ */ /** - * Add a stylesheet to a specific part of the page + * Formats an array of attributes as html * * @param array $params * ['a'] array of attributes. * @param CRM_Core_Smarty $smarty * + * @return string * @throws Exception */ function smarty_function_crmAttributes($params, &$smarty) { diff --git a/CRM/Core/Smarty/plugins/function.crmGetAttribute.php b/CRM/Core/Smarty/plugins/function.crmGetAttribute.php new file mode 100644 index 0000000000..9fd1b74e32 --- /dev/null +++ b/CRM/Core/Smarty/plugins/function.crmGetAttribute.php @@ -0,0 +1,49 @@ +{$html|crmAddClass:$validate} + {capture assign=icon}{crmGetAttribute html=$html attr='crm-icon'}{/capture} + + {if $icon} {/if} + {$html|crmAddClass:$validate} + {/if} {/foreach} {/crmRegion} -- 2.25.1