Upgrading Textarea to Formatted Text and config import does not clear past submissions

Created on 5 April 2024, 8 months ago

Problem/Motivation

Update: Has to do with config import not clearing past submission data.

Still happening on the webform submission page (/admin/structure/webform/manage/*/results/submissions). I have two WYSWIG Text areas and a conditionally hidden field, so not sure as to the exact cause, but its identical to issue #3345964

I just added a new WYSWIG Text Area to the form and the condition to an existing form, so its possible the issue is have an existing webform with submissions, and then add a second WSYWIG text area to get to reproduce this?

TypeError: strlen(): Argument #1 ($string) must be of type string, array given in strlen() (line 395 of core/lib/Drupal/Component/Utility/Unicode.php).
Drupal\Component\Utility\Unicode::validateUtf8(Array) (Line: 65)
Drupal\Component\Utility\Xss::filter(Array, Array) (Line: 91)
Drupal\filter\Plugin\Filter\FilterHtml->process(Array, '') (Line: 118)
Drupal\filter\Element\ProcessedText::preRenderText(Array)
call_user_func_array(Array, Array) (Line: 111)
Drupal\Core\Render\Renderer->doTrustedCallback(Array, Array, 'Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. See https://www.drupal.org/node/2966725', 'exception', 'Drupal\Core\Render\Element\RenderCallbackInterface') (Line: 797)
Drupal\Core\Render\Renderer->doCallback('#pre_render', Array, Array) (Line: 386)
Drupal\Core\Render\Renderer->doRender(Array, 1) (Line: 204)
Drupal\Core\Render\Renderer->render(Array, 1) (Line: 160)
Drupal\Core\Render\Renderer->Drupal\Core\Render\{closure}() (Line: 592)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 161)
Drupal\Core\Render\Renderer->renderPlain(Array) (Line: 303)
check_markup(Array, 'webform_html') (Line: 238)
Drupal\webform\Plugin\WebformElement\TextFormat->formatHtmlItem(Array, Object, Array) (Line: 1373)
Drupal\webform\Plugin\WebformElementBase->format('Html', Array, Object, Array) (Line: 1323)
Drupal\webform\Plugin\WebformElementBase->formatHtml(Array, Object) (Line: 1880)
Drupal\webform\Plugin\WebformElementBase->formatTableColumn(Array, Object, Array) (Line: 1009)
Drupal\webform\WebformSubmissionListBuilder->buildRowColumn(Array, Object) (Line: 842)
Drupal\webform\WebformSubmissionListBuilder->buildRow(Object) (Line: 242)
Drupal\Core\Entity\EntityListBuilder->render() (Line: 567)
Drupal\webform\WebformSubmissionListBuilder->buildEntityList() (Line: 462)
Drupal\webform\WebformSubmissionListBuilder->render() (Line: 23)
Drupal\Core\Entity\Controller\EntityListController->listing('webform_submission')
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 592)

Steps to reproduce

Proposed resolution

Check the $value is not an array before passing to check_markup?

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Closed: won't fix

Version

6.2

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States NicholasS

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

Comments & Activities

  • Issue created by @NicholasS
  • πŸ‡ΊπŸ‡ΈUnited States NicholasS

    Looking into this yes It seems when its rendering the submissions as soon as it gets past the new submissions which had 2 text areas with a conditional field. I get this error when its rendering out a submission from the old form that only had 1 text area and not conditionally hidden fields.

    Locally I could get this fixed by adding

        // if value is array convert to string
        if (is_array($value)) {
          $value = implode(", ", $value);
        }
    

    to

      /**
       * {@inheritdoc}
       */
      protected function formatHtmlItem(array $element, WebformSubmissionInterface $webform_submission, array $options = []) {
        $value = $this->getValue($element, $webform_submission, $options);
    
        $format = $value['format'] ?? $this->getItemFormat($element);
        $value = $value['value'] ?? $value;
        // if value is array convert to string
        if (is_array($value)) {
          $value = implode(", ", $value);
        }
        switch ($format) {
          case 'raw':
            return $value;
    
          case 'value':
            $default_format = filter_default_format(User::load($webform_submission->getOwnerId()));
            return check_markup($value, $default_format);
    
          default:
            return check_markup($value, $format);
        }
      }
    
  • πŸ‡ΊπŸ‡ΈUnited States NicholasS
  • Status changed to Postponed: needs info 8 months ago
  • πŸ‡ΊπŸ‡ΈUnited States jrockowitz Brooklyn, NY

    Can you post a very simple example webform which can be used to replicate this issue?

  • πŸ‡ΊπŸ‡ΈUnited States NicholasS

    Ok so diving into this a bit more over the last hour I can't reproduce the issue in a new form, but I think I have a better Idea as to what is going on.

    What happened is a normal text area was "upgraded" to a WYSWIG, and it appears the same machine name was kept.

    When I do this locally, and I mean
    1. Delete the old text area
    2. Readd the same field but as a WYSWIG field

    I don't get an error.

    But I think when we exported this change to config, and migrated it to prod is it possible that the migration process did not actually clear out the old plain text submissions?

  • πŸ‡ΊπŸ‡ΈUnited States NicholasS

    Yeah so steps to reproduce.

    1. Start with a simple text are a form and submit a test submission

    elements: |-
      title:
        '#type': textfield
        '#title': title
      site_contact_details:
        '#type': textarea
        '#title': 'site contact details'
    

    2. Then import (drush cim) a new version of that webform that makes the field become a WYSWIG text area.

    elements: |-
      title:
        '#type': textfield
        '#title': title
      site_contact_details:
        '#type': text_format
        '#title': 'site contact details'
        '#allowed_formats':
          webform_html: webform_html
    

    3. Do another test submission

    4. See errror on submisison page

  • πŸ‡ΊπŸ‡ΈUnited States NicholasS

    So yeah I guess this was my mistake for keeping the same machine name, but also seems like a fairly common foot gun that could happen to others.

  • πŸ‡ΊπŸ‡ΈUnited States NicholasS
  • πŸ‡ΊπŸ‡ΈUnited States NicholasS
  • Status changed to Closed: won't fix 8 months ago
  • πŸ‡ΊπŸ‡ΈUnited States jrockowitz Brooklyn, NY

    This feels like an edge case related to changing the elements via YAML. For now, I would like to not fix it.

Production build 0.71.5 2024