mirror of
https://github.com/flextype/flextype.git
synced 2025-08-08 06:06:45 +02:00
feat(directives): update directives logic
This commit is contained in:
@@ -16,19 +16,21 @@ declare(strict_types=1);
|
||||
|
||||
use Glowy\Arrays\Arrays as Collection;
|
||||
|
||||
emitter()->addListener('onEntriesFetchSingleDirectives', static function (): void {
|
||||
emitter()->addListener('onEntriesFetchSingleField', static function (): void {
|
||||
|
||||
if (! registry()->get('flextype.settings.entries.directives.constants.enabled')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$field = entries()->registry()->get('methods.fetch.field');
|
||||
if (is_string($field)) {
|
||||
$field = strings($field)
|
||||
|
||||
if (is_string($field['value'])) {
|
||||
$field['value'] = strings($field['value'])
|
||||
->replace('@const(ROOT_DIR)', ROOT_DIR)
|
||||
->replace('@const(PATH_PROJECT)', PATH['project'])
|
||||
->toString();
|
||||
}
|
||||
|
||||
entries()->registry()->set('methods.fetch.field', $field);
|
||||
entries()->registry()->set('methods.fetch.field.key', $field['key']);
|
||||
entries()->registry()->set('methods.fetch.field.value', $field['value']);
|
||||
});
|
@@ -16,20 +16,21 @@ declare(strict_types=1);
|
||||
|
||||
use Glowy\Arrays\Arrays as Collection;
|
||||
|
||||
emitter()->addListener('onEntriesFetchSingleDirectives', static function (): void {
|
||||
emitter()->addListener('onEntriesFetchSingleField', static function (): void {
|
||||
|
||||
if (! registry()->get('flextype.settings.entries.directives.fields.enabled')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$field = entries()->registry()->get('methods.fetch.field');
|
||||
$entry = entries()->registry()->get('methods.fetch.result');
|
||||
$field = entries()->registry()->get('methods.fetch.field');
|
||||
$result = entries()->registry()->get('methods.fetch.result');
|
||||
|
||||
if (is_string($field)) {
|
||||
$field = preg_replace_callback('/@field\((.*?)\)/', function($matches) use ($entry) {
|
||||
return $entry[$matches[1]] ?? '';
|
||||
}, $field);
|
||||
if (is_string($field['value'])) {
|
||||
$field['value'] = preg_replace_callback('/@field\((.*?)\)/', function($matches) use ($result) {
|
||||
return collection($result)->get($matches[1]);
|
||||
}, $field['value']);
|
||||
}
|
||||
|
||||
entries()->registry()->set('methods.fetch.field', $field);
|
||||
entries()->registry()->set('methods.fetch.field.key', $field['key']);
|
||||
entries()->registry()->set('methods.fetch.field.value', $field['value']);
|
||||
});
|
@@ -16,7 +16,7 @@ declare(strict_types=1);
|
||||
|
||||
use Glowy\Arrays\Arrays as Collection;
|
||||
|
||||
emitter()->addListener('onEntriesFetchSingleDirectives', static function (): void {
|
||||
emitter()->addListener('onEntriesFetchSingleField', static function (): void {
|
||||
|
||||
if (! registry()->get('flextype.settings.entries.directives.markdown.enabled')) {
|
||||
return;
|
||||
@@ -24,11 +24,12 @@ emitter()->addListener('onEntriesFetchSingleDirectives', static function (): voi
|
||||
|
||||
$field = entries()->registry()->get('methods.fetch.field');
|
||||
|
||||
if (is_string($field)) {
|
||||
if (strings($field)->contains('@markdown')) {
|
||||
$field = strings(parsers()->markdown()->parse($field))->replace('@markdown', '')->trim()->toString();
|
||||
if (is_string($field['value'])) {
|
||||
if (strings($field['value'])->contains('@markdown')) {
|
||||
$field['value'] = strings(parsers()->markdown()->parse($field['value']))->replace('@markdown', '')->trim()->toString();
|
||||
}
|
||||
}
|
||||
|
||||
entries()->registry()->set('methods.fetch.field', $field);
|
||||
entries()->registry()->set('methods.fetch.field.key', $field['key']);
|
||||
entries()->registry()->set('methods.fetch.field.value', $field['value']);
|
||||
});
|
@@ -16,7 +16,7 @@ declare(strict_types=1);
|
||||
|
||||
use Glowy\Arrays\Arrays as Collection;
|
||||
|
||||
emitter()->addListener('onEntriesFetchSingleDirectives', static function (): void {
|
||||
emitter()->addListener('onEntriesFetchSingleField', static function (): void {
|
||||
|
||||
if (! registry()->get('flextype.settings.entries.directives.shortcodes.enabled')) {
|
||||
return;
|
||||
@@ -24,13 +24,14 @@ emitter()->addListener('onEntriesFetchSingleDirectives', static function (): voi
|
||||
|
||||
$field = entries()->registry()->get('methods.fetch.field');
|
||||
|
||||
if (is_string($field)) {
|
||||
if (strings($field)->contains('@shortcodes')) {
|
||||
$field = strings(parsers()->shortcodes()->parse($field))->replace('@shortcodes', '')->trim()->toString();
|
||||
if (is_string($field['value'])) {
|
||||
if (strings($field['value'])->contains('@shortcodes')) {
|
||||
$field['value'] = strings(parsers()->shortcodes()->parse($field['value']))->replace('@shortcodes', '')->trim()->toString();
|
||||
} elseif (registry()->get('flextype.settings.entries.parsers.shortcodes.enabled') !== false) {
|
||||
$field = parsers()->shortcodes()->parse($field);
|
||||
$field['value'] = parsers()->shortcodes()->parse($field['value']);
|
||||
}
|
||||
}
|
||||
|
||||
entries()->registry()->set('methods.fetch.field', $field);
|
||||
entries()->registry()->set('methods.fetch.field.key', $field['key']);
|
||||
entries()->registry()->set('methods.fetch.field.value', $field['value']);
|
||||
});
|
@@ -16,7 +16,7 @@ declare(strict_types=1);
|
||||
|
||||
use Glowy\Arrays\Arrays as Collection;
|
||||
|
||||
emitter()->addListener('onEntriesFetchSingleDirectives', static function (): void {
|
||||
emitter()->addListener('onEntriesFetchSingleField', static function (): void {
|
||||
|
||||
if (! registry()->get('flextype.settings.entries.directives.types.enabled')) {
|
||||
return;
|
||||
@@ -24,42 +24,43 @@ emitter()->addListener('onEntriesFetchSingleDirectives', static function (): voi
|
||||
|
||||
$field = entries()->registry()->get('methods.fetch.field');
|
||||
|
||||
if (is_string($field)) {
|
||||
if (strings($field)->contains('@type(integer)')) {
|
||||
$field = strings(strings($field)->replace('@type(integer)', '')->trim())->toInteger();
|
||||
} elseif (strings($field)->contains('@type(int)')) {
|
||||
$field = strings(strings($field)->replace('@type(int)', '')->trim())->toInteger();
|
||||
} elseif (strings($field)->contains('@type(float)')) {
|
||||
$field = strings(strings($field)->replace('@type(float)', '')->trim())->toFloat();
|
||||
} elseif (strings($field)->contains('@type(boolean)')) {
|
||||
$field = strings(strings($field)->replace('@type(boolean)', '')->trim())->toBoolean();
|
||||
} elseif (strings($field)->contains('@type(bool)')) {
|
||||
$field = strings(strings($field)->replace('@type(bool)', '')->trim())->toBoolean();
|
||||
} elseif (strings($field)->contains('@type(json)')) {
|
||||
$field = strings($field)->replace('@type(json)', '')->trim();
|
||||
if (strings($field)->isJson()) {
|
||||
$field = $field;
|
||||
if (is_string($field['value'])) {
|
||||
if (strings($field['value'])->contains('@type(integer)')) {
|
||||
$field['value'] = strings(strings($field['value'])->replace('@type(integer)', '')->trim())->toInteger();
|
||||
} elseif (strings($field['value'])->contains('@type(int)')) {
|
||||
$field['value'] = strings(strings($field['value'])->replace('@type(int)', '')->trim())->toInteger();
|
||||
} elseif (strings($field['value'])->contains('@type(float)')) {
|
||||
$field['value'] = strings(strings($field['value'])->replace('@type(float)', '')->trim())->toFloat();
|
||||
} elseif (strings($field['value'])->contains('@type(boolean)')) {
|
||||
$field['value'] = strings(strings($field['value'])->replace('@type(boolean)', '')->trim())->toBoolean();
|
||||
} elseif (strings($field['value'])->contains('@type(bool)')) {
|
||||
$field['value'] = strings(strings($field['value'])->replace('@type(bool)', '')->trim())->toBoolean();
|
||||
} elseif (strings($field['value'])->contains('@type(json)')) {
|
||||
$field['value'] = strings($field['value'])->replace('@type(json)', '')->trim();
|
||||
if (strings($field['value'])->isJson()) {
|
||||
$field['value'] = $field['value'];
|
||||
} else {
|
||||
$field = collectionFromQueryString($field->toString())->toJson();
|
||||
$field['value'] = collectionFromQueryString($field['value']->toString())->toJson();
|
||||
}
|
||||
} elseif (strings($field)->contains('@type(array)')) {
|
||||
$field = strings($field)->replace('@type(array)', '')->trim();
|
||||
if (strings($field)->isJson()) {
|
||||
$field = serializers()->json()->decode($field->toString());
|
||||
} elseif (strings($field['value'])->contains('@type(array)')) {
|
||||
$field['value'] = strings($field['value'])->replace('@type(array)', '')->trim();
|
||||
if (strings($field['value'])->isJson()) {
|
||||
$field['value'] = serializers()->json()->decode($field['value']->toString());
|
||||
} else {
|
||||
$field = collectionFromQueryString($field->toString())->toArray();
|
||||
$field['value'] = collectionFromQueryString($field['value']->toString())->toArray();
|
||||
}
|
||||
} elseif (strings($field)->contains('@type(collection)')) {
|
||||
$field = strings($field)->replace('@type(collection)', '')->trim();
|
||||
if (strings($field)->isJson()) {
|
||||
$field = collection(serializers()->json()->decode($field->toString()));
|
||||
} elseif (strings($field['value'])->contains('@type(collection)')) {
|
||||
$field['value'] = strings($field['value'])->replace('@type(collection)', '')->trim();
|
||||
if (strings($field['value'])->isJson()) {
|
||||
$field['value'] = collection(serializers()->json()->decode($field['value']->toString()));
|
||||
} else {
|
||||
$field = collectionFromQueryString($field->toString());
|
||||
$field['value'] = collectionFromQueryString($field['value']->toString());
|
||||
}
|
||||
} elseif (strings($field)->contains('@type(null)')) {
|
||||
$field = null;
|
||||
} elseif (strings($field['value'])->contains('@type(null)')) {
|
||||
$field['value'] = null;
|
||||
}
|
||||
}
|
||||
|
||||
entries()->registry()->set('methods.fetch.field', $field);
|
||||
entries()->registry()->set('methods.fetch.field.key', $field['key']);
|
||||
entries()->registry()->set('methods.fetch.field.value', $field['value']);
|
||||
});
|
Reference in New Issue
Block a user