diff --git a/src/flextype/core/Parsers/Shortcodes/RegistryShortcode.php b/src/flextype/core/Parsers/Shortcodes/RegistryShortcode.php index 26fca449..38ff86cb 100644 --- a/src/flextype/core/Parsers/Shortcodes/RegistryShortcode.php +++ b/src/flextype/core/Parsers/Shortcodes/RegistryShortcode.php @@ -21,11 +21,25 @@ use Thunder\Shortcode\Shortcode\ShortcodeInterface; use function parsers; use function registry; -// Shortcode: [registry-get id="STRING" default="STRING"] -parsers()->shortcodes()->addHandler('registry-get', static function (ShortcodeInterface $s) { +// Shortcode: [registry] +parsers()->shortcodes()->addHandler('registry', static function (ShortcodeInterface $s) { if (! registry()->get('flextype.settings.parsers.shortcodes.shortcodes.registry.enabled')) { return ''; } - return registry()->get($s->getParameter('id'), $s->getParameter('default')); + $varsDelimeter = $s->getParameter('varsDelimeter') ?: '|'; + + if ($s->getParameter('get') != null) { + + // Get vars + foreach($s->getParameters() as $key => $value) { + $vars = $value !== null ? strings($value)->contains($varsDelimeter) ? explode($varsDelimeter, $value) : [$value] : []; + } + + $result = registry()->get($vars[0], $vars[1] ?? null); + + return is_array($result) ? serializers()->json()->encode($result) : $result; + } + + return ''; }); diff --git a/tests/src/flextype/core/Parsers/Shortcodes/RegistryShortcodeTest.php b/tests/src/flextype/core/Parsers/Shortcodes/RegistryShortcodeTest.php index 878707fa..e89a8969 100644 --- a/tests/src/flextype/core/Parsers/Shortcodes/RegistryShortcodeTest.php +++ b/tests/src/flextype/core/Parsers/Shortcodes/RegistryShortcodeTest.php @@ -2,12 +2,9 @@ declare(strict_types=1); -test('[registry-get] shortcode', function () { - $this->assertEquals('Flextype', - parsers()->shortcodes()->parse('[registry-get id="flextype.manifest.name"]')); - $this->assertEquals('default-value', - parsers()->shortcodes()->parse('[registry-get id="item-name" default="default-value"]')); +test('[registry] shortcode', function () { + expect(strings(parsers()->shortcodes()->parse('[registry get="flextype.manifest"]'))->isJson())->toBeTrue(); + expect(parsers()->shortcodes()->parse('[registry get="flextype.manifest.name"]'))->toBe('Flextype'); + expect(parsers()->shortcodes()->parse('[registry get="flextype.manifest.foo|Default"]'))->toBe('Default'); - registry()->set('flextype.settings.parsers.shortcodes.shortcodes.registry.enabled', false); - $this->assertEquals('', parsers()->shortcodes()->parse('[registry-get id="item-name" default="default-value"]')); });