1
0
mirror of https://github.com/flextype/flextype.git synced 2025-08-08 06:06:45 +02:00

feat(entries): Entries API fetch improvements. #491

This commit is contained in:
Awilum
2020-12-11 14:40:17 +03:00
parent 17a7dc2bba
commit 006e417fe7

View File

@@ -0,0 +1,24 @@
<?php
declare(strict_types=1);
/**
* Flextype (https://flextype.org)
* Founded by Sergey Romanenko and maintained by Flextype Community.
*/
if (flextype('registry')->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());
}
});
}