FormThemeNode.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Bridge\Twig\Node;
  11. use Symfony\Component\Form\FormRenderer;
  12. use Twig\Compiler;
  13. use Twig\Node\Node;
  14. /**
  15. * @author Fabien Potencier <fabien@symfony.com>
  16. */
  17. final class FormThemeNode extends Node
  18. {
  19. public function __construct(Node $form, Node $resources, int $lineno, string $tag = null, bool $only = false)
  20. {
  21. parent::__construct(['form' => $form, 'resources' => $resources], ['only' => $only], $lineno, $tag);
  22. }
  23. public function compile(Compiler $compiler): void
  24. {
  25. $compiler
  26. ->addDebugInfo($this)
  27. ->write('$this->env->getRuntime(')
  28. ->string(FormRenderer::class)
  29. ->raw(')->setTheme(')
  30. ->subcompile($this->getNode('form'))
  31. ->raw(', ')
  32. ->subcompile($this->getNode('resources'))
  33. ->raw(', ')
  34. ->raw(false === $this->getAttribute('only') ? 'true' : 'false')
  35. ->raw(");\n");
  36. }
  37. }