Releases: johannschopplich/kirby-headless
v2.2.0
🚀 Features
toResolvedWriter
for page and file permalinks in writer fields - by @johannschopplich (2050b)
View changes on GitHub
v2.1.1
No significant changes
View changes on GitHub
v2.1.0
v2.0.0
Warning
This release contains a breaking change. If you're using custom file resolvers for the toResolvedBlocks()
method, please upgrade to the latest syntax below. If you haven't defined any blocksResolver
options in your site/config.php
, then you're good to go already!
Migration
toResolvedBlocks()
The toResolvedBlocks()
method is a wrapper around the toBlocks()
method. It's primarily intended for usage with KQL queries, because the toBlocks()
method returns only UUIDs for the files
and pages
fields.
This field method will resolve the UUIDs to the actual file or page objects, so you can access their properties directly in your frontend.
# /site/config/config.php
return [
'blocksResolver' => [
// Define which fields of which blocks need resolving
'files' => [
// Resolve the `image` field in the `image` block as a file
'image' => ['image'],
// Resolve the `image` field in the `intro` block as a file
'intro' => ['image']
],
'pages' => [
// Resolve the `link` field in the `customBlock` block as a page
'customBlock' => ['link']
]
]
];
For an example, take a look at the 🍫 Cacao Kit frontend.
Custom Files or Pages Resolver
To resolve image UUIDs to image objects, you can define a custom resolver in your config.php
. By default, the following resolver is used:
$defaultResolver = fn (\Kirby\Cms\File $image) => [
'url' => $image->url(),
'width' => $image->width(),
'height' => $image->height(),
'srcset' => $image->srcset(),
'alt' => $image->alt()->value()
];
If you just need one custom resolver for all files fields, you can use the blocksResolver.defaultResolvers.files
options key. Respectively, you can use the blocksResolver.defaultResolvers.pages
options key for all pages fields.
Both options accept a closure that receives the file/page object as its first argument and returns an array of properties, just like the default resolver:
# /site/config/config.php
return [
'blocksResolver' => [
// Default Resolvers
'defaultResolvers' => [
'files' => fn (\Kirby\Cms\File $image) => [
'url' => $image->url(),
'alt' => $image->alt()->value()
],
'pages' => fn (\Kirby\Cms\Page $page) => [
// Default resolver for pages
]
]
]
];
Custom Resolver for a Specific Block and Field
If you need a custom resolver for images, links, or any other field in a specific block, you can use the blocksResolver.resolvers
options key. It accepts an array of resolvers, where the key is the block name and the value is a closure that receives the field object as its first argument and returns an array of properties:
# /site/config/config.php
return [
'blocksResolver' => [
'resolvers' => [
'intro:link' => fn (\Kirby\Cms\Field $field) => [
'value' => $field->value()
]
]
]
];
🚀 Features
- Custom field resolvers - by @johannschopplich (d07f3)
View changes on GitHub
v1.7.1
🐞 Bug Fixes
- String field keys for files resolver - by @johannschopplich (c212d)
View changes on GitHub
v1.7.0
🚀 Features
- Custom file resolver for block fields - by @johannschopplich (23103)
View changes on GitHub
v1.6.3
No significant changes
View changes on GitHub
v1.6.2
No significant changes
View changes on GitHub
v1.6.1
🚨 Breaking Changes
- Lowercase resolved item key just like Kirby - by @johannschopplich (13864)
View changes on GitHub
v1.6.0
🚀 Features
- Resolve pages fields inside blocks - by @johannschopplich (7f06f)
🐞 Bug Fixes
hasBody
middleware - by @johannschopplich (2a672)