function mailchimp_campaign_delete_campaign in Mailchimp 8
Same name and namespace in other branches
- 7.5 modules/mailchimp_campaign/mailchimp_campaign.module \mailchimp_campaign_delete_campaign()
- 7.2 modules/mailchimp_campaign/mailchimp_campaign.module \mailchimp_campaign_delete_campaign()
- 7.3 modules/mailchimp_campaign/mailchimp_campaign.module \mailchimp_campaign_delete_campaign()
- 7.4 modules/mailchimp_campaign/mailchimp_campaign.module \mailchimp_campaign_delete_campaign()
- 2.x modules/mailchimp_campaign/mailchimp_campaign.module \mailchimp_campaign_delete_campaign()
Delete a Mailchimp campaign and the local entity.
1 call to mailchimp_campaign_delete_campaign()
- MailchimpCampaignDeleteForm::submitForm in modules/
mailchimp_campaign/ src/ Form/ MailchimpCampaignDeleteForm.php - This is the default entity object builder function. It is called before any other submit handler to build the new entity object to be used by the following submit handlers. At this point of the form workflow the entity is validated and the form state…
File
- modules/
mailchimp_campaign/ mailchimp_campaign.module, line 232 - Module file for mailchimp_campaign.
Code
function mailchimp_campaign_delete_campaign(MailchimpCampaign $campaign) {
/* @var \Mailchimp\MailchimpCampaigns $mcapi */
$mcapi = mailchimp_get_api_object('MailchimpCampaigns');
$result = NULL;
// Delete campaign from Mailchimp.
try {
if (!$mcapi) {
throw new Exception('Cannot delete campaign without Mailchimp API. Check API key has been entered.');
}
$mcapi
->delete($campaign->mc_data->id);
$campaign
->delete();
return TRUE;
} catch (\Exception $e) {
\Drupal::messenger()
->addError($e
->getMessage());
\Drupal::logger('mailchimp_campaign')
->error('An error occurred while deleting this campaign: {message}', [
'message' => $e
->getMessage(),
]);
return FALSE;
}
}