Browse Source

Merge pull request #7887 from cakephp/3.2-deprecate-action

3.2: Deprecate action in Form::create()
Mark Story 10 years ago
parent
commit
017b7952f8
2 changed files with 9 additions and 8 deletions
  1. 5 1
      src/View/Helper/FormHelper.php
  2. 4 7
      tests/TestCase/View/Helper/FormHelperTest.php

+ 5 - 1
src/View/Helper/FormHelper.php

@@ -317,7 +317,7 @@ class FormHelper extends Helper
      * - `type` Form method defaults to autodetecting based on the form context. If
      *   the form context's isCreate() method returns false, a PUT request will be done.
      * - `action` The controller action the form submits to, (optional). Use this option if you
-     *   don't need to change the controller from the current request's controller.
+     *   don't need to change the controller from the current request's controller. Deprecated since 3.2, use `url`.
      * - `url` The URL the form submits to. Can be a string or a URL array. If you use 'url'
      *    you should leave 'action' undefined.
      * - `encoding` Set the accept-charset encoding for the form. Defaults to `Configure::read('App.encoding')`
@@ -357,6 +357,10 @@ class FormHelper extends Helper
             'idPrefix' => null,
         ];
 
+        if (isset($options['action'])) {
+            trigger_error('Using key `action` is deprecated, use `url` directly instead.', E_USER_DEPRECATED);
+        }
+
         if ($options['idPrefix'] !== null) {
             $this->_idPrefix = $options['idPrefix'];
         }

+ 4 - 7
tests/TestCase/View/Helper/FormHelperTest.php

@@ -658,7 +658,7 @@ class FormHelperTest extends TestCase
         $this->article['defaults'] = ['id' => 1];
         $this->Form->request->here = '/articles/edit/1';
         $this->Form->request['action'] = 'delete';
-        $result = $this->Form->create($this->article, ['action' => 'edit']);
+        $result = $this->Form->create($this->article, ['url' => ['action' => 'edit']]);
         $expected = [
             'form' => [
                 'method' => 'post',
@@ -695,7 +695,7 @@ class FormHelperTest extends TestCase
         $this->assertHtml($expected, $result);
 
         $this->Form->request['controller'] = 'Pages';
-        $result = $this->Form->create($this->article, ['action' => 'signup']);
+        $result = $this->Form->create($this->article, ['url' => ['action' => 'signup']]);
         $expected = [
             'form' => [
                 'method' => 'post', 'action' => '/Pages/signup/1',
@@ -726,9 +726,6 @@ class FormHelperTest extends TestCase
             '/div'
         ];
         $this->assertHtml($expected, $result);
-
-        $result = $this->Form->create(false, ['action' => false]);
-        $this->assertHtml($expected, $result);
     }
 
     /**
@@ -743,7 +740,7 @@ class FormHelperTest extends TestCase
 
         $this->Form->request['controller'] = 'users';
 
-        $result = $this->Form->create(false, ['action' => 'login']);
+        $result = $this->Form->create(false, ['url' => ['action' => 'login']]);
         $expected = [
             'form' => [
                 'method' => 'post', 'action' => '/login',
@@ -783,7 +780,7 @@ class FormHelperTest extends TestCase
         $result = $this->Form->create(
             $this->article,
             [
-                'type' => 'post', 'action' => 'index', 'encoding' => 'iso-8859-1'
+                'type' => 'post', 'url' => ['action' => 'index'], 'encoding' => 'iso-8859-1'
             ]
         );
         $expected = [