From ade9d8a8115e26e968cf89d0821881c4b6a84572 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 1 May 2016 22:21:23 -0400 Subject: [PATCH 1/2] Restore backwards compatibility with old 2.x in FormHelper. Restore the behavior of the string 'action' option to its former glory. While we've deprecated this it needs to continue working as it did before. Refs #8628 --- .../Test/Case/View/Helper/FormHelperTest.php | 31 +++++++++++++++++++ lib/Cake/View/Helper/FormHelper.php | 3 +- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php index 2ca621712..08ee366a9 100644 --- a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php @@ -8699,6 +8699,37 @@ class FormHelperTest extends CakeTestCase { $this->assertTags($result, $expected); } +/** + * Test that the action key still uses the model as the implicit controller + * when the url option is undefined. While the action parameter is deprecated + * we need it to continue working for the duration of 2.x + * + * @return void + */ + public function testCreateUrlImpliedController() + { + $restore = error_reporting(E_ALL ^ E_USER_DEPRECATED); + $this->Form->request['controller'] = 'posts'; + $result = $this->Form->create('Comment', array( + 'action' => 'addComment', + 'id' => 'addCommentForm', + 'type' => 'POST' + )); + $expected = array( + 'form' => array( + 'action' => '/comments/addComment', + 'id' => 'addCommentForm', + 'method' => 'post', + 'accept-charset' => strtolower(Configure::read('App.encoding')) + ), + 'div' => array('style' => 'display:none;'), + 'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'), + '/div' + ); + $this->assertTags($result, $expected); + error_reporting($restore); + } + /** * Test the onsubmit option for create() * diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index 5d583a9c4..5cad04688 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -382,6 +382,7 @@ class FormHelper extends AppHelper { if (isset($options['action'])) { trigger_error('Using key `action` is deprecated, use `url` directly instead.', E_USER_DEPRECATED); } + if (is_array($options['url']) && isset($options['url']['action'])) { $options['action'] = $options['url']['action']; } @@ -393,7 +394,7 @@ class FormHelper extends AppHelper { if ($options['action'] === null && $options['url'] === null) { $options['action'] = $this->request->here(false); - } elseif (is_array($options['url'])) { + } elseif (empty($options['url']) || is_array($options['url'])) { if (empty($options['url']['controller'])) { if (!empty($model)) { $options['url']['controller'] = Inflector::underscore(Inflector::pluralize($model)); From 32cb25465f5710c97a92d653b1e3df75b7ed3eba Mon Sep 17 00:00:00 2001 From: Mark Sch Date: Mon, 2 May 2016 10:42:42 +0200 Subject: [PATCH 2/2] Make CS tests pass. --- lib/Cake/Test/Case/View/Helper/FormHelperTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php index 08ee366a9..c2627b8d3 100644 --- a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php @@ -8706,8 +8706,7 @@ class FormHelperTest extends CakeTestCase { * * @return void */ - public function testCreateUrlImpliedController() - { + public function testCreateUrlImpliedController() { $restore = error_reporting(E_ALL ^ E_USER_DEPRECATED); $this->Form->request['controller'] = 'posts'; $result = $this->Form->create('Comment', array(