/**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     global $base_url;
     $block_url = Url::fromRoute('block.admin_display');
     $page_url = Url::fromUri($base_url . '/' . $entity->settings['path']);
     $modes = NULL;
     $mc_lists = mailchimp_get_lists();
     switch ($entity->mode) {
         case MAILCHIMP_SIGNUP_BLOCK:
             $modes = \Drupal::l(t('Block'), $block_url);
             $block_only = TRUE;
             break;
         case MAILCHIMP_SIGNUP_PAGE:
             $modes = \Drupal::l(t('Page'), $page_url);
             break;
         case MAILCHIMP_SIGNUP_BOTH:
             $modes = \Drupal::l(t('Block'), $block_url) . ' and ' . \Drupal::l(t('Page'), $page_url);
             break;
     }
     $list_labels = array();
     foreach ($entity->mc_lists as $list_id) {
         if (!empty($list_id)) {
             $list_url = Url::fromUri('https://admin.mailchimp.com/lists/dashboard/overview?id=' . $mc_lists[$list_id]['web_id'], array('attributes' => array('target' => '_blank')));
             $list_labels[] = \Drupal::l($mc_lists[$list_id]['name'], $list_url);
         }
     }
     $row['label'] = $this->getLabel($entity) . ' (Machine name: ' . $entity->id() . ')';
     $row['display_modes'] = $modes;
     $row['lists'] = implode(', ', $list_labels);
     return $row + parent::buildRow($entity);
 }
Ejemplo n.º 2
0
 /**
  * Tests retrieval of a specific set of lists.
  */
 function testMultiListRetrieval()
 {
     $list_ids = array(DrupalMailchimpLists::TEST_LIST_A, DrupalMailchimpLists::TEST_LIST_B);
     $lists = mailchimp_get_lists($list_ids);
     $this->assertEqual(count($lists), 2, 'Tested correct list count on retrieval.');
     foreach ($list_ids as $list_id) {
         $this->assertTrue(isset($lists[$list_id]), 'Tested valid list ID retrieved: ' . $list_id);
         unset($lists[$list_id]);
     }
     $this->assertEqual(count($lists), 0, 'Tested all lists retrieved.');
 }
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $form = parent::form($form, $form_state);
     $signup = $this->entity;
     $form['title'] = array('#type' => 'textfield', '#title' => $this->t('Title'), '#size' => 35, '#maxlength' => 32, '#default_value' => $signup->title, '#description' => $this->t('The title for this signup form.'), '#required' => TRUE);
     $form['id'] = array('#type' => 'machine_name', '#default_value' => $signup->id, '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH, '#machine_name' => array('source' => array('title'), 'exists' => 'mailchimp_signup_load'), '#description' => t('A unique machine-readable name for this list. It must only contain lowercase letters, numbers, and underscores.'), '#disabled' => !$signup->isNew());
     $form['description'] = array('#type' => 'textarea', '#title' => 'Description', '#default_value' => isset($signup->settings['description']) ? $signup->settings['description'] : '', '#rows' => 2, '#maxlength' => 500, '#description' => t('This description will be shown on the signup form below the title. (500 characters or less)'));
     $mode_defaults = array(MAILCHIMP_SIGNUP_BLOCK => array(MAILCHIMP_SIGNUP_BLOCK), MAILCHIMP_SIGNUP_PAGE => array(MAILCHIMP_SIGNUP_PAGE), MAILCHIMP_SIGNUP_BOTH => array(MAILCHIMP_SIGNUP_BLOCK, MAILCHIMP_SIGNUP_PAGE));
     $form['mode'] = array('#type' => 'checkboxes', '#title' => 'Display Mode', '#required' => TRUE, '#options' => array(MAILCHIMP_SIGNUP_BLOCK => 'Block', MAILCHIMP_SIGNUP_PAGE => 'Page'), '#default_value' => !empty($signup->mode) ? $mode_defaults[$signup->mode] : array());
     $form['settings'] = array('#type' => 'details', '#title' => 'Settings', '#tree' => TRUE, '#open' => TRUE);
     $form['settings']['path'] = array('#type' => 'textfield', '#title' => 'Page URL', '#description' => t('Path to the signup page. ie "newsletter/signup".'), '#default_value' => isset($signup->settings['path']) ? $signup->settings['path'] : NULL, '#states' => array('visible' => array(':input[name="mode[' . MAILCHIMP_SIGNUP_PAGE . ']"]' => array('checked' => TRUE)), 'required' => array(':input[name="mode[' . MAILCHIMP_SIGNUP_PAGE . ']"]' => array('checked' => TRUE))));
     $form['settings']['submit_button'] = array('#type' => 'textfield', '#title' => 'Submit Button Label', '#required' => 'TRUE', '#default_value' => isset($signup->settings['submit_button']) ? $signup->settings['submit_button'] : 'Submit');
     $form['settings']['confirmation_message'] = array('#type' => 'textfield', '#title' => 'Confirmation Message', '#description' => 'This message will appear after a successful submission of this form. Leave blank for no message, but make sure you configure a destination in that case unless you really want to confuse your site visitors.', '#default_value' => isset($signup->settings['confirmation_message']) ? $signup->settings['confirmation_message'] : 'You have been successfully subscribed.');
     $form['settings']['destination'] = array('#type' => 'textfield', '#title' => 'Form destination page', '#description' => 'Leave blank to stay on the form page.', '#default_value' => isset($signup->settings['destination']) ? $signup->settings['destination'] : NULL);
     $form['mc_lists_config'] = array('#type' => 'details', '#title' => t('MailChimp List Selection & Configuration'), '#open' => TRUE);
     $lists = mailchimp_get_lists();
     $options = array();
     foreach ($lists as $mc_list) {
         $options[$mc_list['id']] = $mc_list['name'];
     }
     $mc_admin_url = Url::fromUri('https://admin.mailchimp.com', array('attributes' => array('target' => '_blank')));
     $form['mc_lists_config']['mc_lists'] = array('#type' => 'checkboxes', '#title' => t('MailChimp Lists'), '#description' => t('Select which lists to show on your signup form. You can create additional lists at !MailChimp.', array('!MailChimp' => \Drupal::l(t('MailChimp'), $mc_admin_url))), '#options' => $options, '#default_value' => is_array($signup->mc_lists) ? $signup->mc_lists : array(), '#required' => TRUE, '#ajax' => array('callback' => '::mergefields_callback', 'wrapper' => 'mergefields-wrapper', 'method' => 'replace', 'effect' => 'fade', 'progress' => array('type' => 'throbber', 'message' => t('Retrieving merge fields for this list.'))));
     $form['mc_lists_config']['mergefields'] = array('#prefix' => '<div id="mergefields-wrapper">', '#suffix' => '</div>');
     // Show merge fields if changing list field or editing existing list.
     if ($form_state->getValue('mc_lists') || !$signup->isNew()) {
         $form['mc_lists_config']['mergefields'] = array('#type' => 'fieldset', '#title' => t('Merge Field Display'), '#description' => t('Select the merge fields to show on registration forms. Required fields are automatically displayed.'), '#id' => 'mergefields-wrapper', '#tree' => TRUE, '#weight' => 20);
         $mc_lists = $form_state->getValue('mc_lists') ? $form_state->getValue('mc_lists') : $signup->mc_lists;
         $mergevar_options = $this->getMergevarOptions($mc_lists);
         foreach ($mergevar_options as $mergevar) {
             $form['mc_lists_config']['mergefields'][$mergevar['tag']] = array('#type' => 'checkbox', '#title' => SafeMarkup::checkPlain($mergevar['name']), '#default_value' => isset($signup->settings['mergefields'][$mergevar['tag']]) ? !empty($signup->settings['mergefields'][$mergevar['tag']]) : TRUE, '#required' => $mergevar['req'], '#disabled' => $mergevar['req']);
         }
     }
     $form['subscription_settings'] = array('#type' => 'details', '#title' => t('Subscription Settings'), '#open' => TRUE);
     $form['subscription_settings']['doublein'] = array('#type' => 'checkbox', '#title' => t('Require subscribers to Double Opt-in'), '#description' => t('New subscribers will be sent a link with an email they must follow to confirm their subscription.'), '#default_value' => isset($signup->settings['doublein']) ? $signup->settings['doublein'] : FALSE);
     $form['subscription_settings']['send_welcome'] = array('#type' => 'checkbox', '#title' => t('Send a welcome email to new subscribers'), '#description' => t('New subscribers will be sent a welcome email once they are confirmed.'), '#default_value' => isset($signup->settings['send_welcome']) ? $signup->settings['send_welcome'] : FALSE);
     $form['subscription_settings']['include_interest_groups'] = array('#type' => 'checkbox', '#title' => t('Include interest groups on subscription form.'), '#default_value' => isset($signup->settings['include_interest_groups']) ? $signup->settings['include_interest_groups'] : FALSE, '#description' => t('If set, subscribers will be able to select applicable interest groups on the signup form.'));
     return $form;
 }
 /**
  * {@inheritdoc}
  */
 public function storageSettingsForm(array &$form, FormStateInterface $form_state, $has_data)
 {
     $element = parent::storageSettingsForm($form, $form_state, $has_data);
     $lists = mailchimp_get_lists();
     $options = array('' => t('-- Select --'));
     foreach ($lists as $mc_list) {
         $options[$mc_list['id']] = $mc_list['name'];
     }
     $field_map = \Drupal::entityManager()->getFieldMap();
     $field_definitions = array();
     foreach ($field_map as $entity_type => $fields) {
         $field_definitions[$entity_type] = \Drupal::entityManager()->getFieldStorageDefinitions($entity_type);
     }
     // Prevent MailChimp lists that have already been assigned to a field
     // appearing as field options.
     foreach ($field_map as $entity_type => $fields) {
         foreach ($fields as $field_name => $field_properties) {
             if ($field_properties['type'] == 'mailchimp_lists_subscription') {
                 /* @var $field \Drupal\field\Entity\FieldStorageConfig */
                 $field = $field_definitions[$entity_type][$field_name];
                 $field_settings = $field->getSettings();
                 if ($field_name != $this->getFieldDefinition()->getName() && isset($field_settings['mc_list_id'])) {
                     unset($options[$field_settings['mc_list_id']]);
                 }
             }
         }
     }
     $refresh_lists_url = Url::fromRoute('mailchimp_lists.refresh');
     $mailchimp_url = Url::fromUri('https://admin.mailchimp.com', array('attributes' => array('target' => '_blank')));
     $element['mc_list_id'] = array('#type' => 'select', '#title' => t('MailChimp List'), '#multiple' => FALSE, '#description' => t('Available MailChimp lists which are not already
     attached to Mailchimp Subscription Fields. If there are no options,
     make sure you have created a list at !MailChimp first, then !cacheclear.', array('!MailChimp' => \Drupal::l('MailChimp', $mailchimp_url), '!cacheclear' => \Drupal::l('clear your list cache', $refresh_lists_url))), '#options' => $options, '#default_value' => $this->getSetting('mc_list_id'), '#required' => TRUE, '#disabled' => $has_data);
     $element['double_opt_in'] = array('#type' => 'checkbox', '#title' => 'Require subscribers to Double Opt-in', '#description' => 'New subscribers will be sent a link with an email they must follow to confirm their subscription.', '#default_value' => $this->getSetting('double_opt_in'), '#disabled' => $has_data);
     $element['send_welcome'] = array('#type' => 'checkbox', '#title' => 'Send a welcome email to new subscribers', '#description' => 'New subscribers will be sent a welcome email once they are confirmed.', '#default_value' => $this->getSetting('send_welcome'), '#disabled' => $has_data);
     return $element;
 }
Ejemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 public function overview()
 {
     $content = array();
     $lists_admin_url = Url::fromUri('https://admin.mailchimp.com/lists/', array('attributes' => array('target' => '_blank')));
     $lists_empty_message = t('You don\'t have any lists configured in your
   MailChimp account, (or you haven\'t configured your API key correctly on
   the Global Settings tab). Head over to !link and create some lists, then
   come back here and click "Refresh lists from MailChimp"', array('!link' => \Drupal::l(t('MailChimp'), $lists_admin_url)));
     $content['lists_table'] = array('#type' => 'table', '#header' => array(t('Name'), t('Members'), t('Webhook Status')), '#empty' => $lists_empty_message);
     $mc_lists = mailchimp_get_lists();
     $total_webhook_actions = count(mailchimp_lists_default_webhook_actions());
     foreach ($mc_lists as $mc_list) {
         $enabled_webhook_actions = count(mailchimp_lists_enabled_webhook_actions($mc_list['id']));
         $webhook_url = Url::fromRoute('mailchimp_lists.webhook', array('list_id' => $mc_list['id']));
         $webhook_status = $enabled_webhook_actions . ' of ' . $total_webhook_actions . ' enabled (' . \Drupal::l(t('update'), $webhook_url) . ')';
         $list_url = Url::fromUri('https://admin.mailchimp.com/lists/dashboard/overview?id=' . $mc_list['web_id'], array('attributes' => array('target' => '_blank')));
         $content['lists_table'][$mc_list['id']]['name'] = array('#markup' => \Drupal::l($mc_list['name'], $list_url));
         $content['lists_table'][$mc_list['id']]['member_count'] = array('#markup' => $mc_list['stats']['member_count']);
         $content['lists_table'][$mc_list['id']]['web_id'] = array('#markup' => $webhook_status);
     }
     $refresh_url = Url::fromRoute('mailchimp_lists.refresh', array('destination' => 'admin/config/services/mailchimp/lists'));
     $content['refresh_link'] = array('#markup' => \Drupal::l(t('Refresh lists from Mailchimp'), $refresh_url));
     return $content;
 }
  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    global $base_url;

    $list_details = mailchimp_get_lists($this->signup->mc_lists);

    $subscribe_lists = array();

    // Filter out blank fields so we don't erase values on the Mailchimp side.
    $merge_values = array_filter($form_state->getValue('mergevars'));

    $email = $merge_values['EMAIL'];

    $mailchimp_lists = $form_state->getValue('mailchimp_lists');

    // If we only have one list we won't have checkbox values to investigate.
    if (count(array_filter($this->signup->mc_lists)) == 1) {
      $subscribe_lists[0] = array(
        'subscribe' => reset($this->signup->mc_lists),
        'interest_groups' => isset($mailchimp_lists['interest_groups']) ? $mailchimp_lists['interest_groups'] : NULL,
      );
    }
    else {
      // We can look at the checkbox values now.
      foreach ($mailchimp_lists as $list) {
        if ($list['subscribe']) {
          $subscribe_lists[] = $list;
        }
      }
    }

    $successes = array();

    // Loop through the selected lists and try to subscribe.
    foreach ($subscribe_lists as $list_choices) {
      $list_id = $list_choices['subscribe'];
      $mergevars = $merge_values;

      if (isset($list_choices['interest_groups'])) {
        $mergevars['GROUPINGS'] = mailchimp_reformat_groupings($list_choices['interest_groups']);
      }

      $result = mailchimp_subscribe($list_id, $email, $mergevars, $this->signup->settings['doublein'], $this->signup->settings['send_welcome']);

      if (empty($result)) {
        drupal_set_message(t('There was a problem with your newsletter signup to %list.', array(
          '%list' => $list_details[$list_id]['name'],
        )), 'warning');
      }
      else {
        $successes[] = $list_details[$list_id]['name'];
      }
    }

    if (count($successes) && strlen($this->signup->settings['confirmation_message'])) {
      drupal_set_message($this->signup->settings['confirmation_message'], 'status');
    }

    $destination_url = Url::fromUri($base_url . '/' . $this->signup->settings['destination']);

    $form_state->setRedirectUrl($destination_url);
  }
Ejemplo n.º 7
0
    private function render_import_tab()
    {
        $mailchimp_apikey = get_site_option('mailchimp_apikey', '');
        $mailchimp_mailing_list = get_site_option('mailchimp_mailing_list');
        $mailchimp_ignore_plus = get_site_option('mailchimp_ignore_plus');
        $mailchimp_allow_widget = get_site_option('mailchimp_allow_widget', false);
        $mailchimp_last_imported_list = get_site_option('mailchimp_last_imported_list', $mailchimp_mailing_list);
        if (!empty($mailchimp_apikey)) {
            $api = mailchimp_load_API();
            if (is_wp_error($api)) {
                $api_error = $api->get_error_message();
            }
            $mailchimp_lists = mailchimp_get_lists();
            $api_error = !empty($api_error);
        }
        if (isset($_POST['action']) && $_POST['action'] == 'submit-import') {
            ?>
				<div class="processing_result"></div>
				<p><?php 
            _e('Importing users, please wait. This could take long depending on the number of users you have in your site...', MAILCHIMP_LANG_DOMAIN);
            ?>
</p>
			<?php 
            return;
        }
        if (is_array($mailchimp_lists) && count($mailchimp_lists)) {
            ?>
			<h3><?php 
            _e('Sync Existing Users', MAILCHIMP_LANG_DOMAIN);
            ?>
</h3>
			<span class="description"><?php 
            _e('This function will syncronize all existing users on your install with your MailChimp list, adding new ones, updating the first/last name of previously imported users, and removing spammed or deleted users from your selected list. Note you really only need to do this once after installing, it is carried on automatically after installation.', MAILCHIMP_LANG_DOMAIN);
            ?>
</span>
		<?php 
        }
        ?>

		<table class="form-table">
			<tr class="form-field form-required">
    			<th scope="row"><?php 
        _e('Mailing List', MAILCHIMP_LANG_DOMAIN);
        ?>
</th>
				<td>
					<select name="mailchimp_import_mailing_list" id="mailchimp_import_mailing_list">
						<?php 
        foreach ($mailchimp_lists as $mailchimp_list) {
            ?>
<option value="<?php 
            echo $mailchimp_list['id'];
            ?>
" <?php 
            selected($mailchimp_last_imported_list == $mailchimp_list['id']);
            ?>
><?php 
            echo $mailchimp_list['name'];
            ?>
</option><?php 
        }
        ?>
					</select><br />
					<?php 
        _e('The mailing list you want to import existing users to.', MAILCHIMP_LANG_DOMAIN);
        ?>
	            </td>
	        </tr>
				<tr class="form-field form-required">
				<th scope="row"><?php 
        _e('Auto Opt-in', MAILCHIMP_LANG_DOMAIN);
        ?>
</th>
				<td>
					<select name="mailchimp_import_auto_opt_in" id="mailchimp_import_auto_opt_in">
		                <option value="yes" ><?php 
        _e('Yes', MAILCHIMP_LANG_DOMAIN);
        ?>
</option>
		                <option value="no" ><?php 
        _e('No', MAILCHIMP_LANG_DOMAIN);
        ?>
</option>
		            </select><br />
					<?php 
        _e('Automatically opt-in new users to the mailing list. Users will not receive an email confirmation. Use at your own risk.', MAILCHIMP_LANG_DOMAIN);
        ?>
				</td>
			</tr>
		</table>
		<?php 
        submit_button(__('Import', MAILCHIMP_LANG_DOMAIN), 'primary', 'submit-mailchimp-settings');
    }
Ejemplo n.º 8
0
 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $form = parent::form($form, $form_state);
     $site_config = \Drupal::config('system.site');
     // Attach campaign JS and CSS.
     $form['#attached']['library'][] = 'mailchimp_campaign/campaign-form';
     /* @var $campaign \Drupal\mailchimp_campaign\Entity\MailchimpCampaign */
     $campaign = $this->entity;
     $form_state->set('campaign', $campaign);
     $form['title'] = array('#type' => 'textfield', '#title' => t('Title'), '#description' => t('An internal name to use for this campaign. By default, the campaign subject will be used.'), '#required' => FALSE, '#default_value' => $campaign ? $campaign->mc_data['title'] : '');
     $form['subject'] = array('#type' => 'textfield', '#title' => t('Subject'), '#required' => TRUE, '#default_value' => $campaign ? $campaign->mc_data['subject'] : '');
     $mailchimp_lists = mailchimp_get_lists();
     $form['list_id'] = array('#type' => 'select', '#title' => t('List'), '#description' => t('Select the list this campaign should be sent to.'), '#options' => $this->buildOptionList($mailchimp_lists), '#default_value' => $campaign ? $campaign->mc_data['list_id'] : -1, '#required' => TRUE, '#ajax' => array('callback' => 'Drupal\\mailchimp_campaign\\Form\\MailchimpCampaignForm::listSegmentCallback'));
     if (!empty($form_state->getValue('list_id'))) {
         $list_id = $form_state->getValue('list_id');
     } elseif ($campaign && $campaign->mc_data) {
         $list_id = $campaign->mc_data['list_id'];
         if (isset($campaign->mc_data['saved_segment']['id'])) {
             $segment_id = $campaign->mc_data['saved_segment']['id'];
         }
     }
     $list_segments = array();
     if (isset($list_id)) {
         $list_segments = mailchimp_campaign_get_list_segments($list_id, 'saved');
     }
     if (!empty($list_segments)) {
         $form['list_segment_id'] = array('#type' => 'select', '#title' => t('List Segment'), '#description' => t('Select the list segment this campaign should be sent to.'), '#options' => $this->buildOptionList($list_segments, '-- Entire list --'), '#default_value' => isset($segment_id) ? $segment_id : '');
     } else {
         $form['list_segment_id'] = array();
     }
     $form['list_segment_id']['#prefix'] = '<div id="list-segments-wrapper">';
     $form['list_segment_id']['#suffix'] = '</div>';
     $form['from_email'] = array('#type' => 'textfield', '#title' => t('From Email'), '#description' => t('the From: email address for your campaign message.'), '#default_value' => !empty($campaign->mc_data) ? $campaign->mc_data['from_email'] : $site_config->get('mail'), '#size' => 40, '#maxlength' => 255, '#required' => TRUE);
     $form['from_name'] = array('#type' => 'textfield', '#title' => t('From Name'), '#description' => t('the From: name for your campaign message (not an email address)'), '#default_value' => !empty($campaign->mc_data) ? $campaign->mc_data['from_name'] : $site_config->get('name'), '#size' => 40, '#maxlength' => 255, '#required' => TRUE);
     $template_type_labels = array('user' => 'My Custom Templates', 'basic' => 'Basic Templates', 'gallery' => 'Themes');
     $form['template_id'] = array('#type' => 'select', '#title' => t('Template'), '#description' => t('Select a MailChimp user template to use. Due to a limitation in the API, only templates that do not contain repeating sections are available. If empty, the default template will be applied.'), '#options' => $this->buildOptionList(mailchimp_campaign_list_templates(), '-- Select --', $template_type_labels), '#default_value' => $campaign ? $campaign->mc_data['template_id'] : -1, '#ajax' => array('callback' => 'Drupal\\mailchimp_campaign\\Form\\MailchimpCampaignForm::templateCallback'));
     $form['content'] = array('#id' => 'content-sections', '#type' => 'fieldset', '#title' => t('Content sections'), '#description' => t('The HTML content or, if a template is selected, the content for each section.'), '#tree' => TRUE);
     $mc_template = NULL;
     if (!empty($form_state->getValue('template_id'))) {
         $mc_template = mailchimp_campaign_get_template($form_state->getValue('template_id'));
     } else {
         if ($campaign && $campaign->mc_template) {
             $mc_template = $campaign->mc_template;
         }
     }
     if (isset($list_id)) {
         $merge_vars_list = mailchimp_get_mergevars(array($list_id));
         $merge_vars = $merge_vars_list[$list_id]['merge_vars'];
     } else {
         $merge_vars = array();
     }
     $campaign_template = $campaign->getTemplate();
     $campaign_content = $form_state->getValue('content');
     $entity_type = NULL;
     if ($mc_template) {
         if (strpos($mc_template['info']['source'], 'mc:repeatable')) {
             drupal_set_message(t('WARNING: This template has repeating sections, which are not supported. You may want to select a different template.'), 'warning');
         }
         foreach ($mc_template['info']['default_content'] as $section => $content) {
             // Set the default value and text format to either saved campaign values
             // or defaults coming from the MailChimp template.
             $default_value = $content;
             $format = 'mailchimp_campaign';
             if ($campaign_template != NULL && isset($campaign_template[$section])) {
                 $default_value = $campaign_template[$section]['value'];
                 $format = $campaign_template[$section]['format'];
             }
             $form['content'][$section . '_wrapper'] = array('#type' => 'details', '#title' => SafeMarkup::checkPlain(ucfirst($section)), '#open' => FALSE);
             $form['content'][$section . '_wrapper'][$section] = array('#type' => 'text_format', '#format' => $format, '#title' => SafeMarkup::checkPlain(ucfirst($section)), '#default_value' => $default_value);
             if (isset($campaign_content[$section . '_wrapper']['entity_import']['entity_type'])) {
                 $entity_type = $campaign_content[$section . '_wrapper']['entity_import']['entity_type'];
             }
             $form['content'][$section . '_wrapper'] += $this->getEntityImportFormElements($entity_type, $section);
             if (!empty($list_id)) {
                 $form['content'][$section . '_wrapper'] += $this->getMergeVarsFormElements($merge_vars, $mailchimp_lists[$list_id]['name']);
             }
         }
     } else {
         $section = 'html';
         $form['content']['html_wrapper'] = array('#type' => 'details', '#title' => t('Content'), '#open' => FALSE);
         $form['content']['html_wrapper']['html'] = array('#type' => 'text_format', '#format' => $campaign_template != NULL ? $campaign_template['html']['format'] : 'mailchimp_campaign', '#title' => t('Content'), '#description' => t('The HTML content of the campaign.'), '#access' => empty($form_state->getValue('template_id')), '#default_value' => $campaign_template != NULL ? $campaign_template['html']['value'] : '');
         if (isset($campaign_content[$section . '_wrapper']['entity_import']['entity_type'])) {
             $entity_type = $campaign_content[$section . '_wrapper']['entity_import']['entity_type'];
         }
         $form['content'][$section . '_wrapper'] += $this->getEntityImportFormElements($entity_type, $section);
         $list_name = !empty($list_id) ? $mailchimp_lists[$list_id]['name'] : '';
         $form['content'][$section . '_wrapper'] += $this->getMergeVarsFormElements($merge_vars, $list_name);
     }
     // Message preview:
     if (!empty($form_state->getValue('mailchimp_campaign_campaign_preview'))) {
         $form['preview_wrapper'] = array('#title' => t('Campaign content preview'), '#type' => 'details', '#open' => TRUE);
         $form['preview_wrapper']['preview'] = array('#markup' => $form_state->getValue('mailchimp_campaign_campaign_preview'));
     }
     return $form;
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     mailchimp_get_lists(array(), TRUE);
     drupal_set_message(t('MailChimp lists cache cleared.'));
 }