function mailchimp_campaign_get_list_segments in Mailchimp 8
Same name and namespace in other branches
- 7.5 modules/mailchimp_campaign/mailchimp_campaign.module \mailchimp_campaign_get_list_segments()
- 7.3 modules/mailchimp_campaign/mailchimp_campaign.module \mailchimp_campaign_get_list_segments()
- 7.4 modules/mailchimp_campaign/mailchimp_campaign.module \mailchimp_campaign_get_list_segments()
- 2.x modules/mailchimp_campaign/mailchimp_campaign.module \mailchimp_campaign_get_list_segments()
Gets an array of list segments for a given list ID.
Parameters
int $list_id: The list ID.
string $type: The segment type to get. "static" or "saved".
Return value
array Array of Mailchimp list segments.
2 calls to mailchimp_campaign_get_list_segments()
- MailchimpCampaignForm::form in modules/
mailchimp_campaign/ src/ Form/ MailchimpCampaignForm.php - Gets the actual form array to be built.
- MailchimpCampaignViewBuilder::view in modules/
mailchimp_campaign/ src/ Entity/ MailchimpCampaignViewBuilder.php - Builds the render array for the provided entity.
File
- modules/
mailchimp_campaign/ mailchimp_campaign.module, line 450 - Module file for mailchimp_campaign.
Code
function mailchimp_campaign_get_list_segments($list_id, $type) {
/* @var \Mailchimp\MailchimpLists $mcapi */
$mcapi = mailchimp_get_api_object('MailchimpLists');
$parameters = [
'type' => $type,
'count' => 500,
];
try {
$response = $mcapi
->getSegments($list_id, $parameters);
} catch (\Exception $e) {
\Drupal::messenger()
->addError($e
->getMessage());
\Drupal::logger('mailchimp_campaign')
->error('An error occurred getting list segments for list ID {list_id}: {message} ', [
'list_id' => $list_id,
'message' => $e
->getMessage(),
]);
return NULL;
}
return $response->segments;
}