Details
-
Type: Patch
-
Status: Done/Fixed
-
Priority: Trivial
-
Resolution: Won't Fix
-
Affects Version/s: 4.1.1
-
Fix Version/s: Unscheduled
-
Component/s: Core CiviCRM
-
Labels:None
Description
End users are requesting the ability to capitalize things like State & Country in Mailing labels for postal requirements. The code is not being passed through Smarty so smarty modifiers don't apply. It is likely at this stage the code should be refactored to use the Token class but a reasonable interim fix seems to be to allow people to use the 3 smart modifiers upper, lower & capitalize
e.g
{contact.country|upper} {contact.city|capitalize} {contact.display_name|capitalize}(this last example is not necessarily a good idea as it doesn't do the name oddities but some customers want it)
If you are happy with this I will commit it.
Index: CRM/Utils/Address.php
===================================================================
— CRM/Utils/Address.php (revision 41501)
+++ CRM/Utils/Address.php (working copy)
@@ -205,6 +205,7 @@
// the value is not empty, otherwise drop the whole
foreach ($replacements as $token => $value) {
if ($value) {
+ self::mimicSmartyCaseModifiers($token, $value, $formatted);
$formatted = preg_replace("/{([^{}])\b{$token}\b([^{}])}/u", "\$
{$value}\$
{2}", $formatted);
}
else
+
+ /*
+ * As this code is not being passed through smarty this function mimics the 3
+ * smarty modifiers - upper - lower - capitalize
+ * http://www.smarty.net/docsv2/en/language.modifiers.tpl @param string $token
+ * the token being looked at @param string $value the value of the token being
+ * looked at @param string $outputText the text subject to replacements
+ */
+ static function mimicSmartyCaseModifiers(&$token, &$value, $outputText) {
+ $modifier = '';
+ $modmatches = array();
+ if (preg_match("/{$token}|([^{}]*)}/", $outputText, $modmatches)) {
+ switch ($modmatches[1])
+ $token .= '|' . $modmatches[1];
+ }
+ }
}