getkirby / kirby

Kirby's core application folder
https://getkirby.com
Other
1.32k stars 168 forks source link

$field->toStructure() throws an exception when the field value is invalid #2046

Closed hdodov closed 5 years ago

hdodov commented 5 years ago

The error I'm getting is:

Argument 1 passed to Kirby\Cms\StructureObject::setContent() must be of the type array or null, string given, called in C:\xampp\htdocs\ikarov\kirby\src\Toolkit\Properties.php on line 138

In the debugger, I saw this came from a toStructure() call:

image

This was very tricky to debug because toStructure() is called by a plugin. When you save the default translation, the plugin syncs the structure data with all other translations. Each entry had an options field of type tags which is a comma-separated string. When I changed the blueprint of that field to structure, this error began to appear because the saved value was not a YAML-encoded structure.

To Reproduce Steps to reproduce the behavior:

  1. Have a site.txt with arbitrary string as content.
  2. Run $site->title()->toStructure()

Expected behavior Whenever toStructure() is called with invalid data, it should return an empty structure. Then, when the value is saved, whatever invalid value existed before would be replaced with a valid one.

Kirby Version 3.2.3

bastianallgeier commented 5 years ago