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