mirror of
https://github.com/flextype/flextype.git
synced 2025-08-06 13:16:45 +02:00
feat(expressions): add new field
and var
expressions
This commit is contained in:
30
src/flextype/core/Entries/Expressions/FieldExpression.php
Normal file
30
src/flextype/core/Entries/Expressions/FieldExpression.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?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\Entries\Expressions;
|
||||
|
||||
use Symfony\Component\ExpressionLanguage\ExpressionFunction;
|
||||
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
|
||||
|
||||
class FieldExpression implements ExpressionFunctionProviderInterface
|
||||
{
|
||||
public function getFunctions()
|
||||
{
|
||||
return [
|
||||
new ExpressionFunction('field', fn(string $field) => "entries()->registry()->get('methods.fetch.result.' . $field . ')'", fn($arguments, string $field) => entries()->registry()->get('methods.fetch.result.' . $field))
|
||||
];
|
||||
}
|
||||
}
|
30
src/flextype/core/Entries/Expressions/VarExpression.php
Normal file
30
src/flextype/core/Entries/Expressions/VarExpression.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?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\Entries\Expressions;
|
||||
|
||||
use Symfony\Component\ExpressionLanguage\ExpressionFunction;
|
||||
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
|
||||
|
||||
class VarExpression implements ExpressionFunctionProviderInterface
|
||||
{
|
||||
public function getFunctions()
|
||||
{
|
||||
return [
|
||||
new ExpressionFunction('var', fn(string $var) => "entries()->registry()->get('methods.fetch.result.vars.' . $var . ')'", fn($arguments, string $var) => entries()->registry()->get('methods.fetch.result.vars.' . $var))
|
||||
];
|
||||
}
|
||||
}
|
@@ -110,6 +110,12 @@ entries:
|
||||
csrf:
|
||||
enabled: true
|
||||
class: "Flextype\\Entries\\Expressions\\CsrfExpression"
|
||||
var:
|
||||
enabled: true
|
||||
class: "Flextype\\Entries\\Expressions\\VarExpression"
|
||||
field:
|
||||
enabled: true
|
||||
class: "Flextype\\Entries\\Expressions\\FieldExpression"
|
||||
directives:
|
||||
expressions:
|
||||
enabled: true
|
||||
|
6
tests/fixtures/settings/settings.yaml
vendored
6
tests/fixtures/settings/settings.yaml
vendored
@@ -106,6 +106,12 @@ entries:
|
||||
csrf:
|
||||
enabled: true
|
||||
class: "Flextype\\Entries\\Expressions\\CsrfExpression"
|
||||
var:
|
||||
enabled: true
|
||||
class: "Flextype\\Entries\\Expressions\\VarExpression"
|
||||
field:
|
||||
enabled: true
|
||||
class: "Flextype\\Entries\\Expressions\\FieldExpression"
|
||||
directives:
|
||||
expressions:
|
||||
enabled: true
|
||||
|
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
use Flextype\Component\Filesystem\Filesystem;
|
||||
|
||||
beforeEach(function() {
|
||||
filesystem()->directory(PATH['project'] . '/entries')->create();
|
||||
});
|
||||
|
||||
afterEach(function (): void {
|
||||
filesystem()->directory(PATH['project'] . '/entries')->delete();
|
||||
});
|
||||
|
||||
test('field expression', function () {
|
||||
entries()->create('field', ['test' => '[[ field("id") ]]']);
|
||||
expect(entries()->fetch('field')['test'])->toBe('field');
|
||||
});
|
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
use Flextype\Component\Filesystem\Filesystem;
|
||||
|
||||
beforeEach(function() {
|
||||
filesystem()->directory(PATH['project'] . '/entries')->create();
|
||||
});
|
||||
|
||||
afterEach(function (): void {
|
||||
filesystem()->directory(PATH['project'] . '/entries')->delete();
|
||||
});
|
||||
|
||||
test('var expression', function () {
|
||||
entries()->create('var', ['vars' => ['foo' => 'Foo'], 'test' => '[[ var("foo") ]]']);
|
||||
expect(entries()->fetch('var')['test'])->toBe('Foo');
|
||||
});
|
Reference in New Issue
Block a user