mirror of
https://github.com/flextype/flextype.git
synced 2025-08-08 06:06:45 +02:00
feat(core): drop for now functionality with auto parsing shortcodes and entries fetch
This commit is contained in:
@@ -283,8 +283,8 @@ class Entries
|
||||
// Run event
|
||||
emitter()->emit('onEntriesFetchSingleHasResult');
|
||||
|
||||
// Process fields
|
||||
$result = $this->processFields($this->registry()->get('methods.fetch.result'));
|
||||
// Get the result.
|
||||
$result = $this->registry()->get('methods.fetch.result');
|
||||
|
||||
// Apply `filterCollection` filter for fetch result
|
||||
$this->registry()->set('methods.fetch.result', filterCollection($result, $this->registry()->get('methods.fetch.params.options.filter', [])));
|
||||
@@ -875,88 +875,4 @@ class Entries
|
||||
{
|
||||
return $this->options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process entry field value.
|
||||
*
|
||||
* @param array $entry Entry array.
|
||||
*
|
||||
* @return array Entry with processed fields.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function processFields(array $entry): array
|
||||
{
|
||||
$flatEntry = collection($entry)->dot()->toArray();
|
||||
|
||||
$removeDirectives = function($value) {
|
||||
return strings($value)
|
||||
->replace('@type:array;', '')
|
||||
->replace('@type:string;', '')
|
||||
->replace('@type:bool;', '')
|
||||
->replace('@type:boolean;', '')
|
||||
->replace('@type:int;', '')
|
||||
->replace('@type:integer;', '')
|
||||
->replace('@type:float;', '')
|
||||
->replace('@type:double;', '')
|
||||
->trim()->toString();
|
||||
};
|
||||
|
||||
$processedEntry= [];
|
||||
|
||||
foreach($flatEntry as $key => $value) {
|
||||
|
||||
// Process shortcodes for value if it's string type.
|
||||
$value = gettype($value) == 'string' ? parsers()->shortcodes()->parse($value) : $value;
|
||||
|
||||
if (strings($value)->startsWith('@type:')) {
|
||||
$type = strings($value)->after('@type:')->toString();
|
||||
$argument = strtok($type, ';');
|
||||
|
||||
switch ($argument) {
|
||||
case 'array':
|
||||
$value = $removeDirectives($value);
|
||||
if (strings($value)->isJson()) {
|
||||
$value = collectionFromJson($value)->toArray();
|
||||
} else {
|
||||
$value = collectionFromString($value, ',')->toArray();
|
||||
}
|
||||
break;
|
||||
case 'string':
|
||||
$value = $removeDirectives($value);
|
||||
$value = (string) $value;
|
||||
break;
|
||||
case 'integer':
|
||||
case 'int':
|
||||
$value = $removeDirectives($value);
|
||||
$value = (int) $value;
|
||||
break;
|
||||
case 'boolean':
|
||||
case 'bool':
|
||||
$value = $removeDirectives($value);
|
||||
$value = (bool) $value;
|
||||
break;
|
||||
case 'float':
|
||||
$value = $removeDirectives($value);
|
||||
$value = (float) $value;
|
||||
break;
|
||||
case 'double':
|
||||
$value = $removeDirectives($value);
|
||||
$value = (double) $value;
|
||||
break;
|
||||
default:
|
||||
$value = (string) $value;
|
||||
break;
|
||||
}
|
||||
|
||||
$processedEntry[$key] = $value;
|
||||
} else {
|
||||
$processedEntry[$key] = $value;
|
||||
}
|
||||
|
||||
$processedEntry[$key] = $value;
|
||||
}
|
||||
|
||||
return collection($processedEntry)->undot()->toArray();
|
||||
}
|
||||
}
|
||||
|
@@ -45,12 +45,8 @@ emitter()->addListener('onEntriesFetchSingleHasResult', static function (): void
|
||||
|
||||
if ($parserName == 'shortcodes') {
|
||||
if (collection(entries()->registry()->get('methods.fetch.result'))->has($field)) {
|
||||
$r = parsers()->shortcodes()->parse(entries()->registry()->get('methods.fetch.result.'.$field), $cache);
|
||||
if (strings($r)->isJson()) {
|
||||
$r = collectionFromJson($r)->toArray();
|
||||
}
|
||||
entries()->registry()->set('methods.fetch.result.'.$field,
|
||||
$r);
|
||||
entries()->registry()->set('methods.fetch.result.'.$field,
|
||||
parsers()->shortcodes()->parse(entries()->registry()->get('methods.fetch.result.'.$field), $cache));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -30,55 +30,5 @@ parsers()->shortcodes()->addHandler('entries-fetch', static function (ShortcodeI
|
||||
return '';
|
||||
}
|
||||
|
||||
$id = $s->getParameter('id');
|
||||
$options = [];
|
||||
|
||||
$options['collection'] = $s->getParameter('collection') !== null ? (bool) $s->getParameter('collection') : false;
|
||||
|
||||
if ($s->getParameter('find-depth-from') || $s->getParameter('find-depth-to')) {
|
||||
$options['find']['depth'] = [];
|
||||
$s->getParameter('find-depth-from') !== null and array_push($options['find']['depth'], $s->getParameter('find-depth-from'));
|
||||
$s->getParameter('find-depth-to') !== null and array_push($options['find']['depth'], $s->getParameter('find-depth-from'));
|
||||
}
|
||||
|
||||
if ($s->getParameter('find-date-from') || $s->getParameter('find-date-to')) {
|
||||
$options['find']['date'] = [];
|
||||
$s->getParameter('find-date-from') !== null and array_push($options['find']['date'], $s->getParameter('find-date-from'));
|
||||
$s->getParameter('find-date-to') !== null and array_push($options['find']['date'], $s->getParameter('find-date-from'));
|
||||
}
|
||||
|
||||
if ($s->getParameter('find-size-from') || $s->getParameter('find-size-to')) {
|
||||
$options['find']['size'] = [];
|
||||
$s->getParameter('find-size-from') !== null and array_push($options['find']['size'], $s->getParameter('find-size-from'));
|
||||
$s->getParameter('find-size-to') !== null and array_push($options['find']['size'], $s->getParameter('find-size-from'));
|
||||
}
|
||||
|
||||
$s->getParameter('find-exclude') !== null and $options['find']['exclude'] = $s->getParameter('find-exclude');
|
||||
$s->getParameter('find-contains') !== null and $options['find']['contains'] = $s->getParameter('find-contains');
|
||||
$s->getParameter('find-not-contains') !== null and $options['find']['not_contains'] = $s->getParameter('find-not-contains');
|
||||
$s->getParameter('find-path') !== null and $options['find']['path'] = $s->getParameter('find-path');
|
||||
|
||||
$s->getParameter('filter-sort-by-key') !== null and $options['filter']['sort_by']['key'] = $s->getParameter('filter-sort-by-key');
|
||||
$s->getParameter('filter-sort-by-direction') !== null and $options['filter']['sort_by']['direction'] = $s->getParameter('filter-sort-by-direction');
|
||||
$s->getParameter('filter-group-by') !== null and $options['filter']['group_by'] = $s->getParameter('filter-group-by');
|
||||
$s->getParameter('filter-return') !== null and $options['filter']['return'] = $s->getParameter('filter-return');
|
||||
$s->getParameter('filter-limit') !== null and $options['filter']['limit'] = (int) $s->getParameter('filter-limit');
|
||||
$s->getParameter('filter-offset') !== null and $options['filter']['offset'] = $s->getParameter('filter-offset');
|
||||
$s->getParameter('filter-where') !== null and $options['filter']['where'] = $s->getParameter('filter-where');
|
||||
|
||||
// Re-init Entries service to avoid fields merge conflict for this new shortcode fetch query.
|
||||
|
||||
|
||||
//entries()->registry()->set('methods.fetch.params.id', entries()->registry()->get('methods.fetch.params.id'));
|
||||
//entries()->registry()->set('methods.fetch.params.options', entries()->registry('methods.fetch.params.options'));
|
||||
//entries()->registry()->set('methods.fetch.result', []);
|
||||
|
||||
//(new Entries(registry()->get('flextype.settings.entries')))
|
||||
//dump(entries()->registry()->get('methods.fetch'));
|
||||
//dd(entries()->fetch($id, $options));
|
||||
|
||||
|
||||
|
||||
//dd(entries()->setRegistry()->setOptions(registry()->get('flextype.settings.entries'))->fetch($id, $options));
|
||||
return "@type:array;" . (new Entries(registry()->get('flextype.settings.entries')))->fetch($id, $options)->toJson();
|
||||
return collection(entries()->fetch($s->getParameter('id')))->get($s->getParameter('field'), $s->getParameter('default'));
|
||||
});
|
@@ -10,8 +10,8 @@ afterEach(function () {
|
||||
filesystem()->directory(PATH['project'] . '/entries')->delete();
|
||||
});
|
||||
|
||||
test('[entries_fetch] shortcode', function () {
|
||||
test('[entries-fetch] shortcode', function () {
|
||||
$this->assertTrue(entries()->create('foo', ['title' => 'Foo']));
|
||||
$this->assertEquals('Foo', parsers()->shortcodes()->parse('[entries_fetch id="foo" field="title"]'));
|
||||
$this->assertEquals('Bar', parsers()->shortcodes()->parse('[entries_fetch id="foo" field="bar" default="Bar"]'));
|
||||
$this->assertEquals('Foo', parsers()->shortcodes()->parse('[entries-fetch id="foo" field="title"]'));
|
||||
$this->assertEquals('Bar', parsers()->shortcodes()->parse('[entries-fetch id="foo" field="bar" default="Bar"]'));
|
||||
});
|
||||
|
Reference in New Issue
Block a user