function printfriendly_page_attachments in PrintFriendly & PDF 8
Same name and namespace in other branches
- 8.3 printfriendly.module \printfriendly_page_attachments()
- 8.2 printfriendly.module \printfriendly_page_attachments()
Attach PrintFriendly Script.
File
- ./
printfriendly.module, line 34 - Adds PrintFriendly button to chosen node types and provides a block.
Code
function printfriendly_page_attachments(array &$page) {
$config = \Drupal::config('printfriendly.settings');
$custom_js = "var pfHeaderImgUrl = '" . $config
->get('printfriendly_page_custom_header') . "';";
$custom_js .= "var pfHeaderTagline = '" . $config
->get('printfriendly_tagline') . "';";
$custom_js .= "var pfdisableClickToDel = " . $config
->get('printfriendly_click_delete') . ";";
$custom_js .= "var pfHideImages = " . $config
->get('printfriendly_images') . ";";
$custom_js .= "var pfImageDisplayStyle = '" . $config
->get('printfriendly_image_style') . "';";
$custom_js .= "var pfDisablePDF = " . $config
->get('printfriendly_pdf') . ";";
$custom_js .= "var pfDisableEmail = " . $config
->get('printfriendly_email') . ";";
$custom_js .= "var pfDisablePrint = " . $config
->get('printfriendly_print') . ";";
$custom_js .= "var pfCustomCSS = '" . $config
->get('printfriendly_custom_css') . "';";
$js = 'http://cdn.printfriendly.com/printfriendly.js';
if ($config
->get('printfriendly_website_protocol') == 'https') {
$js = 'https://pf-cdn.printfriendly.com/ssl/main.js';
}
$custom_js .= "(function(){var js, pf;pf = document.createElement('script');pf.type = 'text/javascript';";
$custom_js .= "pf.src='" . $js . "';document.getElementsByTagName('head')[0].appendChild(pf)})();";
$page['#attached']['html_head'][] = [
[
'#tag' => 'script',
'#value' => $custom_js,
],
'declare_printfriendly_inline',
];
}