function mailchimp_campaign_get_template in Mailchimp 8
Same name and namespace in other branches
- 7.5 modules/mailchimp_campaign/mailchimp_campaign.module \mailchimp_campaign_get_template()
- 7.3 modules/mailchimp_campaign/mailchimp_campaign.module \mailchimp_campaign_get_template()
- 7.4 modules/mailchimp_campaign/mailchimp_campaign.module \mailchimp_campaign_get_template()
- 2.x modules/mailchimp_campaign/mailchimp_campaign.module \mailchimp_campaign_get_template()
Return full details for a Mailchimp Template.
Parameters
string $template_id: Optional template ID. Set to return a single Mailchimp template.
bool $reset: True if templates should not be loaded from cache.
Return value
mixed An array with all configuration and content for a Mailchimp Template.
3 calls to mailchimp_campaign_get_template()
- 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.
- mailchimp_campaign_entity_storage_load in modules/
mailchimp_campaign/ mailchimp_campaign.module - Implements hook_entity_storage_load().
File
- modules/
mailchimp_campaign/ mailchimp_campaign.module, line 318 - Module file for mailchimp_campaign.
Code
function mailchimp_campaign_get_template($template_id, $reset = FALSE) {
$all_templates = mailchimp_campaign_list_templates($reset);
foreach ($all_templates as $type) {
if (isset($type[$template_id])) {
$template = $type[$template_id];
// Get template details from cache or the Mailchimp API.
$cache = $reset ? NULL : \Drupal::cache()
->get('template_' . $template_id, 'cache_mailchimp');
if ($cache) {
$template->info = $cache->data;
}
else {
/* @var \Mailchimp\MailchimpTemplates $mc_templates */
if ($mc_templates = mailchimp_get_api_object('MailchimpTemplates')) {
$template->info = $mc_templates
->getTemplateContent($template_id);
$tags = [
'cache_mailchimp',
];
\Drupal::cache()
->set('template_' . $template_id, $template->info, CacheBackendInterface::CACHE_PERMANENT, $tags);
}
}
return $template;
}
}
return NULL;
}