1
0
mirror of https://github.com/flextype/flextype.git synced 2025-08-08 06:06:45 +02:00

feat(shortcodes): fix all shortcodes #199

This commit is contained in:
Awilum
2021-08-01 10:55:07 +03:00
parent c9c4a9658b
commit 221d3b8553
5 changed files with 16 additions and 16 deletions

View File

@@ -12,8 +12,8 @@ namespace Flextype\Support\Parsers\Shortcodes;
use Thunder\Shortcode\Shortcode\ShortcodeInterface;
// Shortcode: [entries_fetch id="entry-id" field="field-name" default="default-value"]
if (flextype('registry')->get('flextype.settings.parsers.shortcode.shortcodes.content.enabled')) {
flextype('parsers')->shortcode()->addHandler('entries_fetch', static function (ShortcodeInterface $s) {
return arrays(flextype('entries')->fetch($s->getParameter('id')))->get($s->getParameter('field'), $s->getParameter('default'));
if (registry()->get('flextype.settings.parsers.shortcodes.entries.enabled')) {
parsers()->shortcodes()->addHandler('entries_fetch', static function (ShortcodeInterface $s) {
return arrays(entries()->fetch($s->getParameter('id')))->get($s->getParameter('field'), $s->getParameter('default'));
});
}

View File

@@ -12,8 +12,8 @@ namespace Flextype\Support\Parsers\Shortcodes;
use Thunder\Shortcode\Shortcode\ShortcodeInterface;
// Shortcode: [media_files_fetch id="media-id" field="field-name" default="default-value"]
if (flextype('registry')->get('flextype.settings.parsers.shortcode.shortcodes.media.enabled')) {
flextype('parsers')->shortcode()->addHandler('media_files_fetch', static function (ShortcodeInterface $s) {
if (registry()->get('flextype.settings.parsers.shortcodes.media.enabled')) {
parsers()->shortcodes()->addHandler('media_files_fetch', static function (ShortcodeInterface $s) {
return arrays(flextype('media')->files()->fetch($s->getParameter('id')))->get($s->getParameter('field'), $s->getParameter('default'));
});
}

View File

@@ -14,10 +14,10 @@ use Thunder\Shortcode\Events;
use Thunder\Shortcode\Shortcode\ShortcodeInterface;
// Shortcode: [raw]
if (flextype('registry')->get('flextype.settings.parsers.shortcode.shortcodes.raw.enabled')) {
flextype('parsers')->shortcode()->addHandler('raw', static function (ShortcodeInterface $s) {
if (registry()->get('flextype.settings.parsers.shortcodes.raw.enabled')) {
parsers()->shortcodes()->addHandler('raw', static function (ShortcodeInterface $s) {
return $s->getContent();
});
flextype('parsers')->shortcode()->addEventHandler(Events::FILTER_SHORTCODES, new FilterRawEventHandler(['raw']));
parsers()->shortcodes()->addEventHandler(Events::FILTER_SHORTCODES, new FilterRawEventHandler(['raw']));
}

View File

@@ -12,8 +12,8 @@ namespace Flextype\Support\Parsers\Shortcodes;
use Thunder\Shortcode\Shortcode\ShortcodeInterface;
// Shortcode: [registry_get name="item-name" default="default-value"]
if (flextype('registry')->get('flextype.settings.parsers.shortcode.shortcodes.registry.enabled')) {
flextype('parsers')->shortcode()->addHandler('registry_get', static function (ShortcodeInterface $s) {
return flextype('registry')->get($s->getParameter('name'), $s->getParameter('default'));
if (registry()->get('flextype.settings.parsers.shortcodes.registry.enabled')) {
parsers()->shortcodes()->addHandler('registry_get', static function (ShortcodeInterface $s) {
return registry()->get($s->getParameter('name'), $s->getParameter('default'));
});
}

View File

@@ -13,12 +13,12 @@ use Slim\Http\Environment;
use Slim\Http\Uri;
// Shortcode: [url]
if (flextype('registry')->get('flextype.settings.parsers.shortcode.shortcodes.url.enabled')) {
flextype('parsers')->shortcode()->addHandler('url', static function () {
if (flextype('registry')->has('flextype.settings.url') && flextype('registry')->get('flextype.settings.url') !== '') {
return flextype('registry')->get('flextype.settings.url');
if (registry()->get('flextype.settings.parsers.shortcodes.url.enabled')) {
parsers()->shortcodes()->addHandler('url', static function () {
if (registry()->has('flextype.settings.url') && registry()->get('flextype.settings.url') !== '') {
return registry()->get('flextype.settings.url');
}
return Uri::createFromEnvironment(new Environment($_SERVER))->getBaseUrl();
return app()->getBasePath();
});
}