You are here

function template_preprocess_printable in Printer and PDF versions for Drupal 8+ 8

Same name and namespace in other branches
  1. 2.x printable.module \template_preprocess_printable()

Preprocess variables for list of printable printer friendly page.

Parameters

array $variables: An associative array containing:

  • elements: Array of participant names. Array keys: #base_url, #title, #html_attributes, #send_script, #include_css.

File

./printable.module, line 119
Provides printer friendly content entities.

Code

function template_preprocess_printable(array &$variables) {
  global $base_url;
  $config = \Drupal::config('printable.settings');
  $variables['base_url'] = $base_url . '/' . drupal_get_path('module', 'printable');
  $request = \Drupal::request();
  $title = '';
  if ($route = $request->attributes
    ->get(RouteObjectInterface::ROUTE_OBJECT)) {
    $title = \Drupal::service('title_resolver')
      ->getTitle($request, $route);
  }
  $variables['title'] = $title;
  $language_interface = \Drupal::languageManager()
    ->getCurrentLanguage();
  $variables['html_attributes'] = new Attribute([
    'lang' => $language_interface
      ->getId(),
    'dir' => $language_interface
      ->getDirection(),
  ]);
  if ($config
    ->get('send_to_printer')) {
    $variables['send_script'] = $variables['base_url'] . '/js/script.js';
    if ($config
      ->get('close_window')) {
      $variables['close_script'] = $variables['base_url'] . '/js/close.js';
    }
  }
  if ($include_path = \Drupal::service('printable.css_include')
    ->getCssIncludePath()) {
    $variables['include_css'] = $include_path;
  }
}