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?
- Install Drupal 8 with the standard profile.
- Create a field of type 'Text (formatted)' with default configuration.
- 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
After
Remaining tasks
Tests are needed.There is a test but it passes while it should fail. Refer to #2382601: Tests which pass while they should fail!.- Follow up issue #2350931: Textarea form element should use #pre_render rather than preprocess function
- Related issue #2349589: JavaScript error on field type Text (formatted)
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,