mirror of
https://github.com/flextype/flextype.git
synced 2025-08-06 13:16:45 +02:00
feat(url): update url shortcodes and helpers
This commit is contained in:
@@ -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')) : [],);
|
||||
});
|
@@ -186,7 +186,7 @@ if (! function_exists('getAbsoluteUrl')) {
|
||||
function getAbsoluteUrl(): string
|
||||
{
|
||||
$url = getBaseUrl();
|
||||
$url .= $_SERVER['REQUEST_URI'];
|
||||
$url .= $_SERVER['REQUEST_URI'] ?? '';
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
Reference in New Issue
Block a user