From 78e9cff2c4e9ec9dbda27d540c5cff8210f7e7e1 Mon Sep 17 00:00:00 2001 From: Awilum Date: Mon, 9 May 2022 16:31:14 +0300 Subject: [PATCH] feat(diretives): add `json` type and logic upd for `array` type --- .../core/Entries/Directives/TypesDirective.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/flextype/core/Entries/Directives/TypesDirective.php b/src/flextype/core/Entries/Directives/TypesDirective.php index d55b8962..9bc99c99 100644 --- a/src/flextype/core/Entries/Directives/TypesDirective.php +++ b/src/flextype/core/Entries/Directives/TypesDirective.php @@ -34,19 +34,26 @@ emitter()->addListener('onEntriesFetchSingleDirectives', static function (): voi $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 = strings($field)->toArray(','); + $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 = collection(strings($field)->toArray(',')); + $field = collectionFromQueryString($field->toString()); } } elseif (strings($field)->contains('@type:null')) { $field = null;