Problem/Motivation

When implementing a required field of type webform_html_editor, the required field is not validated it contains data.

Current behavior:

A required webform_html_editor field can be saved without input.

Expected behavior:

A required webform_html_editor field produces an error message on webform save "The field Administrative description is required."

Steps to reproduce

Introduce a '#type' => 'webform_html_editor' where '#required' = TRUE:

$form['general_settings']['description'] = [
      '#type' => 'webform_html_editor',
      '#title' => $this->t('Administrative description'),
      '#default_value' => $webform->get('description'),
      '#required' => TRUE,
    ];

Save the webform:

Proposed resolution

It seems the magic in Drupal\webform\Element\WebformHtmlEditor::validateWebformHtmlEditor() doesn't get executed when there are other errors in the settings form. This causes an array to be set for $element['#value']['value'] in preRenderWebformHtmlEditor().

Adding the code below to preRenderWebformHtmlEditor seems to help, feels kind of wrong though. Don't know enough about the history of the webform_html_editor form field type to provide an alternative? Any suggestions would be welcome.

if(is_array($element['#value']['value'])){
  $element['#value']=$element['#value']['value'];
  $element['#format']=$element['#value']['format'];
}

Remaining tasks

User interface changes

API changes

Data model changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

johannijdam created an issue. See original summary.

seanB’s picture

Title: Bug with saving a custom field » WebformHtmlEditor error when settings form validation fails
Issue summary: View changes

Cleaned the IS and title up a bit. This has nothing to do with the custom field as far as I could tell.

jrockowitz’s picture

Status: Needs review » Postponed (maintainer needs more info)

Have you tested the latest dev release.

I think this is a duplicate issue.

@see #2939788: Custom email body replaced with "Array" on validation error (disabled dialogs)

If this is not a duplicate issue, can you please provide the steps required to reproduce the problem.

idebr’s picture

Title: WebformHtmlEditor error when settings form validation fails » '#type' => 'webform_html_editor' element with '#required' => TRUE does not display a 'field is required' message on save
Issue summary: View changes
Status: Postponed (maintainer needs more info) » Needs work
FileSize
365.37 KB

The attached patch does not solve the problem.

I have expanded the issue summary with steps to reproduce.

jrockowitz’s picture

The attached webform can be used to reproduce the issue.

  • jrockowitz committed 7124efd on 2941032-html-required
    Issue #2941032 by johannijdam, jrockowitz, idebr: '#type' => '...
jrockowitz’s picture

Status: Needs work » Needs review
FileSize
10.05 KB
jrockowitz’s picture

Status: Needs review » Fixed

I manually retested the patch and everything looks good. I committed the patch. Please download the latest dev release to review.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.