Skip to content

Commit

Permalink
feat: allow arrays for blocksResolver.files
Browse files Browse the repository at this point in the history
  • Loading branch information
johannschopplich committed Mar 22, 2023
1 parent 1d14459 commit e893e67
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,8 @@ return [
// Blocks that contain files fields
'files' => [
// Block name as key, field name as value
// Resolve the built-in `image` field of the `image` block
'image' => 'image'
// Resolve the `image` field of the built-in `image` block
'image' => ['image']
]
]
];
Expand Down
11 changes: 10 additions & 1 deletion src/extensions/fieldMethods.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
<?php

$filesResolver = function (\Kirby\Cms\Block $item) {
foreach (array_values(option('blocksResolver.files', ['image' => 'image'])) as $key) {
$keys = array_values(option('blocksResolver.files', ['image' => 'image']));

// Flatten keys, since the option values can be arrays
$keys = array_reduce(
$keys,
fn ($acc, $i) => array_merge($acc, is_array($i) ? $i : [$i]),
[]
);

foreach ($keys as $key) {
/** @var \Kirby\Cms\Files $images */
$images = $item->content()->get($key)->toFiles();

Expand Down

0 comments on commit e893e67

Please sign in to comment.