Answers.Body: <p>The answer is already here. According to a tiny mention at the bottom of <a href="http://wiki.civicrm.org/confluence/display/CRMDOC/Directories" rel="nofollow">http://wiki.civicrm.org/confluence/display/CRMDOC/Directories</a> page, it is possible (and, more important, it works!) to copy modified core files to Custom PHP Path Directory (at civicrm/admin/setting/path?reset=1) , preserving original files/folders structure, so next time CiviCRM gets security updates, changes should be kept (unless original file / function major changes). </p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-11-27T10:57:23.933Z
Answers.LastActivityDate: 2015-12-01T11:22:40.633Z
Answers.LastEditDate: 2015-12-01T11:22:40.633Z
Answers.UserDisplayName: yurg
Body: <p><strong>This is not a duplicate of <a href="https://civicrm.stackexchange.com/questions/4580/is-it-possible-to-change-the-mailing-label-format">Is it possible to change the Mailing label format?</a></strong> </p>
  
  <p>While printing Mailing Labels, we've found that Addressee Tokens don't work as expected when "Merge labels for contacts with the same address" is ticked. </p>
  
  <p>Mean, if one wants to get "Mr &amp; Mrs Smith", {addressee} token should be used at <strong>civicrm/admin/setting/preferences/address?reset=1</strong>; we've tried to add "contact.formal_title", but it doesn't get merged properly, only first value is printed, so it looks like:</p>
  
  <pre><code> "Mr Smith Title
  Mr A &amp; Mrs B Smith " 
  </code></pre>
  
  <p>instead of </p>
  
  <pre><code>Mr Smith Title  A &amp; Mrs Smith Title B Smith
  </code></pre>
  
  <p>There is a <strong>mergeSameAddress</strong> function at \civicrm\CRM\Core\BAO\Address.php which works with <strong>&amp;$rows</strong> parameter, but there is no "formal_title" in a $row according to <strong>print_r</strong>: </p>
  
  <pre><code>  [contact_type] =&gt; Individual
              [display_name] =&gt; H S W
              [do_not_mail] =&gt; 0
              [first_name] =&gt; H S
              [last_name] =&gt; W
              [prefix_id] =&gt; 
              [is_deceased] =&gt; 0
              [addressee_id] =&gt; 1
              [addressee_display] =&gt; H S W
              [addressee_custom] =&gt; 
              [address_id] =&gt; 20144
              [street_address] =&gt; 111
              [supplemental_address_1] =&gt; 111
              [supplemental_address_2] =&gt; 
              [city] =&gt; 
              [postal_code_suffix] =&gt; 
              [postal_code] =&gt; 111
              [address_name] =&gt; 
              [county_id] =&gt; 
              [state_province_id] =&gt; 
              [country_id] =&gt; 1226
              [individual_prefix] =&gt; 
              [addressee] =&gt; H S W
              [county] =&gt; 
              [state_province_name] =&gt; 
              [state_province] =&gt; 
              [country] =&gt; 111
  </code></pre>
  
  <p>What would be a proper way to add formal_title as a part of a merged address value (assuming appending formal_title to a first name)? Currently, <strong>Prefix</strong> works as desired, but it exists in a $rows, so can be easily retrieved. Not sure why formal_title is not a part of this and it's not clear, where $rows data is came from.     </p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Desired result has been achieved by modifying two core files: </p>
  
  <ol>
  <li>civicrm/CRM/Core/BAO/Address.php </li>
  </ol>
  
  <p>line 1059</p>
  
  <blockquote>
    <p>'formal_title' =>  $rows[$rowID]['formal_title'],</p>
  </blockquote>
  
  <p>line 1095</p>
  
  <p>replace </p>
  
  <blockquote>
    <p>$family = trim(implode(" &amp; ", array_keys($first_names)) . " " . $last_name);</p>
  </blockquote>
  
  <p>to  </p>
  
  <blockquote>
    <p>$family = trim(implode(" &amp; ", array_keys($first_names)));</p>
  </blockquote>
  
  <ol start="2">
  <li>civicrm/CRM/Contact/Form/Task/Label.php 
  line 167</li>
  </ol>
  
  <blockquote>
    <p>$returnProperties['formal_title'] = 1;</p>
  </blockquote>
  
  <p>Just curious, how to make it according to best practices of CiviCRM development. </p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-11-27T10:56:48.583Z
Comments.Text: Pls. see accepted answer at http://civicrm.stackexchange.com/questions/7783/query-php-function-modify , same answer applies here.
Comments.UserDisplayName: yurg
Tags: <developer><mailing><address-labels>
Title: Custom Mailing Labels and "Merge labels for contacts with the same address"
ThreadText: # Custom Mailing Labels and "Merge labels for contacts with the same address"
  
  (Asked by: username_0 on 2015-11-24)
  
  **This is not a duplicate of [Is it possible to change the Mailing label format?](https://civicrm.stackexchange.com/questions/4580/is-it-possible-to-change-the-mailing-label-format)**
  
  While printing Mailing Labels, we've found that Addressee Tokens don't work as expected when "Merge labels for contacts with the same address" is ticked.
  
  Mean, if one wants to get "Mr & Mrs Smith", {addressee} token should be used at **civicrm/admin/setting/preferences/address?reset=1**; we've tried to add "contact.formal\_title", but it doesn't get merged properly, only first value is printed, so it looks like:
  
  ```
   "Mr Smith Title
  Mr A & Mrs B Smith " 
  
  ```
  
  instead of
  
  ```
  Mr Smith Title  A & Mrs Smith Title B Smith
  
  ```
  
  There is a **mergeSameAddress** function at \civicrm\CRM\Core\BAO\Address.php which works with **&$rows** parameter, but there is no "formal\_title" in a $row according to **print\_r**:
  
  ```
    [contact_type] => Individual
              [display_name] => H S W
              [do_not_mail] => 0
              [first_name] => H S
              [last_name] => W
              [prefix_id] => 
              [is_deceased] => 0
              [addressee_id] => 1
              [addressee_display] => H S W
              [addressee_custom] => 
              [address_id] => 20144
              [street_address] => 111
              [supplemental_address_1] => 111
              [supplemental_address_2] => 
              [city] => 
              [postal_code_suffix] => 
              [postal_code] => 111
              [address_name] => 
              [county_id] => 
              [state_province_id] => 
              [country_id] => 1226
              [individual_prefix] => 
              [addressee] => H S W
              [county] => 
              [state_province_name] => 
              [state_province] => 
              [country] => 111
  
  ```
  
  What would be a proper way to add formal\_title as a part of a merged address value (assuming appending formal\_title to a first name)? Currently, **Prefix** works as desired, but it exists in a $rows, so can be easily retrieved. Not sure why formal\_title is not a part of this and it's not clear, where $rows data is came from.
  
  **UPDATE**
  
  Desired result has been achieved by modifying two core files:
  
  1. civicrm/CRM/Core/BAO/Address.php
  
  line 1059
  
  > 'formal\_title' => $rows[$rowID]['formal\_title'],
  
  line 1095
  
  replace
  
  > $family = trim(implode(" & ", array\_keys($first\_names)) . " " . $last\_name);
  
  to
  
  > $family = trim(implode(" & ", array\_keys($first\_names)));
  
  2. civicrm/CRM/Contact/Form/Task/Label.php
     line 167
  
  > $returnProperties['formal\_title'] = 1;
  
  Just curious, how to make it according to best practices of CiviCRM development.
  
  **Tags:** developer, mailing, address-labels
  
  > **Comments:**
  > **username_0**: Pls. see accepted answer at http://civicrm.stackexchange.com/questions/7783/query-php-function-modify , same answer applies here.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2015-11-27. Score: 3 | Accepted answer
  
  The answer is already here. According to a tiny mention at the bottom of <http://wiki.civicrm.org/confluence/display/CRMDOC/Directories> page, it is possible (and, more important, it works!) to copy modified core files to Custom PHP Path Directory (at civicrm/admin/setting/path?reset=1) , preserving original files/folders structure, so next time CiviCRM gets security updates, changes should be kept (unless original file / function major changes).
  
  
  ---
  
  