Created
November 15, 2016 23:35
-
-
Save ABM-Dan/11b8e7665be44a613c15b2bb76a7452a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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