mirror of
https://github.com/flextype/flextype.git
synced 2025-08-08 06:06:45 +02:00
feat(entries): Entries API improvements. #491
This commit is contained in:
@@ -35,106 +35,6 @@ class Entries
|
||||
*/
|
||||
private $storage = [];
|
||||
|
||||
/**
|
||||
* Callback method for fetch.
|
||||
*
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
private $fetchCallbackMethod = 'single';
|
||||
|
||||
/**
|
||||
* Get an item from an storage using "dot" notation.
|
||||
*
|
||||
* @param string|int|null $key Key.
|
||||
* @param mixed $default Default value.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @return array Updated storage.
|
||||
*/
|
||||
public function getStorage($key, $default = null)
|
||||
{
|
||||
return arrays($this->storage)->get($key, $default);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given dot-notated key exists in the storage.
|
||||
*
|
||||
* @param string|array $keys Keys
|
||||
*
|
||||
* @return bool Return TRUE key exists in the array, FALSE otherwise.
|
||||
*/
|
||||
public function hasStorage($keys): bool
|
||||
{
|
||||
return arrays($this->storage)->has($keys);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an storage item to a given value using "dot" notation.
|
||||
* If no key is given to the method, the entire storage will be replaced.
|
||||
*
|
||||
* @param string|null $key Key.
|
||||
* @param mixed $value Value.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @return array Updated storage.
|
||||
*/
|
||||
public function setStorage(?string $key, $value): void
|
||||
{
|
||||
$this->storage = arrays($this->storage)->set($key, $value)->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an storage value using "dot notation".
|
||||
*
|
||||
* @param array|string $keys Keys
|
||||
*
|
||||
* @return array Updated storage.
|
||||
*/
|
||||
public function deleteStorage($keys): self
|
||||
{
|
||||
return $this->storage = arrays($this->storage)->delete($keys)->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch.
|
||||
*
|
||||
* @param string $id Unique identifier of the entry.
|
||||
* @param array $options Options array.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function fetch(string $id, array $options = [])
|
||||
{
|
||||
// Store data in EMS.
|
||||
$this->setStorage('fetch.id', $id);
|
||||
$this->setStorage('fetch.options', $options);
|
||||
$this->setStorage('fetch.data', []);
|
||||
|
||||
// Run event: onEntriesFetch
|
||||
flextype('emitter')->emit('onEntriesFetch');
|
||||
|
||||
// Get valid callable method for fetch.
|
||||
$fetchFromCallbackMethodName = strings($this->hasStorage('fetch.options.from') ?
|
||||
$this->getStorage('fetch.options.from') :
|
||||
$this->fetchCallbackMethod)
|
||||
->studly()
|
||||
->prepend('fetch')
|
||||
->toString();
|
||||
|
||||
$fetchFromCallbackMethod = is_callable([$this, $fetchFromCallbackMethodName]) ?
|
||||
$fetchFromCallbackMethodName :
|
||||
$this->fetchCallbackMethod;
|
||||
|
||||
// Get fetch result
|
||||
return $this->{$fetchFromCallbackMethod}($this->getStorage('fetch.id'),
|
||||
$this->getStorage('fetch.options'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch single entry.
|
||||
*
|
||||
@@ -434,6 +334,61 @@ class Entries
|
||||
return filesystem()->file($this->getFileLocation($this->getStorage('has.id')))->exists();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an item from an storage using "dot" notation.
|
||||
*
|
||||
* @param string|int|null $key Key.
|
||||
* @param mixed $default Default value.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @return array Updated storage.
|
||||
*/
|
||||
public function getStorage($key, $default = null)
|
||||
{
|
||||
return arrays($this->storage)->get($key, $default);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given dot-notated key exists in the storage.
|
||||
*
|
||||
* @param string|array $keys Keys
|
||||
*
|
||||
* @return bool Return TRUE key exists in the array, FALSE otherwise.
|
||||
*/
|
||||
public function hasStorage($keys): bool
|
||||
{
|
||||
return arrays($this->storage)->has($keys);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an storage item to a given value using "dot" notation.
|
||||
* If no key is given to the method, the entire storage will be replaced.
|
||||
*
|
||||
* @param string|null $key Key.
|
||||
* @param mixed $value Value.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @return array Updated storage.
|
||||
*/
|
||||
public function setStorage(?string $key, $value): void
|
||||
{
|
||||
$this->storage = arrays($this->storage)->set($key, $value)->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an storage value using "dot notation".
|
||||
*
|
||||
* @param array|string $keys Keys
|
||||
*
|
||||
* @return array Updated storage.
|
||||
*/
|
||||
public function deleteStorage($keys): self
|
||||
{
|
||||
return $this->storage = arrays($this->storage)->delete($keys)->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get entry file location
|
||||
*
|
||||
|
53
src/flextype/Foundation/Entries/Fields/EntriesField.php
Normal file
53
src/flextype/Foundation/Entries/Fields/EntriesField.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?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.entries.fetchCollection.enabled')) {
|
||||
flextype('emitter')->addListener('onEntriesFetchSingleHasResult', static function (): void {
|
||||
if (flextype('entries')->getStorage('fetch.data.entries.fetchCollection') !== null) {
|
||||
// Get fetch.
|
||||
$original = flextype('entries')->getStorage('fetch');
|
||||
|
||||
// Modify fetch.
|
||||
foreach (flextype('entries')->getStorage('fetch.data.entries.fetchCollection') as $field => $body) {
|
||||
$data[$field] = flextype('entries')->fetchCollection($body['id'],
|
||||
isset($body['options']) ?
|
||||
$body['options'] :
|
||||
[]);
|
||||
}
|
||||
|
||||
// Save fetch.
|
||||
flextype('entries')->setStorage('fetch.id', $original['id']);
|
||||
flextype('entries')->setStorage('fetch.options', $original['options']);
|
||||
flextype('entries')->setStorage('fetch.data', arrays($original['data'])->merge($data)->toArray());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (flextype('registry')->get('flextype.settings.entries.fields.entries.fetchSingle.enabled')) {
|
||||
flextype('emitter')->addListener('onEntriesFetchSingleHasResult', static function (): void {
|
||||
if (flextype('entries')->getStorage('fetch.data.entries.fetchSingle') !== null) {
|
||||
// Get fetch.
|
||||
$original = flextype('entries')->getStorage('fetch');
|
||||
|
||||
// Modify fetch.
|
||||
foreach (flextype('entries')->getStorage('fetch.data.entries.fetchSingle') as $field => $body) {
|
||||
$data[$field] = flextype('entries')->fetchSingle($body['id'],
|
||||
isset($body['options']) ?
|
||||
$body['options'] :
|
||||
[]);
|
||||
}
|
||||
|
||||
// Save fetch.
|
||||
flextype('entries')->setStorage('fetch.id', $original['id']);
|
||||
flextype('entries')->setStorage('fetch.options', $original['options']);
|
||||
flextype('entries')->setStorage('fetch.data', arrays($original['data'])->merge($data)->toArray());
|
||||
}
|
||||
});
|
||||
}
|
@@ -1,32 +0,0 @@
|
||||
<?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) {
|
||||
|
||||
// Get fetch.
|
||||
$original = flextype('entries')->getStorage('fetch');
|
||||
|
||||
// Modify fetch.
|
||||
foreach (flextype('entries')->getStorage('fetch.data.fetch') as $field => $body) {
|
||||
$data[$field] = flextype('entries')->fetch($body['id'],
|
||||
isset($body['options']) ?
|
||||
$body['options'] :
|
||||
[]);
|
||||
}
|
||||
|
||||
// Save fetch.
|
||||
flextype('entries')->setStorage('fetch.id', $original['id']);
|
||||
flextype('entries')->setStorage('fetch.options', $original['options']);
|
||||
flextype('entries')->setStorage('fetch.data', arrays($original['data'])->merge($data)->toArray());
|
||||
}
|
||||
});
|
||||
}
|
@@ -12,6 +12,6 @@ use Thunder\Shortcode\Shortcode\ShortcodeInterface;
|
||||
// Shortcode: [entries_fetch id="entry-id" field="field-name" default="default-value"]
|
||||
if (flextype('registry')->get('flextype.settings.shortcode.shortcodes.entries.enabled')) {
|
||||
flextype('shortcode')->addHandler('entries_fetch', static function (ShortcodeInterface $s) {
|
||||
return arrays(flextype('entries')->fetch($s->getParameter('id')))->get($s->getParameter('field'), $s->getParameter('default'));
|
||||
return arrays(flextype('entries')->fetchSingle($s->getParameter('id')))->get($s->getParameter('field'), $s->getParameter('default'));
|
||||
});
|
||||
}
|
||||
|
@@ -59,8 +59,11 @@ errors:
|
||||
entries:
|
||||
extension: md
|
||||
fields:
|
||||
fetch:
|
||||
enabled: true
|
||||
entries:
|
||||
fetchCollection:
|
||||
enabled: true
|
||||
fetchSingle:
|
||||
enabled: true
|
||||
slug:
|
||||
enabled: true
|
||||
published_at:
|
||||
|
@@ -27,28 +27,28 @@ test('test update() method', function () {
|
||||
$this->assertFalse(flextype('entries')->update('bar', ['title' => 'Test']));
|
||||
});
|
||||
|
||||
test('test fetch() entry', function () {
|
||||
test('test fetchSingle() and fetchCollection() entry', function () {
|
||||
flextype('entries')->create('foo', ['title' => 'Foo']);
|
||||
flextype('entries')->create('foo/bar', ['title' => 'Bar']);
|
||||
flextype('entries')->create('foo/baz', ['title' => 'Baz']);
|
||||
flextype('entries')->create('foo/zed', ['title' => 'Zed']);
|
||||
|
||||
$this->assertEquals(12, flextype('entries')->fetch('foo')->count());
|
||||
$this->assertEquals('foo', flextype('entries')->fetch('foo')['id']);
|
||||
$this->assertEquals(12, flextype('entries')->fetch('foo', ['from' => 'single'])->count());
|
||||
$this->assertEquals('foo', flextype('entries')->fetch('foo')['id']);
|
||||
$this->assertEquals(3, flextype('entries')->fetch('foo', ['from' => 'collection'])->count());
|
||||
$this->assertEquals(12, flextype('entries')->fetchSingle('foo')->count());
|
||||
$this->assertEquals('foo', flextype('entries')->fetchSingle('foo')['id']);
|
||||
$this->assertEquals(12, flextype('entries')->fetchSingle('foo', [])->count());
|
||||
$this->assertEquals('foo', flextype('entries')->fetchSingle('foo')['id']);
|
||||
$this->assertEquals(3, flextype('entries')->fetchCollection('foo')->count());
|
||||
|
||||
$this->assertEquals('Bar', flextype('entries')->fetch('foo/bar')['title']);
|
||||
$this->assertEquals('Baz', flextype('entries')->fetch('foo/baz')['title']);
|
||||
$this->assertEquals('Zed', flextype('entries')->fetch('foo/zed')['title']);
|
||||
$this->assertEquals('Bar', flextype('entries')->fetchSingle('foo/bar')['title']);
|
||||
$this->assertEquals('Baz', flextype('entries')->fetchSingle('foo/baz')['title']);
|
||||
$this->assertEquals('Zed', flextype('entries')->fetchSingle('foo/zed')['title']);
|
||||
|
||||
flextype('entries')->setStorage('fetch.id', 'wrong-entry');
|
||||
$this->assertEquals(0, flextype('entries')->fetch('wrong-entry')->count());
|
||||
$this->assertEquals(0, flextype('entries')->fetchSingle('wrong-entry')->count());
|
||||
flextype('entries')->setStorage('fetch.id', 'wrong-entry');
|
||||
$this->assertEquals(0, flextype('entries')->fetch('wrong-entry')->count());
|
||||
$this->assertEquals(0, flextype('entries')->fetchSingle('wrong-entry')->count());
|
||||
|
||||
$this->assertTrue(count(flextype('entries')->fetch('foo', ['from' => 'collection'])) > 0);
|
||||
$this->assertTrue(count(flextype('entries')->fetchCollection('foo')) > 0);
|
||||
|
||||
/*
|
||||
flextype('emitter')->addListener('onEntriesFetchCollectionHasResult', static function (): void {
|
||||
|
@@ -13,7 +13,7 @@ afterEach(function (): void {
|
||||
test('test CreatedAtField', function () {
|
||||
// 1
|
||||
flextype('entries')->create('foo', []);
|
||||
$created_at = flextype('entries')->fetch('foo')['created_at'];
|
||||
$created_at = flextype('entries')->fetchSingle('foo')['created_at'];
|
||||
$this->assertTrue(strlen($created_at) > 0);
|
||||
$this->assertTrue((ctype_digit($created_at) && strtotime(date('Y-m-d H:i:s', $created_at)) === (int)$created_at));
|
||||
});
|
||||
|
@@ -12,10 +12,10 @@ afterEach(function (): void {
|
||||
|
||||
test('test CreatedByField', function () {
|
||||
flextype('entries')->create('foo', []);
|
||||
$created_by = flextype('entries')->fetch('foo')['created_by'];
|
||||
$created_by = flextype('entries')->fetchSingle('foo')['created_by'];
|
||||
$this->assertEquals('', $created_by);
|
||||
|
||||
flextype('entries')->create('bar', ['created_by' => 'Zed']);
|
||||
$created_by = flextype('entries')->fetch('bar')['created_by'];
|
||||
$created_by = flextype('entries')->fetchSingle('bar')['created_by'];
|
||||
$this->assertEquals('Zed', $created_by);
|
||||
});
|
||||
|
@@ -10,17 +10,17 @@ afterEach(function (): void {
|
||||
filesystem()->directory(PATH['project'] . '/entries')->delete();
|
||||
});
|
||||
|
||||
test('test fetchField for blog', function () {
|
||||
test('test entries field 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');
|
||||
$blog = flextype('entries')->fetchSingle('blog');
|
||||
|
||||
$this->assertEquals(14, $blog->count());
|
||||
});
|
||||
|
||||
test('test fetchField for catalog', function () {
|
||||
test('test entries field for catalog', function () {
|
||||
|
||||
// Create catalog
|
||||
flextype('entries')->create('catalog', flextype('frontmatter')->decode(filesystem()->file(ROOT_DIR . '/tests/Foundation/Entries/Fields/fixtures/entries/catalog/entry.md')->get()));
|
||||
@@ -38,7 +38,7 @@ test('test fetchField for catalog', function () {
|
||||
// Create banner
|
||||
flextype('entries')->create('banner', ['title' => 'Banner']);
|
||||
|
||||
$catalogSingle = flextype('entries')->fetch('catalog');
|
||||
$catalogSingle = flextype('entries')->fetchSingle('catalog');
|
||||
|
||||
$this->assertEquals(16, $catalogSingle->count());
|
||||
$this->assertEquals('Catalog', $catalogSingle['title']);
|
||||
@@ -50,20 +50,20 @@ test('test fetchField for catalog', function () {
|
||||
$this->assertTrue(isset($catalogSingle['discounts']['discounts/30-off']));
|
||||
$this->assertEquals('30% off', $catalogSingle['discounts']['discounts/30-off']['title']);
|
||||
|
||||
$catalogCollection = flextype('entries')->fetch('catalog', ['from' => 'collection']);
|
||||
$catalogCollection = flextype('entries')->fetchCollection('catalog');
|
||||
$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', ['from' => 'collection', 'find' => ['depth' => ['>0', '<4']]]);
|
||||
$catalogLongCollecion = flextype('entries')->fetchCollection('catalog', ['find' => ['depth' => ['>0', '<4']]]);
|
||||
$this->assertEquals(5, $catalogLongCollecion->count());
|
||||
|
||||
$banner = flextype('entries')->fetch('banner');
|
||||
$banner = flextype('entries')->fetchSingle('banner');
|
||||
$this->assertEquals('Banner', $banner['title']);
|
||||
$this->assertEquals('banner', $banner['id']);
|
||||
});
|
||||
|
||||
test('test fetchField for albmus', function () {
|
||||
test('test entries field for albmus', function () {
|
||||
flextype('entries')->create('root', flextype('frontmatter')->decode(filesystem()->file(ROOT_DIR . '/tests/Foundation/Entries/Fields/fixtures/entries/root/entry.md')->get()));
|
||||
|
||||
flextype('entries')->create('albums', flextype('frontmatter')->decode(filesystem()->file(ROOT_DIR . '/tests/Foundation/Entries/Fields/fixtures/entries/root/albums/entry.md')->get()));
|
||||
@@ -74,16 +74,18 @@ test('test fetchField for albmus', function () {
|
||||
flextype('entries')->create('banners/1', ['title' => 'Banner1']);
|
||||
flextype('entries')->create('banners/2', ['title' => 'Banner2']);
|
||||
|
||||
$root = flextype('entries')->fetchSingle('root');
|
||||
|
||||
$this->assertEquals(16, $root->count());
|
||||
});
|
||||
|
||||
test('test fetchField for long nested entries', function () {
|
||||
test('test entries field for long nested entries', function () {
|
||||
flextype('entries')->create('level1', flextype('frontmatter')->decode(filesystem()->file(ROOT_DIR . '/tests/Foundation/Entries/Fields/fixtures/entries/level1/entry.md')->get()));
|
||||
flextype('entries')->create('level1/level2', flextype('frontmatter')->decode(filesystem()->file(ROOT_DIR . '/tests/Foundation/Entries/Fields/fixtures/entries/level1/level2/entry.md')->get()));
|
||||
flextype('entries')->create('level1/level2/level3', flextype('frontmatter')->decode(filesystem()->file(ROOT_DIR . '/tests/Foundation/Entries/Fields/fixtures/entries/level1/level2/level3/entry.md')->get()));
|
||||
flextype('entries')->create('level1/level2/level3/level4', flextype('frontmatter')->decode(filesystem()->file(ROOT_DIR . '/tests/Foundation/Entries/Fields/fixtures/entries/level1/level2/level3/level4/entry.md')->get()));
|
||||
|
||||
$level = flextype('entries')->fetch('level1')->sortKeys();
|
||||
$level = flextype('entries')->fetchSingle('level1');
|
||||
|
||||
$this->assertEquals(14, $level->count());
|
||||
$this->assertEquals('level1/level2', $level['root']['id']);
|
@@ -12,10 +12,10 @@ afterEach(function (): void {
|
||||
|
||||
test('test IdField', function () {
|
||||
flextype('entries')->create('foo', []);
|
||||
$id = flextype('entries')->fetch('foo')['id'];
|
||||
$id = flextype('entries')->fetchSingle('foo')['id'];
|
||||
$this->assertEquals('foo', $id);
|
||||
|
||||
flextype('entries')->create('foo/bar', []);
|
||||
$id = flextype('entries')->fetch('foo/bar')['id'];
|
||||
$id = flextype('entries')->fetchSingle('foo/bar')['id'];
|
||||
$this->assertEquals('foo/bar', $id);
|
||||
});
|
||||
|
@@ -13,7 +13,7 @@ afterEach(function (): void {
|
||||
test('test ModifiedAtField', function () {
|
||||
flextype('entries')->create('foo', []);
|
||||
|
||||
$modified_at = flextype('entries')->fetch('foo')['modified_at'];
|
||||
$modified_at = flextype('entries')->fetchSingle('foo')['modified_at'];
|
||||
|
||||
$this->assertTrue(strlen($modified_at) > 0);
|
||||
$this->assertTrue((ctype_digit($modified_at) && strtotime(date('Y-m-d H:i:s', $modified_at)) === (int)$modified_at));
|
||||
|
@@ -12,8 +12,8 @@ afterEach(function (): void {
|
||||
|
||||
test('test ParsersField', function () {
|
||||
flextype('entries')->create('foo', ['content' => '#Foo', 'parsers' => ['markdown' => ['enabled' => true, 'fields' => ['content']]]]);
|
||||
$this->assertEquals('<h1>Foo</h1>', flextype('entries')->fetch('foo')['content']);
|
||||
$this->assertEquals('<h1>Foo</h1>', flextype('entries')->fetchSingle('foo')['content']);
|
||||
|
||||
flextype('entries')->create('bar', ['content' => '[registry_get name="Bar" default="Zed"]', 'parsers' => ['shortcode' => ['enabled' => true, 'fields' => ['content']]]]);
|
||||
$this->assertEquals('Zed', flextype('entries')->fetch('bar')['content']);
|
||||
$this->assertEquals('Zed', flextype('entries')->fetchSingle('bar')['content']);
|
||||
});
|
||||
|
@@ -13,7 +13,7 @@ afterEach(function (): void {
|
||||
test('test PublishedAtField', function () {
|
||||
flextype('entries')->create('foo', []);
|
||||
|
||||
$published_at = flextype('entries')->fetch('foo')['published_at'];
|
||||
$published_at = flextype('entries')->fetchSingle('foo')['published_at'];
|
||||
|
||||
$this->assertTrue(strlen($published_at) > 0);
|
||||
$this->assertTrue((ctype_digit($published_at) && strtotime(date('Y-m-d H:i:s', $published_at)) === (int)$published_at));
|
||||
|
@@ -12,10 +12,10 @@ afterEach(function (): void {
|
||||
|
||||
test('test PublishedByField', function () {
|
||||
flextype('entries')->create('foo', []);
|
||||
$published_by = flextype('entries')->fetch('foo')['published_by'];
|
||||
$published_by = flextype('entries')->fetchSingle('foo')['published_by'];
|
||||
$this->assertEquals('', $published_by);
|
||||
|
||||
flextype('entries')->create('bar', ['published_by' => 'Zed']);
|
||||
$published_by = flextype('entries')->fetch('bar')['published_by'];
|
||||
$published_by = flextype('entries')->fetchSingle('bar')['published_by'];
|
||||
$this->assertEquals('Zed', $published_by);
|
||||
});
|
||||
|
@@ -14,14 +14,14 @@ test('test RoutableField', function () {
|
||||
flextype('registry')->set('flextype.settings.cache.enabled', false);
|
||||
|
||||
flextype('entries')->create('foo', ['routable' => true]);
|
||||
$routable = flextype('entries')->fetch('foo')['routable'];
|
||||
$routable = flextype('entries')->fetchSingle('foo')['routable'];
|
||||
$this->assertTrue($routable);
|
||||
|
||||
flextype('entries')->create('bar', []);
|
||||
$routable = flextype('entries')->fetch('bar')['routable'];
|
||||
$routable = flextype('entries')->fetchSingle('bar')['routable'];
|
||||
$this->assertTrue($routable);
|
||||
|
||||
flextype('entries')->create('zed', ['routable' => false]);
|
||||
$routable = flextype('entries')->fetch('zed')['routable'];
|
||||
$routable = flextype('entries')->fetchSingle('zed')['routable'];
|
||||
$this->assertFalse($routable);
|
||||
});
|
||||
|
@@ -12,10 +12,10 @@ afterEach(function (): void {
|
||||
|
||||
test('test SlugField', function () {
|
||||
flextype('entries')->create('foo', []);
|
||||
$slug = flextype('entries')->fetch('foo')['slug'];
|
||||
$slug = flextype('entries')->fetchSingle('foo')['slug'];
|
||||
$this->assertEquals('foo', $slug);
|
||||
|
||||
flextype('entries')->create('bar', []);
|
||||
$slug = flextype('entries')->fetch('bar')['slug'];
|
||||
$slug = flextype('entries')->fetchSingle('bar')['slug'];
|
||||
$this->assertEquals('bar', $slug);
|
||||
});
|
||||
|
@@ -14,6 +14,6 @@ afterEach(function (): void {
|
||||
|
||||
test('test UuidField', function () {
|
||||
flextype('entries')->create('foo', []);
|
||||
$uuid = flextype('entries')->fetch('foo')['uuid'];
|
||||
$uuid = flextype('entries')->fetchSingle('foo')['uuid'];
|
||||
$this->assertTrue(v::uuid()->validate($uuid));
|
||||
});
|
||||
|
@@ -12,14 +12,14 @@ afterEach(function (): void {
|
||||
|
||||
test('test VisibilityField', function () {
|
||||
flextype('entries')->create('foo', []);
|
||||
$visibility = flextype('entries')->fetch('foo')['visibility'];
|
||||
$visibility = flextype('entries')->fetchSingle('foo')['visibility'];
|
||||
$this->assertEquals('visible', $visibility);
|
||||
|
||||
flextype('entries')->create('bar', ['visibility' => 'draft']);
|
||||
$visibility = flextype('entries')->fetch('bar')['visibility'];
|
||||
$visibility = flextype('entries')->fetchSingle('bar')['visibility'];
|
||||
$this->assertEquals('draft', $visibility);
|
||||
|
||||
flextype('entries')->create('zed', ['visibility' => 'foobar']);
|
||||
$visibility = flextype('entries')->fetch('zed')['visibility'];
|
||||
$visibility = flextype('entries')->fetchSingle('zed')['visibility'];
|
||||
$this->assertEquals('visible', $visibility);
|
||||
});
|
||||
|
@@ -1,8 +1,8 @@
|
||||
---
|
||||
title: blog
|
||||
fetch:
|
||||
posts:
|
||||
id: blog
|
||||
options:
|
||||
from: collection
|
||||
entries:
|
||||
fetchCollection:
|
||||
posts:
|
||||
id: blog
|
||||
options: []
|
||||
---
|
||||
|
@@ -1,27 +1,26 @@
|
||||
---
|
||||
title: GT
|
||||
brand: gt
|
||||
fetch:
|
||||
discounts_available:
|
||||
id: discounts
|
||||
options:
|
||||
from: collection
|
||||
filter:
|
||||
where:
|
||||
-
|
||||
key: category
|
||||
operator: eq
|
||||
value: bikes
|
||||
label1:
|
||||
id: discounts/50-off
|
||||
options:
|
||||
from: single
|
||||
filter:
|
||||
limit: 3
|
||||
label2:
|
||||
id: discounts/30-off
|
||||
options:
|
||||
from: single
|
||||
filter:
|
||||
limit: 2
|
||||
entries:
|
||||
fetchCollection:
|
||||
discounts_available:
|
||||
id: discounts
|
||||
options:
|
||||
filter:
|
||||
where:
|
||||
-
|
||||
key: category
|
||||
operator: eq
|
||||
value: bikes
|
||||
fetchSingle:
|
||||
label1:
|
||||
id: discounts/50-off
|
||||
options:
|
||||
filter:
|
||||
limit: 3
|
||||
label2:
|
||||
id: discounts/30-off
|
||||
options:
|
||||
filter:
|
||||
limit: 2
|
||||
---
|
||||
|
@@ -1,14 +1,15 @@
|
||||
---
|
||||
title: Norco
|
||||
brand: norco
|
||||
fetch:
|
||||
label:
|
||||
from: single
|
||||
id: discounts/30-off
|
||||
options:
|
||||
from: collection
|
||||
discounts:
|
||||
id: discounts
|
||||
options:
|
||||
from: collection
|
||||
entries:
|
||||
fetchSingle:
|
||||
label:
|
||||
id: discounts/30-off
|
||||
options:
|
||||
from: collection
|
||||
fetchCollection:
|
||||
discounts:
|
||||
id: discounts
|
||||
options:
|
||||
from: collection
|
||||
---
|
||||
|
@@ -1,36 +1,35 @@
|
||||
---
|
||||
title: Catalog
|
||||
visibility: draft
|
||||
fetch:
|
||||
label1:
|
||||
id: discounts/50-off
|
||||
options:
|
||||
from: single
|
||||
filter:
|
||||
limit: 4
|
||||
bikes:
|
||||
id: catalog/bikes
|
||||
options:
|
||||
from: collection
|
||||
filter:
|
||||
where:
|
||||
-
|
||||
key: brand
|
||||
operator: eq
|
||||
value: gt
|
||||
limit: 10
|
||||
discounts:
|
||||
id: discounts
|
||||
options:
|
||||
from: collection
|
||||
filter:
|
||||
where:
|
||||
-
|
||||
key: title
|
||||
operator: eq
|
||||
value: '30% off'
|
||||
-
|
||||
key: category
|
||||
operator: eq
|
||||
value: bikes
|
||||
entries:
|
||||
fetchSingle:
|
||||
label1:
|
||||
id: discounts/50-off
|
||||
options:
|
||||
filter:
|
||||
limit: 4
|
||||
fetchCollection:
|
||||
bikes:
|
||||
id: catalog/bikes
|
||||
options:
|
||||
filter:
|
||||
where:
|
||||
-
|
||||
key: brand
|
||||
operator: eq
|
||||
value: gt
|
||||
limit: 10
|
||||
discounts:
|
||||
id: discounts
|
||||
options:
|
||||
filter:
|
||||
where:
|
||||
-
|
||||
key: title
|
||||
operator: eq
|
||||
value: '30% off'
|
||||
-
|
||||
key: category
|
||||
operator: eq
|
||||
value: bikes
|
||||
---
|
||||
|
@@ -1,6 +1,7 @@
|
||||
---
|
||||
title: level1
|
||||
fetch:
|
||||
root:
|
||||
id: level1/level2
|
||||
entries:
|
||||
fetchSingle:
|
||||
root:
|
||||
id: level1/level2
|
||||
---
|
||||
|
@@ -1,6 +1,7 @@
|
||||
---
|
||||
title: level2
|
||||
fetch:
|
||||
root:
|
||||
id: level1/level2/level3
|
||||
entries:
|
||||
fetchSingle:
|
||||
root:
|
||||
id: level1/level2/level3
|
||||
---
|
||||
|
@@ -1,6 +1,7 @@
|
||||
---
|
||||
title: level3
|
||||
fetch:
|
||||
root:
|
||||
id: level1/level2/level3/level4
|
||||
entries:
|
||||
fetchSingle:
|
||||
root:
|
||||
id: level1/level2/level3/level4
|
||||
---
|
||||
|
@@ -1,22 +1,19 @@
|
||||
---
|
||||
title: Album 1
|
||||
fetch:
|
||||
banner-single:
|
||||
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:
|
||||
id: banners/2
|
||||
entries:
|
||||
fetchSingle:
|
||||
banner-single:
|
||||
id: banners
|
||||
banner-single-2:
|
||||
id: banners/2
|
||||
fetchCollection:
|
||||
banners-collection:
|
||||
id: banners
|
||||
banners-collection-2:
|
||||
id: banners
|
||||
options:
|
||||
filter:
|
||||
limit: 1
|
||||
find:
|
||||
depth: ">0"
|
||||
---
|
||||
|
@@ -1,18 +1,15 @@
|
||||
---
|
||||
title: Root
|
||||
fetch:
|
||||
single:
|
||||
id: albums
|
||||
options:
|
||||
from: single
|
||||
collection:
|
||||
id: albums
|
||||
options:
|
||||
from: collection
|
||||
collectionWithDepth:
|
||||
id: albums
|
||||
options:
|
||||
from: collection
|
||||
find:
|
||||
depth: '>0'
|
||||
entries:
|
||||
fetchSingle:
|
||||
albums:
|
||||
id: albums
|
||||
fetchCollection:
|
||||
collection:
|
||||
id: albums
|
||||
collectionWithDepth:
|
||||
id: albums
|
||||
options:
|
||||
find:
|
||||
depth: '>0'
|
||||
---
|
||||
|
Reference in New Issue
Block a user