diff --git a/src/flextype/Foundation/Entries/Fields/FetchField.php b/src/flextype/Foundation/Entries/Fields/FetchField.php new file mode 100644 index 00000000..6c91a2a9 --- /dev/null +++ b/src/flextype/Foundation/Entries/Fields/FetchField.php @@ -0,0 +1,24 @@ +get('flextype.settings.entries.fields.fetch.enabled')) { + flextype('emitter')->addListener('onEntriesFetchSingleHasResult', static function (): void { + if (flextype('entries')->getStorage('fetch.data.fetch') !== null) { + $original = flextype('entries')->getStorage('fetch'); + foreach (flextype('entries')->getStorage('fetch.data.fetch') as $fetch) { + if (isset($fetch['options']) && isset($fetch['options']['collection']) && strings($fetch['options']['collection'])->isTrue()) { + $data[$fetch['result']] = flextype('entries')->fetchCollection($fetch['id'], $fetch['options']); + } else { + $data[$fetch['result']] = flextype('entries')->fetchSingle($fetch['id']); + } + } + flextype('entries')->setStorage('fetch.data', arrays($original['data'])->merge($data)->toArray()); + } + }); +}