You are here

function _webform_entity_print_webform_submission_template in Webform 6.x

Same name and namespace in other branches
  1. 8.5 modules/webform_entity_print/webform_entity_print.module \_webform_entity_print_webform_submission_template()

Build Webform Entity Print template.

Parameters

array &$build: A renderable array representing the entity content.

\Drupal\Core\Entity\EntityInterface $entity: The entity object being rendered.

\Drupal\Core\Entity\Display\EntityViewDisplayInterface $display: The entity view display holding the display options configured for the entity components.

1 call to _webform_entity_print_webform_submission_template()
webform_entity_print_webform_submission_view_alter in modules/webform_entity_print/webform_entity_print.module
Implements hook_ENTITY_TYPE_view_alter() for webform_submission entities.

File

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

Code

function _webform_entity_print_webform_submission_template(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display) {

  /** @var \Drupal\webform\WebformThirdPartySettingsManagerInterface $third_party_settings_manager */
  $third_party_settings_manager = \Drupal::service('webform.third_party_settings_manager');
  $default_template_settings = $third_party_settings_manager
    ->getThirdPartySetting('webform_entity_print', 'template') ?: [];
  $webform_template_settings = $entity
    ->getWebform()
    ->getThirdPartySetting('webform_entity_print', 'template') ?: [];
  $template = array_filter($webform_template_settings) + array_filter($default_template_settings);

  /** @var \Drupal\webform\WebformTokenManagerInterface $token_manager */
  $token_manager = \Drupal::service('webform.token_manager');
  $template = $token_manager
    ->replace($template, $entity);

  // Header.
  if (!empty($template['header'])) {
    $build['webform_entity_print_header'] = [
      '#type' => 'container',
      '#attributes' => [
        'class' => [
          'webform-entity-print-header',
        ],
      ],
      '#markup' => $template['header'],
      '#weight' => -20,
    ];
  }

  // Footer.
  if (!empty($template['footer'])) {
    $build['webform_entity_print_footer'] = [
      '#type' => 'container',
      '#attributes' => [
        'class' => [
          'webform-entity-print-footer',
        ],
      ],
      '#markup' => $template['footer'],
      '#weight' => 20,
    ];
  }
}