Problem/Motivation
When text fields are configured without default plain_text behavior and no option to select format, format is saved to the Drupal database as NULL. Drupal knows to interpret that as plain_text as a sensible default. However, when this is serialized, it outputs the NULL value for the format
property. This requires external knowledge of how to interpret the NULL (as plain_text).
It can also is a mismatch for the Typed Data API's declaration that this value is filter_format
if typed data is interpreted as translating to a single specific type, such as a string. This is especially a problem for Contributed modules such as Schemata that seek to derive correct schema definitions of any serialized content based on Typed Data.
Proposed resolution
Not sure what the best approach is right now.
Option A: Store the format as plain_text
when one is not otherwise available.
Option B: Serialize formats to plain_text when a NULL is found. Least impact on the rest of Drupal, but sets the precedent that NULLs will be special cased in serialization.
Remaining tasks
Decide on direction...
User interface changes
None.
API changes
Option A: Switch return of NULL values from some format retrieval methods to plain_text
Option B: Normalizer addition.
Data model changes
Option A: Storing plain_text in lieu of NULL
Option B: None
Comments
Comment #2
Grayside CreditAttribution: Grayside at Phase2 for Norwegian Cruise Line commentedComment #4
Wim LeersIs this a generic problem? Or does it apply only to text fields?
Comment #5
Grayside CreditAttribution: Grayside at Phase2 for Norwegian Cruise Line commentedThis particular issue is initially scoped to text fields. However, the general problem was briefly touched on in #2751325: All serialized values are strings, should be integers/booleans when appropriate with the thought of
Which I interpret to mean "our data types should be able to define what NULL means to them" such that when we load an entity it automatically understands how to handle it's NULL values, changing them to not-null in some cases. However, approaching that so generally seems like a much broader lift and aside from string = '' and format = 'plain_text' I don't have any practical examples.
Comment #6
Wim LeersComment #16
larowlanThis feels like a task to me
Comment #17
larowlan