protected function CampaignMonitorCampaignSendForm::createHtmlFile in Campaign Monitor 8
Create the file that campaign monitor will use for the campaign.
Parameters
array $settings:
object $node:
Return value
Web accessible filepath of saved file
1 call to CampaignMonitorCampaignSendForm::createHtmlFile()
- CampaignMonitorCampaignSendForm::submitForm in modules/
campaignmonitor_campaign/ src/ Form/ CampaignMonitorCampaignSendForm.php - Form submission handler.
File
- modules/
campaignmonitor_campaign/ src/ Form/ CampaignMonitorCampaignSendForm.php, line 133
Class
- CampaignMonitorCampaignSendForm
- Campaign Monitor send form.
Namespace
Drupal\campaignmonitor_campaign\FormCode
protected function createHtmlFile($settings, $node) {
$config = \Drupal::config('campaignmonitor_campaign.settings');
$view_builder = \Drupal::entityTypeManager()
->getViewBuilder('node');
$render_array = $view_builder
->view($node, $settings['view_mode']);
$theme = \Drupal::service('theme.manager')
->getActiveTheme();
$renderer = \Drupal::service('bare_html_page_renderer');
$libraries = $theme
->getLibraries();
// Foreach ($libraries as $library) {
// $render_array['#attached']['library'][] = $library;
// }.
$render_array['#attached']['library'][] = $config
->get('css_library');
$render_array['#attached']['html_response_attachment_placeholders'] = [
'styles' => '[styles]',
];
$html = render($render_array);
// Add the document theme wrapper.
$template_array = [
'#html' => $html
->__toString(),
'#theme' => 'campaignmonitor_campaign_html',
];
$template = render($template_array);
$response = new HtmlResponse();
$response
->setContent($template_array);
// Process attachments, because this does not go via the regular render
// pipeline, but will be sent directly.
$response
->setAttachments($render_array['#attached']);
$response = $this->htmlResponseAttachmentsProcessor
->processAttachments($response);
$contents = $response
->getContent();
// Save the contents to a file in the public file directory.
$filepath = campaignmonitor_campaign_get_filepath($node);
file_put_contents($filepath, $contents);
return campaignmonitor_campaign_get_filepath($node, 'path');
}