Skip to content

Commit 86859c2

Browse files
committed
#2 [JqueryHelper] Get url in jQueryFormToRemote's first argument is now deprecated. Get now FormView object
The same for ecommit_javascript_jquery_ajax_form Twig function
1 parent 3c7fdd2 commit 86859c2

2 files changed

Lines changed: 25 additions & 5 deletions

File tree

Helper/JqueryHelper.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Ecommit\JavascriptBundle\Helper;
1313

1414
use Ecommit\UtilBundle\Helper\UtilHelper;
15+
use Symfony\Component\Form\FormView;
1516
use Symfony\Component\OptionsResolver\OptionsResolver;
1617

1718
class JqueryHelper
@@ -241,14 +242,33 @@ public function jQueryButtonToRemote($name, $url, $options = array(), $htmlOptio
241242
* Returns a form tag that will submit using XMLHttpRequest in the background instead of the regular
242243
* reloading POST arrangement.
243244
*
244-
* @param string $name The button text
245+
* @param FormView|string $form The form or the url. Url is deprecated since 2.2 version
245246
* @param array $options Options. See JqueryHelper::jQueryLinkToRemote
246247
* @param array $htmlOptions Html options
247248
* @see See JqueryHelper::jQueryLinkToRemote
248249
* @return string
249250
*/
250-
public function jQueryFormToRemote($url, $options = array(), $htmlOptions = array())
251+
public function jQueryFormToRemote($form, $options = array(), $htmlOptions = array())
251252
{
253+
//Set Url
254+
if (isset($options['url'])) {
255+
$url = $options['url'];
256+
unset($options['url']);
257+
} else {
258+
if ($form instanceof FormView) {
259+
$url = $form->vars['action'];
260+
} elseif (is_string($form)) {
261+
// BC
262+
$url = $form;
263+
trigger_error('Use url in jQueryFormToRemote\'s first argument is deprecated since 2.2 version.', E_USER_DEPRECATED);
264+
} else {
265+
throw new \Exception('form msut be FormView object or string value.');
266+
}
267+
}
268+
if (!$url) {
269+
throw new \Exception('Url must be defined.');
270+
}
271+
252272
$options['form'] = true;
253273
$htmlOptions['action'] = isset($htmlOptions['action']) ? $htmlOptions['action'] : $url;
254274
$htmlOptions['method'] = isset($htmlOptions['method']) ? $htmlOptions['method'] : 'post';

Twig/JqueryExtension.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,14 @@ public function jqueryAjaxButton($name, $url, $options = array(), $htmlOptions =
118118
* Returns a form tag that will submit using XMLHttpRequest in the background instead of the regular
119119
* reloading POST arrangement.
120120
*
121-
* @param string $name The button text
121+
* @param FormView|string $form The form or the url. Url is deprecated since 2.2 version
122122
* @param array $options Options. See Manager::jQueryFormToRemote
123123
* @param array $htmlOptions Html options
124124
* @see See Manager::jQueryFormToRemote
125125
* @return string
126126
*/
127-
public function jqueryAjaxForm($url, $options = array(), $htmlOptions = array())
127+
public function jqueryAjaxForm($form, $options = array(), $htmlOptions = array())
128128
{
129-
return $this->jqueryHelper->jQueryFormToRemote($url, $options, $htmlOptions);
129+
return $this->jqueryHelper->jQueryFormToRemote($form, $options, $htmlOptions);
130130
}
131131
}

0 commit comments

Comments
 (0)