TwigTest example

public function getFilters(): array
    {
        return [
            new TwigFilter('humanize', [FormRenderer::class, 'humanize']),
            new TwigFilter('form_encode_currency', [FormRenderer::class, 'encodeCurrency']['is_safe' => ['html'], 'needs_environment' => true]),
        ];
    }

    public function getTests(): array
    {
        return [
            new TwigTest('selectedchoice', 'Symfony\Bridge\Twig\Extension\twig_is_selected_choice'),
            new TwigTest('rootform', 'Symfony\Bridge\Twig\Extension\twig_is_root_form'),
        ];
    }

    public function getFieldName(FormView $view): string
    {
        $view->setRendered();

        return $view->vars['full_name'];
    }

    

    public function createArray(array $array): ArrayFacade
    {
        return new ArrayFacade($array);
    }

    public function getTests(): array
    {
        return [
            // adds test: "var is true"             new TwigTest('true', null, ['node_class' => TrueTest::class]),
            // adds test: "var is false"             new TwigTest('false', null, ['node_class' => FalseTest::class]),
            // adds test: "var is array"             new TwigTest('array', null, ['node_class' => ArrayTest::class]),
            // adds test: "var is bool" / "var is boolean"             new TwigTest('bool', null, ['node_class' => BooleanTest::class]),
            new TwigTest('boolean', null, ['node_class' => BooleanTest::class]),
            // adds test: "var is callable"             new TwigTest('callable', null, ['node_class' => CallableTest::class]),
            // adds test: "var is float"             new TwigTest('float', null, ['node_class' => FloatTest::class]),
            
use Shopware\Core\Framework\Log\Package;
use Twig\Extension\AbstractExtension;
use Twig\TwigTest;

#[Package('core')] class InstanceOfExtension extends AbstractExtension
{
    public function getTests(): array
    {
        return [
            'instanceof' => new TwigTest('instanceof', $this->isInstanceOf(...)),
        ];
    }

    public function isInstanceOf($var$class): bool
    {
        return (new \ReflectionClass($class))->isInstance($var);
    }
}
Home | Imprint | This part of the site doesn't use cookies.