Skip to content

Instantly share code, notes, and snippets.

@ABM-Dan
Created November 15, 2016 23:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ABM-Dan/11b8e7665be44a613c15b2bb76a7452a to your computer and use it in GitHub Desktop.
Save ABM-Dan/11b8e7665be44a613c15b2bb76a7452a to your computer and use it in GitHub Desktop.
<?php
namespace CommonBundle\Twig;
use Symfony\Bridge\Twig\Form\TwigRenderer;
use Symfony\Component\Form\FormView;
class FormSubmitExtension extends \Twig_Extension
{
/**
* {@inheritdoc}
*/
public function getFunctions()
{
return [new \Twig_SimpleFunction('form_submit', [$this, 'createSubmitButton'], ['needs_environment' => true, 'is_safe' => ['all']])];
}
/**
* @param \Twig_Environment $env
* @param FormView $formView
* @param string $label
*/
public function createSubmitButton(\Twig_Environment $env, FormView $formView, $label)
{
/** @var TwigRenderer $formRenderer */
$formRenderer = $env->getExtension('form')->renderer;
$submitView = new FormView($formView);
$formRenderer->renderBlock($submitView, 'submit_widget', ['label' => $label]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment