is there a way to enforce data of (custom) fields to be stored as JSON rather than YAML?
All ways i tried to store an array of objects resulted in it’s YAML representation. Blocks and other fields store their content as JSON.
Any idea? Thanks in advance,
I thought you had already done this with your custom field the other day?
no, i was able to read data from content file, send it to vue and convert there via JSON.parse into an array again. That day i wasn’t (yet) able to store data through the page so i manipulated the content field data manually
Now the API is able to write data, too and thus i came across the problem that my array data is always converted into YAML.
Well, the custom field I linked to the other day actually stores data as json, so you should be able to do the same.
I mean this one: Revert button not reverting unsaved changes in custom plugin - #8 by isaac
sorry for coming back to you so late. I might have explained things misunderstandable, so i try it again a little bit differenlty @texnixe :
What i am currently trying to achieve is to save the content the same way a BlockField does. In this case data is being migrated from a page on another site to this. Hence, after downloading the remote files to my local instance in need to fix the file references being stored in an image block.
After fixing the content with the correct URLs the page is created like
$articleJson = A::merge($articleJson, $fixedFileIds, A::MERGE_OVERWRITE);
$articlePage = $newsBlog->createChild([
'model' => 'blog_article_community',
'template' => 'blog_article_community',
'parent' => $newsBlog,
'slug' => $slug,
'content' => $articleJson,
which works pretty well except for the fact, that the fixed block field which stores its data JSON formatted, gets stored YAML formatted due to Kirby\Form::strings() L361.
So after creating the page the block field isn’t rendered correctly as the toBlocks() method expects something differntly.
Probably this makes things clearer?
Best and thanks in advance, Thomas E.-E.