From b9f2127bceab4b16fa59b37890ac11a3888bd548 Mon Sep 17 00:00:00 2001 From: ufundo Date: Tue, 24 May 2022 19:20:37 +0000 Subject: [PATCH] dev/core#3463 - CiviMail - prefer frontend_title from group for mailing.group token --- CRM/Mailing/BAO/Mailing.php | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/CRM/Mailing/BAO/Mailing.php b/CRM/Mailing/BAO/Mailing.php index 83ddc6dad5..7dde359c36 100644 --- a/CRM/Mailing/BAO/Mailing.php +++ b/CRM/Mailing/BAO/Mailing.php @@ -1419,22 +1419,25 @@ ORDER BY civicrm_email.is_bulkmail DESC 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; } /** -- 2.25.1