|
12 | 12 | namespace Ecommit\JavascriptBundle\Helper; |
13 | 13 |
|
14 | 14 | use Ecommit\UtilBundle\Helper\UtilHelper; |
| 15 | +use Symfony\Component\Form\FormView; |
15 | 16 | use Symfony\Component\OptionsResolver\OptionsResolver; |
16 | 17 |
|
17 | 18 | class JqueryHelper |
@@ -241,14 +242,33 @@ public function jQueryButtonToRemote($name, $url, $options = array(), $htmlOptio |
241 | 242 | * Returns a form tag that will submit using XMLHttpRequest in the background instead of the regular |
242 | 243 | * reloading POST arrangement. |
243 | 244 | * |
244 | | - * @param string $name The button text |
| 245 | + * @param FormView|string $form The form or the url. Url is deprecated since 2.2 version |
245 | 246 | * @param array $options Options. See JqueryHelper::jQueryLinkToRemote |
246 | 247 | * @param array $htmlOptions Html options |
247 | 248 | * @see See JqueryHelper::jQueryLinkToRemote |
248 | 249 | * @return string |
249 | 250 | */ |
250 | | - public function jQueryFormToRemote($url, $options = array(), $htmlOptions = array()) |
| 251 | + public function jQueryFormToRemote($form, $options = array(), $htmlOptions = array()) |
251 | 252 | { |
| 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 | + |
252 | 272 | $options['form'] = true; |
253 | 273 | $htmlOptions['action'] = isset($htmlOptions['action']) ? $htmlOptions['action'] : $url; |
254 | 274 | $htmlOptions['method'] = isset($htmlOptions['method']) ? $htmlOptions['method'] : 'post'; |
|
0 commit comments