mirror of
https://github.com/flextype/flextype.git
synced 2025-08-07 21:56:33 +02:00
feat(directive): check if field value is string
This commit is contained in:
@@ -24,9 +24,11 @@ emitter()->addListener('onEntriesFetchSingleDirectives', static function (): voi
|
||||
|
||||
$field = entries()->registry()->get('methods.fetch.field');
|
||||
|
||||
if (strings($field)->contains('@parser:markdown')) {
|
||||
$field = strings(parsers()->markdown()->parse($field))->replace('@parser:markdown', '')->trim()->toString();
|
||||
}
|
||||
if (is_string($field)) {
|
||||
if (strings($field)->contains('@parser:markdown')) {
|
||||
$field = strings(parsers()->markdown()->parse($field))->replace('@parser:markdown', '')->trim()->toString();
|
||||
}
|
||||
}
|
||||
|
||||
entries()->registry()->set('methods.fetch.field', $field);
|
||||
});
|
@@ -24,10 +24,12 @@ emitter()->addListener('onEntriesFetchSingleDirectives', static function (): voi
|
||||
|
||||
$field = entries()->registry()->get('methods.fetch.field');
|
||||
|
||||
if (strings($field)->contains('@parser:shortcodes')) {
|
||||
$field = strings(parsers()->shortcodes()->parse($field))->replace('@parser:shortcodes', '')->trim()->toString();
|
||||
} elseif (registry()->get('flextype.settings.entries.parsers.shortcodes.enabled') !== false) {
|
||||
$field = parsers()->shortcodes()->parse($field);
|
||||
if (is_string($field)) {
|
||||
if (strings($field)->contains('@parser:shortcodes')) {
|
||||
$field = strings(parsers()->shortcodes()->parse($field))->replace('@parser:shortcodes', '')->trim()->toString();
|
||||
} elseif (registry()->get('flextype.settings.entries.parsers.shortcodes.enabled') !== false) {
|
||||
$field = parsers()->shortcodes()->parse($field);
|
||||
}
|
||||
}
|
||||
|
||||
entries()->registry()->set('methods.fetch.field', $field);
|
||||
|
@@ -24,40 +24,42 @@ emitter()->addListener('onEntriesFetchSingleDirectives', static function (): voi
|
||||
|
||||
$field = entries()->registry()->get('methods.fetch.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;
|
||||
} else {
|
||||
$field = collectionFromQueryString($field->toString())->toJson();
|
||||
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;
|
||||
} else {
|
||||
$field = collectionFromQueryString($field->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());
|
||||
} else {
|
||||
$field = collectionFromQueryString($field->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()));
|
||||
} else {
|
||||
$field = collectionFromQueryString($field->toString());
|
||||
}
|
||||
} elseif (strings($field)->contains('@type:null')) {
|
||||
$field = null;
|
||||
}
|
||||
} elseif (strings($field)->contains('@type:array')) {
|
||||
$field = strings($field)->replace('@type:array', '')->trim();
|
||||
if (strings($field)->isJson()) {
|
||||
$field = serializers()->json()->decode($field->toString());
|
||||
} else {
|
||||
$field = collectionFromQueryString($field->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()));
|
||||
} else {
|
||||
$field = collectionFromQueryString($field->toString());
|
||||
}
|
||||
} elseif (strings($field)->contains('@type:null')) {
|
||||
$field = null;
|
||||
}
|
||||
|
||||
|
||||
entries()->registry()->set('methods.fetch.field', $field);
|
||||
});
|
Reference in New Issue
Block a user