Skip to content
Snippets Groups Projects
Commit 6ddb0988 authored by Dan Ruscoe's avatar Dan Ruscoe
Browse files

Add Connected Sites integration.

parent 9945d03f
No related branches found
Tags 8.x-1.6
No related merge requests found
......@@ -42,7 +42,7 @@ function mailchimp_admin_settings() {
}
}
$form['connected_sites']['sites'] = array(
$form['connected_sites']['config'] = array(
'#type' => 'container',
'#states' => array(
'invisible' => array(
......@@ -54,12 +54,20 @@ function mailchimp_admin_settings() {
if (!empty($connected_sites_options)) {
// If the MailChimp account contains connected sites, allow the user to
// choose one here.
$form['connected_sites']['sites']['mailchimp_connected_id'] = array(
$form['connected_sites']['config']['mailchimp_connected_id'] = array(
'#type' => 'radios',
'#options' => $connected_sites_options,
'#default_value' => variable_get('mailchimp_connected_id', FALSE),
'#prefix' => t('<p><b>Choose a connected site from your MailChimp account.</b></p>'),
);
// Allow the user to configure which paths to embed JavaScript on.
$form['connected_sites']['config']['mailchimp_connected_paths'] = array(
'#type' => 'textarea',
'#default_value' => variable_get('mailchimp_connected_paths', FALSE),
'#prefix' => t("<p><b>Configure paths to embed MailChimp's JavaScript code on.</b></p>"),
'#description' => t('Specify pages using their paths. Enter one path per line. <front> is the front page. If you have created a pop-up subscription form in MailChimp, it will appear on paths defined here.'),
);
}
else {
// If the MailChimp account does not contain any connected sites, gently
......
......@@ -1863,3 +1863,38 @@ function mailchimp_format_date($input) {
return NULL;
}
}
/**
* Implements hook_page_build().
*/
function mailchimp_page_build(&$page) {
// Insert JavaScript for MailChimp Connected Sites, if enabled.
if (variable_get('mailchimp_enable_connected', FALSE)) {
// Limit JavaScript embed to pre-configured paths.
$connected_site_paths = variable_get('mailchimp_connected_paths', FALSE);
$valid_paths = explode("\r\n", $connected_site_paths);
$path = current_path();
if ((drupal_is_front_page() && in_array('<front>', $valid_paths)) || in_array($path, $valid_paths)) {
$connected_site_id = variable_get('mailchimp_connected_id', FALSE);
if (!empty($connected_site_id)) {
/* @var \Mailchimp\MailchimpConnectedSites $mc_connected */
$mc_connected = mailchimp_get_api_object('MailchimpConnectedSites');
// Verify Connected Site exists on the MailChimp side and insert JS.
$connected_site = $mc_connected->getConnectedSite($connected_site_id);
if (!empty($connected_site)) {
$mcjs = array(
'#type' => 'markup',
'#markup' => $connected_site->site_script->fragment,
);
drupal_add_html_head($mcjs, 'mcjs');
}
}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment