[Translations] Getting elements for a translated webforms gives an incomplete elements list sometimes

Created on 11 May 2022, about 2 years ago
Updated 29 April 2024, about 2 months ago

Problem/Motivation

There is a webform on a site, where the webform is created in french and it's translated into dutch. These webforms are regularly exported in a CSV file. For this, we fetch the webform data through \Drupal\beobank_api\Utility\SubmissionBase::getFormData on the submission first. Then through the form data, we fetch the webform through \Drupal\webform\Entity\WebformSubmission::getWebform.

Now we notice that not all fields are exported. Looking further, we see only elements that have actually translated labels are exported.

It seems \Drupal\webform\Entity\Webform::initElementsTranslation can't get all the elements, since the webform object has in both elements and elementsOriginal, the translated elements, but no elements for which no translated configuration is stored.

Part of it is because that's the way data is fetched in \Drupal\Core\Config\Entity\ConfigEntityStorage::doLoadMultiple, so there's not much that can be done there I fear. Unless a major change in \Drupal\webform\Entity\Webform::postLoad is done.

However in \Drupal\webform\Entity\Webform::getElementsDecodedAndFlattened or in \Drupal\webform\Entity\Webform::initElements something could be done about this maybe.

Steps to reproduce

  • Create a webform in any language
  • Add two simple elements, e.g. type text. Give both of them a simple label
  • Translate the webform and make sure only one of the elements gets translated configuration, e.g. by only translating one of the elements' label
  • Fetch the submission, through the submission, fetch the form and fetch the elements/fields through the form with e.g. the code below
  • Check what elements are returned.
    $formData = $submission->getFormData();
    $form = $formData->getWebform();
    $fields = $form->getElementsDecodedAndFlattened();

Proposed resolution

To be checked.

πŸ› Bug report
Status

Needs review

Version

6.2

Component

Code

Created by

πŸ‡§πŸ‡ͺBelgium daften

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024