diff --git a/src/flextype/core/Parsers/Shortcodes/FieldShortcode.php b/src/flextype/core/Parsers/Shortcodes/FieldShortcode.php new file mode 100644 index 00000000..97699c46 --- /dev/null +++ b/src/flextype/core/Parsers/Shortcodes/FieldShortcode.php @@ -0,0 +1,30 @@ +shortcodes()->addHandler('field', static function (ShortcodeInterface $s) { + if (! registry()->get('flextype.settings.parsers.shortcodes.shortcodes.field.enabled')) { + return ''; + } + + return entries()->registry()->get('methods.fetch.result.' . parsers()->shortcodes()->parse($s->getBBCode())); +}); diff --git a/src/flextype/settings.yaml b/src/flextype/settings.yaml index 755051b6..16fcf9e0 100644 --- a/src/flextype/settings.yaml +++ b/src/flextype/settings.yaml @@ -628,7 +628,10 @@ parsers: var: enabled: true path: "/src/flextype/core/Parsers/Shortcodes/VarShortcode.php" - + field: + enabled: true + path: "/src/flextype/core/Parsers/Shortcodes/FieldShortcode.php" + # CORS # # CORS (Cross-origin resource sharing) allows JavaScript web apps to make HTTP requests to other domains. diff --git a/tests/fixtures/settings/settings.yaml b/tests/fixtures/settings/settings.yaml index 401918b0..60df05b2 100644 --- a/tests/fixtures/settings/settings.yaml +++ b/tests/fixtures/settings/settings.yaml @@ -609,7 +609,10 @@ parsers: var: enabled: true path: "/src/flextype/core/Parsers/Shortcodes/VarShortcode.php" - + field: + enabled: true + path: "/src/flextype/core/Parsers/Shortcodes/FieldShortcode.php" + # CORS # # CORS (Cross-origin resource sharing) allows JavaScript web apps to make HTTP requests to other domains. diff --git a/tests/src/flextype/core/Parsers/Shortcodes/FieldShortcodeTest.php b/tests/src/flextype/core/Parsers/Shortcodes/FieldShortcodeTest.php new file mode 100644 index 00000000..cfa96d72 --- /dev/null +++ b/tests/src/flextype/core/Parsers/Shortcodes/FieldShortcodeTest.php @@ -0,0 +1,16 @@ +directory(PATH['project'] . '/entries')->ensureExists(0755, true); +}); + +afterEach(function () { + filesystem()->directory(PATH['project'] . '/entries')->delete(); +}); + +test('field shortcode', function () { + expect(entries()->create('foo', ['title' => '(field:id)']))->toBeTrue(); + expect(entries()->fetch('foo')['title'])->toBe('foo'); +}); \ No newline at end of file