Closed nilshoerrmann closed 2 months ago
For the files, pages etc. fields you should better always apply first ->toFiles()
etc. and not just apply ->isEmpty()
on the raw field.
We usually do that, but in this case we were using the core or
method which relies on isEmpty
:
<?php if (
$image = $plugin->header()->or($plugin->cover())->toFile()
): ?>
The fallback was never used because or
always assumed the header image to be set und toFile
then return null
. header
and cover
both being files fields here.
For the files, pages etc. fields you should better always apply first ->toFiles() etc. and not just apply ->isEmpty() on the raw field.
Just to make the point: it's Kirby applying isEmpty
on the raw field here.
Description
When using the Symfony YAML handler –
'yaml.handler' => 'symfony'
– Kirby will create non-empty values for empty content. Given a files field, removing all previously selected files will be stored as[]
in the content file. Using the default YAML handler will result in an empty string.Result with Symfony YAML handler:
Result with default YAML handler:
This divergent behaviour will cause issues when using
isEmpty
or methods relying on this method (likeisNotEmpty
oror
) becauseisEmpty
checks on the plain field value. So even ifisNotEmpty
will returntrue
on an object, as consecutive call totoFile()
will still result in an empty object. This is unexpected and does break templating logic.Expected behavior
Empty values should be identified correctly independent of the chosen YAML handler.
Scope This will affect any field storing collection-like content.
To reproduce
Your setup
Kirby Version
4.4.0 RC1 but it should be the same issue ever since YAML handlers have been introduced. PHP Version In case this matters, it happens on PHP 8.2 for us.