When adding a field of type:

    $form['textarea'] = array(
      '#type' => 'text_format',
      '#format' => 'full_html',
      '#title' => 'Form element'
    );

And the validation of the form fails, the values for these field types are empty.
The problem is caused by /src/Plugin/Alter/ElementInfo.php on line 37:

$element['#input'] = $types[$element['#base_type']]['#input']

When commenting out this line, the problem is solved, but I don't think this is a solid solution?

I added a small example module that exposes a form to demonstrate the problem. Just install it and make sure you are using boostrap as default theme. Then enter a value and submit the form. You will see that the value has magically disappeared :)

CommentFileSizeAuthor
text_format_example.zip1.77 KBrobin.ingelbrecht
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

robin.ingelbrecht created an issue. See original summary.

robin.ingelbrecht’s picture

Title: text_format element loses value when validation fails » text_format element loses value when form validation fails
robin.ingelbrecht’s picture

Issue summary: View changes
robin.ingelbrecht’s picture

Issue summary: View changes
markhalliwell’s picture

Title: text_format element loses value when form validation fails » Setting #input based on #base_type is unnecessary
Version: 8.x-3.0-beta2 » 8.x-3.x-dev
Priority: Critical » Normal
Issue tags: +Needs backport to D7

I looked through what code actually uses #base_type and it appears that only the filter/text modules do (for the text_format element). I think this entire code is unnecessary and should come out. It was probably introduced as an artifact from some old code.

  • markcarver committed bfc481b on 8.x-3.x
    Issue #2652782 by markcarver: Setting #input based on #base_type is...

  • markcarver committed 7684354 on 7.x-3.x
    Issue #2652782 by markcarver: Setting #input based on #base_type is...
markhalliwell’s picture

Status: Active » Fixed
Issue tags: -Needs backport to D7

Status: Fixed » Closed (fixed)

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