You are here

public function MailchimpCampaignForm::preview in Mailchimp 8

Same name and namespace in other branches
  1. 2.x modules/mailchimp_campaign/src/Form/MailchimpCampaignForm.php \Drupal\mailchimp_campaign\Form\MailchimpCampaignForm::preview()

Generates a preview of the campaign template content.

File

modules/mailchimp_campaign/src/Form/MailchimpCampaignForm.php, line 415

Class

MailchimpCampaignForm
Form controller for the MailchimpCampaign entity edit form.

Namespace

Drupal\mailchimp_campaign\Form

Code

public function preview(array $form, FormStateInterface $form_state) {
  $text = '';
  $template_content = $this
    ->parseTemplateContent($form_state
    ->getValue('content'));
  $content = mailchimp_campaign_render_template($template_content);
  foreach ($content as $key => $section) {
    $text .= "<h3>{$key}</h3>" . $section;
  }
  $form_state
    ->setValue('mailchimp_campaign_campaign_preview', $text);
  $form_state
    ->setRebuild(TRUE);
}