improve newsletter subcription result values

This commit is contained in:
Marc Michalsky 2024-06-06 15:08:44 +02:00
parent 221f9c72f3
commit 90f27f70c7
Signed by untrusted user who does not match committer: marc.koch
GPG key ID: 12406554CFB028B9

View file

@ -526,7 +526,7 @@ function civicrm_api3_twingle_donation_Submit($params) {
// If usage of double opt-in is selected, use MailingEventSubscribe.create // If usage of double opt-in is selected, use MailingEventSubscribe.create
// to add contact to newsletter groups defined in the profile // to add contact to newsletter groups defined in the profile
$result_values['newsletter']['newsletter_double_opt_in'] $result_values['newsletter_double_opt_in']
= (bool) $profile->getAttribute('newsletter_double_opt_in') = (bool) $profile->getAttribute('newsletter_double_opt_in')
? 'true' ? 'true'
: 'false'; : 'false';
@ -555,7 +555,7 @@ function civicrm_api3_twingle_donation_Submit($params) {
] ]
)['visibility'] == 'Public Pages'; )['visibility'] == 'Public Pages';
if (!in_array($group_id, $group_memberships, FALSE) && $is_public_group) { if (!in_array($group_id, $group_memberships, FALSE) && $is_public_group) {
$result_values['newsletter'][][$group_id] = civicrm_api3( $result = civicrm_api3(
'MailingEventSubscribe', 'MailingEventSubscribe',
'create', 'create',
[ [
@ -564,9 +564,12 @@ function civicrm_api3_twingle_donation_Submit($params) {
'contact_id' => $contact_id, 'contact_id' => $contact_id,
] ]
); );
$subscription = CRM_Utils_Array::first($result['values']);
$subscription['group_id'] = $group_id;
$result_values['newsletter_subscriptions'][] = $subscription;
} }
elseif ($is_public_group) { elseif ($is_public_group) {
$result_values['newsletter'][] = $group_id; $result_values['newsletter_group_ids'][] = $group_id;
} }
} }
// If requested, add contact to newsletter groups defined in the profile. // If requested, add contact to newsletter groups defined in the profile.
@ -584,8 +587,7 @@ function civicrm_api3_twingle_donation_Submit($params) {
'contact_id' => $contact_id, 'contact_id' => $contact_id,
] ]
); );
$result_values['newsletter_group_ids'][] = $group_id;
$result_values['newsletter'][] = $group_id;
} }
} }