diff --git a/src/flextype/core/Parsers/Shortcodes/UrlShortcode.php b/src/flextype/core/Parsers/Shortcodes/UrlShortcode.php index e297e052..20928b3e 100644 --- a/src/flextype/core/Parsers/Shortcodes/UrlShortcode.php +++ b/src/flextype/core/Parsers/Shortcodes/UrlShortcode.php @@ -16,19 +16,54 @@ declare(strict_types=1); namespace Flextype\Parsers\Shortcodes; +use Thunder\Shortcode\Shortcode\ShortcodeInterface; use function app; use function parsers; use function registry; -// Shortcode: [url] -parsers()->shortcodes()->addHandler('url', static function () { +// Shortcode: [getBaseUrl] +parsers()->shortcodes()->addHandler('getBaseUrl', static function () { if (! registry()->get('flextype.settings.parsers.shortcodes.shortcodes.url.enabled')) { return ''; } - if (registry()->has('flextype.settings.url') && registry()->get('flextype.settings.url') !== '') { - return registry()->get('flextype.settings.url'); + return getBaseUrl(); +}); + +// Shortcode: [getBasePath] +parsers()->shortcodes()->addHandler('getBasePath', static function () { + if (! registry()->get('flextype.settings.parsers.shortcodes.shortcodes.url.enabled')) { + return ''; } - return app()->getBasePath(); + return getBasePath(); }); + +// Shortcode: [getAbsoluteUrl] +parsers()->shortcodes()->addHandler('getAbsoluteUrl', static function () { + if (! registry()->get('flextype.settings.parsers.shortcodes.shortcodes.url.enabled')) { + return ''; + } + + return getAbsoluteUrl(); +}); + +// Shortcode: [getUriString] +parsers()->shortcodes()->addHandler('getUriString', static function () { + if (! registry()->get('flextype.settings.parsers.shortcodes.shortcodes.url.enabled')) { + return ''; + } + + return getUriString(); +}); + +// Shortcode: [urlFor routeName="route-name" data='{"foo": "Foo"}' queryParams='{"foo": "Foo"}'] +parsers()->shortcodes()->addHandler('urlFor', static function (ShortcodeInterface $s) { + if (! registry()->get('flextype.settings.parsers.shortcodes.shortcodes.url.enabled')) { + return ''; + } + + return urlFor($s->getParameter('routeName'), + $s->getParameter('data') != null ? serializers()->json()->decode($s->getParameter('data')) : [], + $s->getParameter('queryParams') != null ? serializers()->json()->decode($s->getParameter('queryParams')) : [],); +}); \ No newline at end of file diff --git a/src/flextype/helpers/url.php b/src/flextype/helpers/url.php index f741c1a2..91d14633 100644 --- a/src/flextype/helpers/url.php +++ b/src/flextype/helpers/url.php @@ -186,7 +186,7 @@ if (! function_exists('getAbsoluteUrl')) { function getAbsoluteUrl(): string { $url = getBaseUrl(); - $url .= $_SERVER['REQUEST_URI']; + $url .= $_SERVER['REQUEST_URI'] ?? ''; return $url; }