mirror of
https://github.com/flextype/flextype.git
synced 2025-08-08 06:06:45 +02:00
feat(fields): Add new field fetch
for Entries API #492
This commit is contained in:
@@ -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];
|
||||
});
|
||||
|
Reference in New Issue
Block a user