Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 293694

Fields of type 'Text (formatted)' do NOT save values.

$
0
0

Problem/Motivation

Any field of type 'Text (formatted)' simply does not save the data entered into it when a module is enabled that alters the element info for #type text_format and adds an additional #pre_render callback.

Possible data loss: It could simply cause data loss as the user will simply fail to notice the entered data is not saved.

Impossible to submit data: In case the field is set as 'required', the user will not be able to submit the data at all.

How to reproduce?

  1. Install Drupal 8 with the standard profile.
  2. Create a field of type 'Text (formatted)' with default configuration.
  3. Try to save a value for that field. e.g. when you create a content.

Note: This is about a "text" field (as in Field API) not a "textfield" (as in @FormElement("textfield")).

Proposed resolution

Technical reason:
The filter module copies selected element info properties from the top-level #type text_format element to the lower level #type textfield element, and then augments the lower level #type textfield element with its default values using the + $array operator. The + $array operator will not override existing keys.
When text module is enabled on its own, there is no value for #type textfield in #pre_render and so the lower level #type textfield receives the default $array value from the textfield element info.
When editor module is enabled, it alters the element info for #type text_format, adding a #pre_render entry, this is copied into the lower level #type textfield and prevents the default from being added via the default when + $array is used.
The solution in the patch is to make sure that #pre_render values form #type text_format are not copied into the lower level #type textfield element, ensuring the defaults are set.

Before

Before screenshot

After

After screenshot

Remaining tasks

User interface changes

None.

API changes

Unknown.

Original report by @Kartagis

I noticed that fields created via Field API or otherwise (only on registration form) don't save information. I first noticed this when I created a field via my module and attached it to user entity_type. I then tested it by manually creating a formatted text field with Field UI, and noticed that behaviour too.
Regards,


Viewing all articles
Browse latest Browse all 293694

Trending Articles