kirby
kirby copied to clipboard
Extending core block blueprints
Description
When extending Kirbys core image block it’s not possible to limit the ratio options.
testBlocks:
type: blocks
fieldsets:
image:
extends: blocks/image
fields:
ratio:
options:
1/1: "1:1"
16/9: "16:9"
7/5: "7:5"
Expected behavior
The only options for the ratio
should be the ones passed from the blueprint. (1/1, 16/9, 7/5)
As described in the cook book recipe Modifying blocks types and custom blocks / Extending existing fields it should be possible to limit the options.
Your setup
Kirby Version
3.7.2.1
Additional context
The difference between the example given in cook book recipe and the one above is the use of an non-associative array for the level options in the recipe and a associative array for ratio options.
[…]
fieldsets:
heading:
extends: blocks/heading
fields:
level:
# non-associative array, does overwrite the core block options
options:
- h2
- h3
image:
extends: blocks/image
fields:
ratio:
# associative array, does not overwrite the core block options
options:
1/1: "1:1"
16/9: "16:9"
7/5: "7:5"
This is probably the only possible behaviour? Kirby/Cms/Blueprint,php:210 is merging the core blocks blueprint settings with the extension by calling A::merge($mixin, $props, A::MERGE_REPLACE)
.
With A::MERGE_REPLACE
only non-associative arrays will be replaced, so it’s not possible to remove keys from an associative array and that’s what you want 99.9% of the time when using extends with blueprints.
Maybe the cook book recipe should make a note of this?