Skip to content

Commit

Permalink
dev/core#3463 - CiviMail - prefer frontend_title from group for maili…
Browse files Browse the repository at this point in the history
…ng.group token
  • Loading branch information
ufundo committed May 25, 2022
1 parent 2648645 commit b9f2127
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions CRM/Mailing/BAO/Mailing.php
Original file line number Diff line number Diff line change
Expand Up @@ -1419,22 +1419,25 @@ public function &getGroupNames() {
if (!isset($this->id)) {
return [];
}
$mg = new CRM_Mailing_DAO_MailingGroup();
$mgtable = CRM_Mailing_DAO_MailingGroup::getTableName();
$group = CRM_Contact_BAO_Group::getTableName();

$mg->query("SELECT $group.title as name FROM $mgtable
INNER JOIN $group ON $mgtable.entity_id = $group.id
WHERE $mgtable.mailing_id = {$this->id}
AND $mgtable.entity_table = '$group'
AND $mgtable.group_type = 'Include'
ORDER BY $group.name");
$mailingGroups = \Civi\Api4\MailingGroup::get()
->addSelect('group.title', 'group.frontend_title')
->addJoin('Group AS group', 'LEFT', ['entity_id', '=', 'group.id'])
->addWhere('mailing_id', '=', $this->id)
->addWhere('entity_table', '=', 'civicrm_group')
->addWhere('group_type', '=', 'Include')
->execute();

$groupNames = [];

$groups = [];
while ($mg->fetch()) {
$groups[] = $mg->name;
foreach ($mailingGroups as $mg) {
$name = $mg['group.frontend_title'] ?? $mg['group.title'];
if ($name) {
$groupNames[] = $name;
}
}
return $groups;

return $groupNames;
}

/**
Expand Down

0 comments on commit b9f2127

Please sign in to comment.