/**
  * {@inheritdoc}
  */
 public function view(EntityInterface $entity, $view_mode = 'full', $langcode = NULL)
 {
     $build = parent::view($entity, $view_mode, $langcode);
     if ($view_mode == 'mail') {
         // Convert field labels into headings.
         // @todo Improve drupal_html_to_text() to convert DIVs correctly.
         foreach (Element::children($build) as $key) {
             if (isset($build[$key]['#label_display']) && $build[$key]['#label_display'] == 'above') {
                 $build[$key] += array('#prefix' => '');
                 $build[$key]['#prefix'] = $build[$key]['#title'] . ":\n";
                 $build[$key]['#label_display'] = 'hidden';
             }
         }
         $build = array('#markup' => drupal_html_to_text(drupal_render($build)));
     }
     return $build;
 }
Esempio n. 2
1
 /**
  * {@inheritdoc}
  */
 public function view(EntityInterface $entity, $view_mode = 'full', $langcode = NULL)
 {
     $build = parent::view($entity, $view_mode, $langcode);
     if ($view_mode == 'mail') {
         // Convert field labels into headings.
         // @todo Improve \Drupal\Core\Mail\MailFormatHelper::htmlToText() to
         // convert DIVs correctly.
         foreach (Element::children($build) as $key) {
             if (isset($build[$key]['#label_display']) && $build[$key]['#label_display'] == 'above') {
                 $build[$key] += array('#prefix' => '');
                 $build[$key]['#prefix'] = $build[$key]['#title'] . ":\n";
                 $build[$key]['#label_display'] = 'hidden';
             }
         }
         $build['#post_render'][] = function ($html, array $elements) {
             return MailFormatHelper::htmlToText($html);
         };
     }
     return $build;
 }
 /**
  * {@inheritdoc}
  */
 public function view(EntityInterface $entity, $view_mode = 'full', $langcode = NULL)
 {
     $build = parent::view($entity, $view_mode, $langcode);
     // Attach campaign JS and CSS.
     $build['#attached']['library'][] = 'mailchimp_campaign/campaign-view';
     // Prepare rendered content.
     /* @var $entity \Drupal\mailchimp_campaign\Entity\MailchimpCampaign */
     $content = $this->renderTemplate($entity->getTemplate());
     $rendered = '';
     foreach ($content as $key => $section) {
         $rendered .= "<h3>{$key}</h3>" . $section;
     }
     // Get the template name.
     $mc_template = mailchimp_campaign_get_template($entity->mc_data['template_id']);
     $mc_template_name = isset($mc_template) ? $mc_template['name'] : '';
     $list_segment_name = 'N/A';
     $list_segments = mailchimp_campaign_get_list_segments($entity->list['id'], 'saved');
     if (isset($entity->mc_data['saved_segment']['id'])) {
         foreach ($list_segments as $list_segment) {
             if ($list_segment['id'] == $entity->mc_data['saved_segment']['id']) {
                 $list_segment_name = $list_segment['name'];
             }
         }
     }
     $list_url = Url::fromUri('https://admin.mailchimp.com/lists/dashboard/overview?id=' . $entity->list['web_id'], array('attributes' => array('target' => '_blank')));
     $archive_url = Url::fromUri($entity->mc_data['archive_url']);
     $fields = array('subject' => array('label' => t('Subject'), 'value' => $entity->mc_data['subject']), 'list' => array('label' => t('MailChimp List'), 'value' => \Drupal::l($entity->list['name'], $list_url)), 'list_segment' => array('label' => t('List Segment'), 'value' => $list_segment_name), 'from_email' => array('label' => t('From Email'), 'value' => $entity->mc_data['from_email']), 'from_name' => array('label' => t('From Name'), 'value' => $entity->mc_data['from_name']), 'template' => array('label' => t('Template'), 'value' => $mc_template_name), 'type' => array('label' => t('List type'), 'value' => $entity->mc_data['type']), 'status' => array('label' => t('Status'), 'value' => $entity->mc_data['status']), 'emails_sent' => array('label' => t('Emails sent'), 'value' => $entity->mc_data['emails_sent']), 'send_time' => array('label' => t('Send time'), 'value' => $entity->mc_data['send_time']), 'content' => array('label' => t('Rendered template HTML (!archive)', array('!archive' => \Drupal::l('View MailChimp archive', $archive_url, array('attributes' => array('target' => '_blank'))))), 'value' => $rendered));
     foreach ($fields as $key => $field) {
         $build[$key] = array('#prefix' => "<div class=\"field campaign-{$key}\"><h3 class=\"field-label\">{$field['label']}</h3>", '#markup' => "<p>{$field['value']}</p>", '#suffix' => '</div>');
     }
     return $build;
 }