You are here

function webform_entity_print_preprocess_entity_print in Webform 8.5

Same name and namespace in other branches
  1. 6.x modules/webform_entity_print/webform_entity_print.module \webform_entity_print_preprocess_entity_print()

Implements hook_preprocess_entity_print().

File

modules/webform_entity_print/webform_entity_print.module, line 182
Provides Entity Print (PDF) integration.

Code

function webform_entity_print_preprocess_entity_print(array &$variables) {
  $webform_submission = _webform_entity_print_preprocess_entity_print_get_webform_submission($variables['content']);
  if (!$webform_submission) {
    return;
  }

  // Add webform submission to variables.
  $variables['webform_submission'] = $webform_submission;
  $webform = $webform_submission
    ->getWebform();
  $css = [];

  // Add webform CSS.
  $assets = $webform
    ->getAssets();
  if ($assets['css']) {
    $css[] = $assets['css'];
  }

  // Add webform entity print CSS.

  /** @var \Drupal\webform\WebformThirdPartySettingsManagerInterface $third_party_settings_manager */
  $third_party_settings_manager = \Drupal::service('webform.third_party_settings_manager');

  // Append default print template CSS.
  $default_template = $third_party_settings_manager
    ->getThirdPartySetting('webform_entity_print', 'template') ?: [];
  if (!empty($default_template['css'])) {
    $css[] = $default_template['css'];
  }

  // Append webform print template CSS.
  $webform_template = $webform
    ->getThirdPartySetting('webform_entity_print', 'template') ?: [];
  if (!empty($webform_template['css'])) {
    $css[] = $webform_template['css'];
  }

  // Append a style tag to entity print CSS link tags.
  $variables['entity_print_css'] = Markup::create($variables['entity_print_css'] . PHP_EOL . '<style type="text/css" media="all">' . PHP_EOL . implode(PHP_EOL, $css) . PHP_EOL . '</style>' . PHP_EOL);
}