So what was previously - image.png\n is now - image.png. Later, when it's saved, the value is no longer considered multi-line and does not get \n\n prepended to it.
Expected behavior
The first format should never happen, because the string is essentially one line. When saved from the panel, the field should look like this:
Logo: - image.png
To reproduce
Create a site.yml blueprint with a pages field
Save some value through the panel to get the first format
Description
When you save a YAML-encoded field in the panel (e.g. a files field) and it has one entry, it's saved like this:
Later, if you use
$model->writeContent()
, it turns to this:This makes it annoying when you keep changes in Git, because you get "fake" changes.
The first format happens because when the field value is encoded with YAML here:
https://github.com/getkirby/kirby/blob/cfac315bc685193d0fe1b10fe3bf45a96e48fd15/src/Data/Yaml.php#L37
…it is returned with a newline character at the end, i.e.:
Then, when it's saved by the TXT data handler, it's considered a multi-line string and has
\n\n
prepended to it:https://github.com/getkirby/kirby/blob/cfac315bc685193d0fe1b10fe3bf45a96e48fd15/src/Data/Txt.php#L76-L79
The second format happens because the TXT data handler trims whitespace from the value here:
https://github.com/getkirby/kirby/blob/cfac315bc685193d0fe1b10fe3bf45a96e48fd15/src/Data/Txt.php#L125
So what was previously
- image.png\n
is now- image.png
. Later, when it's saved, the value is no longer considered multi-line and does not get\n\n
prepended to it.Expected behavior
The first format should never happen, because the string is essentially one line. When saved from the panel, the field should look like this:
To reproduce
Create a
site.yml
blueprint with a pages fieldSave some value through the panel to get the first format
Execute this:
You'll see the second format
Your setup
Kirby Version
3.7.1