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:
@@ -18,7 +18,6 @@ if (flextype('registry')->get('flextype.settings.entries.fields.fetch.enabled'))
|
||||
// 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'] :
|
||||
[]);
|
||||
@@ -26,7 +25,6 @@ if (flextype('registry')->get('flextype.settings.entries.fields.fetch.enabled'))
|
||||
|
||||
// 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());
|
||||
}
|
||||
|
@@ -10,6 +10,16 @@ afterEach(function (): void {
|
||||
filesystem()->directory(PATH['project'] . '/entries')->delete();
|
||||
});
|
||||
|
||||
test('test fetchField for blog', function () {
|
||||
flextype('entries')->create('blog', flextype('frontmatter')->decode(filesystem()->file(ROOT_DIR . '/tests/Foundation/Entries/Fields/fixtures/entries/blog/entry.md')->get()));
|
||||
flextype('entries')->create('blog/post-1', flextype('frontmatter')->decode(filesystem()->file(ROOT_DIR . '/tests/Foundation/Entries/Fields/fixtures/entries/blog/post-1/entry.md')->get()));
|
||||
flextype('entries')->create('blog/post-2', flextype('frontmatter')->decode(filesystem()->file(ROOT_DIR . '/tests/Foundation/Entries/Fields/fixtures/entries/blog/post-2/entry.md')->get()));
|
||||
|
||||
$blog = flextype('entries')->fetch('blog');
|
||||
|
||||
$this->assertEquals(14, $blog->count());
|
||||
});
|
||||
|
||||
test('test fetchField for catalog', function () {
|
||||
|
||||
// Create catalog
|
||||
@@ -40,23 +50,12 @@ test('test fetchField for catalog', function () {
|
||||
$this->assertTrue(isset($catalogSingle['discounts']['discounts/30-off']));
|
||||
$this->assertEquals('30% off', $catalogSingle['discounts']['discounts/30-off']['title']);
|
||||
|
||||
$catalogSingleWithCollectionFalse = flextype('entries')->fetch('catalog', 'single');
|
||||
$this->assertEquals(16, $catalogSingleWithCollectionFalse->count());
|
||||
$this->assertEquals('Catalog', $catalogSingleWithCollectionFalse['title']);
|
||||
$this->assertEquals('catalog', $catalogSingleWithCollectionFalse['id']);
|
||||
$this->assertEquals(1, $catalogSingleWithCollectionFalse['bikes']->count());
|
||||
$this->assertTrue(isset($catalogSingleWithCollectionFalse['bikes']['catalog/bikes/gt']));
|
||||
$this->assertEquals('GT', $catalogSingleWithCollectionFalse['bikes']['catalog/bikes/gt']['title']);
|
||||
$this->assertEquals(1, $catalogSingleWithCollectionFalse['discounts']->count());
|
||||
$this->assertTrue(isset($catalogSingleWithCollectionFalse['discounts']['discounts/30-off']));
|
||||
$this->assertEquals('30% off', $catalogSingleWithCollectionFalse['discounts']['discounts/30-off']['title']);
|
||||
|
||||
$catalogCollection = flextype('entries')->fetch('catalog', 'collection');
|
||||
$catalogCollection = flextype('entries')->fetch('catalog', ['from' => 'collection']);
|
||||
$this->assertEquals(1, $catalogCollection->count());
|
||||
$this->assertEquals('Bikes', $catalogCollection['catalog/bikes']['title']);
|
||||
$this->assertEquals('catalog/bikes', $catalogCollection['catalog/bikes']['id']);
|
||||
|
||||
$catalogLongCollecion = flextype('entries')->fetch('catalog', 'collection', ['find' => ['depth' => ['>0', '<4']]]);
|
||||
$catalogLongCollecion = flextype('entries')->fetch('catalog', ['from' => 'collection', 'find' => ['depth' => ['>0', '<4']]]);
|
||||
$this->assertEquals(5, $catalogLongCollecion->count());
|
||||
|
||||
$banner = flextype('entries')->fetch('banner');
|
||||
@@ -64,17 +63,6 @@ test('test fetchField for catalog', function () {
|
||||
$this->assertEquals('banner', $banner['id']);
|
||||
});
|
||||
|
||||
test('test fetchField for blog', function () {
|
||||
flextype('entries')->create('blog', flextype('frontmatter')->decode(filesystem()->file(ROOT_DIR . '/tests/Foundation/Entries/Fields/fixtures/entries/blog/entry.md')->get()));
|
||||
flextype('entries')->create('blog/post-1', flextype('frontmatter')->decode(filesystem()->file(ROOT_DIR . '/tests/Foundation/Entries/Fields/fixtures/entries/blog/post-1/entry.md')->get()));
|
||||
flextype('entries')->create('blog/post-2', flextype('frontmatter')->decode(filesystem()->file(ROOT_DIR . '/tests/Foundation/Entries/Fields/fixtures/entries/blog/post-2/entry.md')->get()));
|
||||
|
||||
$blog = flextype('entries')->fetch('blog')->sortKeys();
|
||||
|
||||
$this->assertEquals(14, $blog->count());
|
||||
});
|
||||
|
||||
|
||||
test('test fetchField for albmus', function () {
|
||||
flextype('entries')->create('root', flextype('frontmatter')->decode(filesystem()->file(ROOT_DIR . '/tests/Foundation/Entries/Fields/fixtures/entries/root/entry.md')->get()));
|
||||
|
||||
|
@@ -2,6 +2,7 @@
|
||||
title: blog
|
||||
fetch:
|
||||
posts:
|
||||
from: collection
|
||||
id: blog
|
||||
options:
|
||||
from: collection
|
||||
---
|
||||
|
@@ -4,8 +4,8 @@ brand: gt
|
||||
fetch:
|
||||
discounts_available:
|
||||
id: discounts
|
||||
from: collection
|
||||
options:
|
||||
from: collection
|
||||
filter:
|
||||
where:
|
||||
-
|
||||
@@ -13,15 +13,15 @@ fetch:
|
||||
operator: eq
|
||||
value: bikes
|
||||
label1:
|
||||
from: single
|
||||
id: discounts/50-off
|
||||
options:
|
||||
from: single
|
||||
filter:
|
||||
limit: 3
|
||||
label2:
|
||||
from: single
|
||||
id: discounts/30-off
|
||||
options:
|
||||
from: single
|
||||
filter:
|
||||
limit: 2
|
||||
---
|
||||
|
@@ -5,9 +5,10 @@ fetch:
|
||||
label:
|
||||
from: single
|
||||
id: discounts/30-off
|
||||
options: []
|
||||
options:
|
||||
from: collection
|
||||
discounts:
|
||||
from: collection
|
||||
id: discounts
|
||||
options: []
|
||||
options:
|
||||
from: collection
|
||||
---
|
||||
|
@@ -3,15 +3,15 @@ title: Catalog
|
||||
visibility: draft
|
||||
fetch:
|
||||
label1:
|
||||
from: single
|
||||
id: discounts/50-off
|
||||
options:
|
||||
from: single
|
||||
filter:
|
||||
limit: 4
|
||||
bikes:
|
||||
id: catalog/bikes
|
||||
from: collection
|
||||
options:
|
||||
from: collection
|
||||
filter:
|
||||
where:
|
||||
-
|
||||
@@ -21,8 +21,8 @@ fetch:
|
||||
limit: 10
|
||||
discounts:
|
||||
id: discounts
|
||||
from: collection
|
||||
options:
|
||||
from: collection
|
||||
filter:
|
||||
where:
|
||||
-
|
||||
|
@@ -2,6 +2,5 @@
|
||||
title: level1
|
||||
fetch:
|
||||
root:
|
||||
from: single
|
||||
id: level1/level2
|
||||
---
|
||||
|
@@ -2,6 +2,5 @@
|
||||
title: level2
|
||||
fetch:
|
||||
root:
|
||||
from: single
|
||||
id: level1/level2/level3
|
||||
---
|
||||
|
@@ -2,6 +2,5 @@
|
||||
title: level3
|
||||
fetch:
|
||||
root:
|
||||
from: single
|
||||
id: level1/level2/level3/level4
|
||||
---
|
||||
|
@@ -1,7 +0,0 @@
|
||||
---
|
||||
title: blog
|
||||
fetch:
|
||||
collection:
|
||||
id: blog
|
||||
from: collection
|
||||
---
|
@@ -1,3 +0,0 @@
|
||||
---
|
||||
title: Post 1
|
||||
---
|
@@ -1,3 +0,0 @@
|
||||
---
|
||||
title: Post 2
|
||||
---
|
@@ -2,20 +2,21 @@
|
||||
title: Album 1
|
||||
fetch:
|
||||
banner-single:
|
||||
from: single
|
||||
id: banners
|
||||
banners-collection:
|
||||
from: collection
|
||||
id: banners
|
||||
banners-collection-2:
|
||||
from: collection
|
||||
id: banners
|
||||
options:
|
||||
from: single
|
||||
banners-collection:
|
||||
id: banners
|
||||
options:
|
||||
from: collection
|
||||
banners-collection-2:
|
||||
id: banners
|
||||
options:
|
||||
from: collection
|
||||
filter:
|
||||
limit: 1
|
||||
find:
|
||||
depth: ">0"
|
||||
banner-single-2:
|
||||
from: single
|
||||
id: banners/2
|
||||
---
|
||||
|
@@ -2,15 +2,17 @@
|
||||
title: Root
|
||||
fetch:
|
||||
single:
|
||||
from: single
|
||||
id: albums
|
||||
collection:
|
||||
from: collection
|
||||
id: albums
|
||||
collectionWithDepth:
|
||||
from: collection
|
||||
id: albums
|
||||
options:
|
||||
from: single
|
||||
collection:
|
||||
id: albums
|
||||
options:
|
||||
from: collection
|
||||
collectionWithDepth:
|
||||
id: albums
|
||||
options:
|
||||
from: collection
|
||||
find:
|
||||
depth: '>0'
|
||||
---
|
||||
|
Reference in New Issue
Block a user