diff --git a/src/flextype/Foundation/Entries/Fields/FetchField.php b/src/flextype/Foundation/Entries/Fields/FetchField.php index 4ed5536f..57159139 100644 --- a/src/flextype/Foundation/Entries/Fields/FetchField.php +++ b/src/flextype/Foundation/Entries/Fields/FetchField.php @@ -10,22 +10,25 @@ declare(strict_types=1); if (flextype('registry')->get('flextype.settings.entries.fields.fetch.enabled')) { flextype('emitter')->addListener('onEntriesFetchSingleHasResult', static function (): void { - if (flextype('entries')->getStorage('fetch_single.data.fetch') !== null) { - $original = flextype('entries')->getStorage('fetch_single'); + if (flextype('entries')->getStorage('fetch.data.fetch') !== null) { - $fetch = flextype('entries')->getStorage('fetch_single.data.fetch'); + // Get fetch. + $original = flextype('entries')->getStorage('fetch'); - foreach ($fetch as $field => $body) { - $data[$field] = flextype('entries')->fetch($body['id'], $body['from'], $body['options']); + // Modify fetch. + foreach (flextype('entries')->getStorage('fetch.data.fetch') as $field => $body) { + $data[$field] = flextype('entries')->fetch($body['id'], + $body['from'], + isset($body['options']) ? + $body['options'] : + []); } - flextype('entries')->setStorage('fetch_single.id', $original['id']); - flextype('entries')->setStorage('fetch_single.options', $original['options']); - flextype('entries')->setStorage('fetch_single.data', arrays($original['data'])->merge($data)->toArray()); + // Save fetch. + flextype('entries')->setStorage('fetch.id', $original['id']); + flextype('entries')->setStorage('fetch.from', $original['from']); + flextype('entries')->setStorage('fetch.options', $original['options']); + flextype('entries')->setStorage('fetch.data', arrays($original['data'])->merge($data)->toArray()); } }); } - -flextype('entries')::macro('fetchFromAnotherDB', function($id, $options) { - return [$id, $options]; -});