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

geek-merlin created an issue. See original summary.

geek-merlin’s picture

Title: Default to normalize newlines in config strings to \n » Default to normalize newlines in "text" config to \n
geek-merlin’s picture

geek-merlin’s picture

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

damienmckenna’s picture

FYI 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.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.