RenderBlockNode.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 Twig\Compiler;
  12. use Twig\Node\Expression\FunctionExpression;
  13. /**
  14. * Compiles a call to {@link \Symfony\Component\Form\FormRendererInterface::renderBlock()}.
  15. *
  16. * The function name is used as block name. For example, if the function name
  17. * is "foo", the block "foo" will be rendered.
  18. *
  19. * @author Bernhard Schussek <bschussek@gmail.com>
  20. */
  21. final class RenderBlockNode extends FunctionExpression
  22. {
  23. public function compile(Compiler $compiler): void
  24. {
  25. $compiler->addDebugInfo($this);
  26. $arguments = iterator_to_array($this->getNode('arguments'));
  27. $compiler->write('$this->env->getRuntime(\'Symfony\Component\Form\FormRenderer\')->renderBlock(');
  28. if (isset($arguments[0])) {
  29. $compiler->subcompile($arguments[0]);
  30. $compiler->raw(', \''.$this->getAttribute('name').'\'');
  31. if (isset($arguments[1])) {
  32. $compiler->raw(', ');
  33. $compiler->subcompile($arguments[1]);
  34. }
  35. }
  36. $compiler->raw(')');
  37. }
  38. }