Uploaded image for project: 'CiviCRM'
  1. CiviCRM
  2. CRM-10571

Allow users to capitalize (or other case functions) fields in mailing labels

    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

      {fooTOKENbar}

      foreach ($replacements as $token => $value) {
      if ($value) {
      + self::mimicSmartyCaseModifiers($token, $value, $formatted);
      $formatted = preg_replace("/{([^{}])\b{$token}\b([^{}])}/u", "\$

      {1}

      {$value}\$

      {2}

      ", $formatted);
      }
      else

      { @@ -297,5 +298,30 @@ $newSequence = array_unique($newSequence); return $newSequence; }

      +
      + /*
      + * 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])

      { + case 'upper': + $value = strtoupper($value); + break; + case 'lower': + $value = strtolower($value); + break; + case 'capitalize': + $value = ucwords($value); + }

      + $token .= '|' . $modmatches[1];
      + }
      + }
      }

        Attachments

          Activity

            People

            • Assignee:
              eileen Eileen McNaughton
              Reporter:
              eileen Eileen McNaughton
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: