Skip to content

Commit dc177cb

Browse files
committed
TwigRenderer is used by jQueryFormToRemote
1 parent 8a033f0 commit dc177cb

2 files changed

Lines changed: 20 additions & 4 deletions

File tree

Helper/JqueryHelper.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Ecommit\UtilBundle\Helper\UtilHelper;
1515
use Symfony\Component\Form\FormView;
1616
use Symfony\Component\OptionsResolver\OptionsResolver;
17+
use Twig_Environment;
1718

1819
class JqueryHelper
1920
{
@@ -23,13 +24,20 @@ class JqueryHelper
2324
*/
2425
protected $util;
2526

27+
/**
28+
* @var Twig_Environment
29+
*/
30+
protected $templating;
31+
2632
/**
2733
* Constructor
2834
* @param UtilHelper $utilHelper
35+
* @param Twig_Environment $templating
2936
*/
30-
public function __construct(UtilHelper $util)
37+
public function __construct(UtilHelper $util, Twig_Environment $templating)
3138
{
3239
$this->util = $util;
40+
$this->templating = $templating;
3341
}
3442

3543

@@ -250,14 +258,21 @@ public function jQueryButtonToRemote($name, $url, $options = array(), $htmlOptio
250258
*/
251259
public function jQueryFormToRemote($form, $options = array(), $htmlOptions = array())
252260
{
261+
if ($form instanceof FormView) {
262+
$options['form'] = true;
263+
$htmlOptions['onsubmit'] = $this->jQueryRemoteFunction($form->vars['action'], $options) . '; return false;';
264+
265+
//Après suppression du BC (ci-dessous), la méthode devra être uniquement ce cas
266+
return $this->templating->getRuntime('Symfony\Bridge\Twig\Form\TwigRenderer')
267+
->renderBlock($form, 'form_start', ['attr' => $htmlOptions]);
268+
}
269+
253270
//Set Url
254271
if (isset($options['url'])) {
255272
$url = $options['url'];
256273
unset($options['url']);
257274
} else {
258-
if ($form instanceof FormView) {
259-
$url = $form->vars['action'];
260-
} elseif (is_string($form)) {
275+
if (is_string($form)) {
261276
// BC
262277
$url = $form;
263278
trigger_error('Use url in jQueryFormToRemote\'s first argument is deprecated since 2.2 version.', E_USER_DEPRECATED);

Resources/config/services.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<services>
55
<service id="ecommit_javascript.helper.jquery_helper" class="Ecommit\JavascriptBundle\Helper\JqueryHelper">
66
<argument type="service" id="ecommit_util.helper" />
7+
<argument type="service" id="twig"/>
78
</service>
89

910
<service id="ecommit_javascript.twig.jquery_extension" class="Ecommit\JavascriptBundle\Twig\JqueryExtension">

0 commit comments

Comments
 (0)