Open maximelebreton opened 6 years ago
ok that's because the plugin works only with string
fields (for files), and not with object
fields (and custom fields seems to be saved as objects in kirby?).
i've made a dirty fix to fit my needs, but if you have a better solution?
in JsonApiUtil.php
:
public static function filesToJson($page, $fields = null)
{
if (empty($page)) {
return null;
}
$files = [];
foreach ($page->files() as $file) {
$collection = new JsonFieldCollection();
if ($fields) {
$file_fields = [];
foreach ($fields as $field) {
$file_field = $file->{$field}();
if ( is_string( $file_field ) ) {
$file_fields[$field] = new StaticField( $file_field );
}
if ( is_object( $file_field ) ) {
$file_fields[$field] = new StaticField( $file_field->value() );
}
}
$collection->addFields($file_fields);
} else {
$collection->addFields([
'url' => new StaticField($file->url()),
'name' => new StaticField($file->name()),
'extension' => new StaticField($file->extension()),
'size' => new StaticField($file->size()),
'niceSize' => new StaticField($file->niceSize()),
'mime' => new StaticField($file->mime()),
'type' => new StaticField($file->type()),
]);
}
$files[] = $collection;
}
return new JsonListCollection($files);
}
Hi @lord-executor, and thanks for your work!
Here is my problem, I try to build a custom API, but I can't get custom fields (on files for this example).
if i have a blueprint like this:
and a custom api like this:
the result is:
I can get the
url
field of my files, but not thecustomcolor
field, and dont understand why...Any ideas?
Thanks!