Problem/Motivation
Coming from #3202631: Add Textarea option to normalize newlines to \n
In #2844452: Export configuration YAML strings as multiline, we earned neat readable exports for multiline config items IFF they do not contain "\r".
Many config contain \r though, simply for lazynesss, as the HTML standard mandates textarea elements to return "\r\n" line breaks.
@longwave #7:
Instead could typed data be responsible for normalisation for storage?
@geek-merlin #8:
Use the source, Luke: TypedData does NOT mess with primitive data, it only validates via constraints.StorableConfigBase OTOH already massages data on save() (not on setValue()) in \Drupal\Core\Config\StorableConfigBase::castValue (so the stored config has other sort as in-memory config, which may also violate the principle of least surprise for some).
- So we can add a constraint to string TypedData.
- And we can normalize newlines in StorableConfigBase::castValue (but let's get a signal from code owners if they are open to that).I'll add a bold proposal for that.
Proposed resolution
- In core.data_types.schema.yml::text, add a new property "normalized_newlines", defaulting to TRUE,
- ...and a constraint NormalizedNewlines, that, if the property is true, validates that the text does not contain "\r"
- For now, only add a deprecation, and error in D10
- In \Drupal\Core\Config\StorableConfigBase::castValue, normalize all newlines that must be
Remaining tasks
...
User interface changes
...
API changes
...
Data model changes
...
Release notes snippet
...
Comments
Comment #2
geek-merlinComment #3
geek-merlinComment #4
geek-merlinComment #6
damienmckennaFYI in #3202631-13: Add Textarea option to normalize newlines to \n I provided a patch that changes the default of #normalize_newlines from FALSE to TRUE, and it appears to work in my local testing.