mirror of
https://github.com/flextype/flextype.git
synced 2025-08-08 06:06:45 +02:00
feat(shortcodes): add const
shortcode
This commit is contained in:
40
src/flextype/core/Parsers/Shortcodes/ConstShortcode.php
Normal file
40
src/flextype/core/Parsers/Shortcodes/ConstShortcode.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Flextype - Hybrid Content Management System with the freedom of a headless CMS
|
||||
* and with the full functionality of a traditional CMS!
|
||||
*
|
||||
* Copyright (c) Sergey Romanenko (https://awilum.github.io)
|
||||
*
|
||||
* Licensed under The MIT License.
|
||||
*
|
||||
* For full copyright and license information, please see the LICENSE
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*/
|
||||
|
||||
namespace Flextype\Parsers\Shortcodes;
|
||||
|
||||
use Thunder\Shortcode\Shortcode\ShortcodeInterface;
|
||||
use function registry;
|
||||
|
||||
// Shortcode: const
|
||||
// Usage: (const:PROJECT_DIR)
|
||||
parsers()->shortcodes()->addHandler('const', static function (ShortcodeInterface $s) {
|
||||
if (! registry()->get('flextype.settings.parsers.shortcodes.shortcodes.const.enabled')) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if ($s->getBBCode() !== null) {
|
||||
$const = parsers()->shortcodes()->parse($s->getBBCode());
|
||||
|
||||
if (defined($const)) {
|
||||
return constant($const);
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
});
|
@@ -661,6 +661,9 @@ parsers:
|
||||
uuid:
|
||||
enabled: true
|
||||
path: "/src/flextype/core/Parsers/Shortcodes/UuidShortcode.php"
|
||||
const:
|
||||
enabled: true
|
||||
path: "/src/flextype/core/Parsers/Shortcodes/ConstShortcode.php"
|
||||
var:
|
||||
enabled: true
|
||||
path: "/src/flextype/core/Parsers/Shortcodes/VarShortcode.php"
|
||||
|
3
tests/fixtures/settings/settings.yaml
vendored
3
tests/fixtures/settings/settings.yaml
vendored
@@ -645,6 +645,9 @@ parsers:
|
||||
uuid:
|
||||
enabled: true
|
||||
path: "/src/flextype/core/Parsers/Shortcodes/UuidShortcode.php"
|
||||
const:
|
||||
enabled: true
|
||||
path: "/src/flextype/core/Parsers/Shortcodes/ConstShortcode.php"
|
||||
var:
|
||||
enabled: true
|
||||
path: "/src/flextype/core/Parsers/Shortcodes/VarShortcode.php"
|
||||
|
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
beforeEach(function() {
|
||||
filesystem()->directory(PATH['project'] . '/entries')->ensureExists(0755, true);
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
filesystem()->directory(PATH['project'] . '/entries')->delete();
|
||||
});
|
||||
|
||||
test('const shortcode', function () {
|
||||
define('foo', 'Foo');
|
||||
expect(entries()->create('const', ['test' => '(const:foo)']))->toBeTrue();
|
||||
expect(entries()->fetch('const')['test'])->toBe('Foo');
|
||||
});
|
Reference in New Issue
Block a user