PDF fields out of order

Created on 15 March 2023, over 1 year ago
Updated 13 June 2023, over 1 year ago

Problem/Motivation

We have successfully setup a webform with a PDF attachment. This PDF works as desired when it is attached to an email. However if we make this PDF visible as a link when viewing the submission for authorized users, the fields are sorted by key instead of using the weight as laid out in the webform.

Steps to reproduce

Setup a PDF attachment for a webform that will email the completed webform as an attachment to a target email address. Sort the webform fields in a different order than by key. Observer that the emailed PDF is correct, but viewing the attached PDF in a submission in incorrect.

Proposed resolution

Correct the sort when viewing the link to the PDF vs an attachment.

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Closed: works as designed

Version

6.1

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States srees

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @srees
  • πŸ‡ΊπŸ‡ΈUnited States srees
  • Status changed to Needs review over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States srees

    I'm not sure this is the best way to solve it, but I've written a patch that is working for me.

  • Status changed to Closed: works as designed over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States jrockowitz Brooklyn, NY

    It seems like you are doing some custom theming. You should use webform elements to sort the fields in the Twig template or create a custom preprocessor that sorts the submission data.

    /**
     * Implements hook_preprocess_entity_print().
     */
    function THEME_preprocess_entity_print(array &$variables) {
      $webform_submission = _webform_entity_print_preprocess_entity_print_get_webform_submission($variables['content']);
      if (!$webform_submission) {
        return;
      }
    
      // Order the submission data to match the Webform fields
      $get_data = $webform_submission->getData();
      $set_data = array();
      foreach (array_keys($webform_submission->getWebform()->getElementsDecodedAndFlattened()) as $key){
        if(isset($get_data[$key])){
          $set_data[$key] = $get_data[$key];
        }
      }
      $webform_submission->setData($set_data);
      $variables['webform_submission'] = $webform_submission;
    }
  • πŸ‡ΊπŸ‡ΈUnited States srees

    I do not understand how this cannot be a bug. Did you try my steps to reproduce? The only "custom" thing I'm doing is taking advantage of the option within the attached PDF field to generate output from embedded TWIG.

    The twig template is receiving the data in the order it is set in the webform. This is expected. However viewing a link to the PDF is in order of key, which is not expected. These should be uniform without me having to customize through a hook.

    I'm not even asking that the TWIG template be honored in the online version of the PDF (though that would be logical). Just that data be provided in a consistent format.

Production build 0.71.5 2024