You are here

function printfriendly_page_attachments in PrintFriendly & PDF 8.2

Same name and namespace in other branches
  1. 8.3 printfriendly.module \printfriendly_page_attachments()
  2. 8 printfriendly.module \printfriendly_page_attachments()

Attach PrintFriendly Script.

File

./printfriendly.module, line 91
Adds PrintFriendly button to chosen node types and provides a block.

Code

function printfriendly_page_attachments(array &$page) {
  upgrade();
  $config = \Drupal::config('printfriendly.settings');

  // Attach JS custom 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') . "';";
  $custom_js .= "var pfPlatform = 'Drupal';";

  // Use schema less URLs to load all PF Assets
  $js = '//cdn.printfriendly.com/printfriendly.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',
  ];

  // Attach CSS
  $page['#attached']['library'][] = 'printfriendly/printfriendly-libraries';
}