Skip to content

Commit

Permalink
feat(shortcodes): fix all shortcodes #199
Browse files Browse the repository at this point in the history
  • Loading branch information
Awilum committed Aug 1, 2021
1 parent c9c4a96 commit 221d3b8
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
6 changes: 3 additions & 3 deletions src/flextype/Support/Parsers/Shortcodes/EntriesShortcode.php
Expand Up @@ -12,8 +12,8 @@
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'));
});
}
4 changes: 2 additions & 2 deletions src/flextype/Support/Parsers/Shortcodes/MediaShortcode.php
Expand Up @@ -12,8 +12,8 @@
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'));
});
}
6 changes: 3 additions & 3 deletions src/flextype/Support/Parsers/Shortcodes/RawShortcode.php
Expand Up @@ -14,10 +14,10 @@
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']));
}
6 changes: 3 additions & 3 deletions src/flextype/Support/Parsers/Shortcodes/RegistryShortcode.php
Expand Up @@ -12,8 +12,8 @@
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'));
});
}
10 changes: 5 additions & 5 deletions src/flextype/Support/Parsers/Shortcodes/UrlShortcode.php
Expand Up @@ -13,12 +13,12 @@
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();
});
}

0 comments on commit 221d3b8

Please sign in to comment.