This is not a duplicate of 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:
- 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)));
- 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.