mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merge pull request #7961 from cakephp/2.8-deprecate-action
Deprecate action in Form::create()
This commit is contained in:
commit
6fbc029b9b
2 changed files with 36 additions and 20 deletions
|
@ -1780,11 +1780,13 @@ class FormHelperTest extends CakeTestCase {
|
||||||
$this->assertFalse(empty($result));
|
$this->assertFalse(empty($result));
|
||||||
$this->assertFalse($this->UserForm->OpenidUrl->validates());
|
$this->assertFalse($this->UserForm->OpenidUrl->validates());
|
||||||
|
|
||||||
$result = $this->Form->create('UserForm', array('type' => 'post', 'action' => 'login'));
|
$result = $this->Form->create('UserForm', array('type' => 'post', 'url' => array('action' => 'login')));
|
||||||
$encoding = strtolower(Configure::read('App.encoding'));
|
$encoding = strtolower(Configure::read('App.encoding'));
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'form' => array(
|
'form' => array(
|
||||||
'method' => 'post', 'action' => '/user_forms/login', 'id' => 'UserFormLoginForm',
|
'action' => '/user_forms/login',
|
||||||
|
'id' => 'UserFormLoginForm',
|
||||||
|
'method' => 'post',
|
||||||
'accept-charset' => $encoding
|
'accept-charset' => $encoding
|
||||||
),
|
),
|
||||||
'div' => array('style' => 'display:none;'),
|
'div' => array('style' => 'display:none;'),
|
||||||
|
@ -1822,7 +1824,7 @@ class FormHelperTest extends CakeTestCase {
|
||||||
$this->assertFalse($this->ValidateUser->validates());
|
$this->assertFalse($this->ValidateUser->validates());
|
||||||
$this->assertFalse($this->ValidateUser->ValidateProfile->validates());
|
$this->assertFalse($this->ValidateUser->ValidateProfile->validates());
|
||||||
|
|
||||||
$result = $this->Form->create('ValidateUser', array('type' => 'post', 'action' => 'add'));
|
$result = $this->Form->create('ValidateUser', array('type' => 'post', 'url' => array('action' => 'add')));
|
||||||
$encoding = strtolower(Configure::read('App.encoding'));
|
$encoding = strtolower(Configure::read('App.encoding'));
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'form' => array('method' => 'post', 'action' => '/validate_users/add', 'id', 'accept-charset' => $encoding),
|
'form' => array('method' => 'post', 'action' => '/validate_users/add', 'id', 'accept-charset' => $encoding),
|
||||||
|
@ -1875,7 +1877,7 @@ class FormHelperTest extends CakeTestCase {
|
||||||
$this->assertFalse($this->ValidateUser->ValidateProfile->validates());
|
$this->assertFalse($this->ValidateUser->ValidateProfile->validates());
|
||||||
$this->assertFalse($this->ValidateUser->ValidateProfile->ValidateItem->validates());
|
$this->assertFalse($this->ValidateUser->ValidateProfile->ValidateItem->validates());
|
||||||
|
|
||||||
$result = $this->Form->create('ValidateUser', array('type' => 'post', 'action' => 'add'));
|
$result = $this->Form->create('ValidateUser', array('type' => 'post', 'url' => array('action' => 'add')));
|
||||||
$encoding = strtolower(Configure::read('App.encoding'));
|
$encoding = strtolower(Configure::read('App.encoding'));
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'form' => array('method' => 'post', 'action' => '/validate_users/add', 'id', 'accept-charset' => $encoding),
|
'form' => array('method' => 'post', 'action' => '/validate_users/add', 'id', 'accept-charset' => $encoding),
|
||||||
|
@ -8539,7 +8541,9 @@ class FormHelperTest extends CakeTestCase {
|
||||||
$result = $this->Form->create('User', array('url' => array('action' => 'login')));
|
$result = $this->Form->create('User', array('url' => array('action' => 'login')));
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'form' => array(
|
'form' => array(
|
||||||
'id' => 'UserAddForm', 'method' => 'post', 'action' => '/users/login',
|
'action' => '/users/login',
|
||||||
|
'id' => 'UserLoginForm',
|
||||||
|
'method' => 'post',
|
||||||
'accept-charset' => $encoding
|
'accept-charset' => $encoding
|
||||||
),
|
),
|
||||||
'div' => array('style' => 'display:none;'),
|
'div' => array('style' => 'display:none;'),
|
||||||
|
@ -8548,7 +8552,7 @@ class FormHelperTest extends CakeTestCase {
|
||||||
);
|
);
|
||||||
$this->assertTags($result, $expected);
|
$this->assertTags($result, $expected);
|
||||||
|
|
||||||
$result = $this->Form->create('User', array('action' => 'login'));
|
$result = $this->Form->create('User', array('url' => array('action' => 'login')));
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'form' => array(
|
'form' => array(
|
||||||
'id' => 'UserLoginForm', 'method' => 'post', 'action' => '/users/login',
|
'id' => 'UserLoginForm', 'method' => 'post', 'action' => '/users/login',
|
||||||
|
@ -8562,7 +8566,12 @@ class FormHelperTest extends CakeTestCase {
|
||||||
|
|
||||||
$result = $this->Form->create('User', array('url' => '/users/login'));
|
$result = $this->Form->create('User', array('url' => '/users/login'));
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'form' => array('method' => 'post', 'action' => '/users/login', 'accept-charset' => $encoding, 'id' => 'UserAddForm'),
|
'form' => array(
|
||||||
|
'action' => '/users/login',
|
||||||
|
'id' => 'UserAddForm',
|
||||||
|
'method' => 'post',
|
||||||
|
'accept-charset' => $encoding
|
||||||
|
),
|
||||||
'div' => array('style' => 'display:none;'),
|
'div' => array('style' => 'display:none;'),
|
||||||
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
'input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST'),
|
||||||
'/div'
|
'/div'
|
||||||
|
@ -8570,7 +8579,7 @@ class FormHelperTest extends CakeTestCase {
|
||||||
$this->assertTags($result, $expected);
|
$this->assertTags($result, $expected);
|
||||||
|
|
||||||
$this->Form->request['controller'] = 'pages';
|
$this->Form->request['controller'] = 'pages';
|
||||||
$result = $this->Form->create('User', array('action' => 'signup'));
|
$result = $this->Form->create('User', array('url' => array('action' => 'signup')));
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'form' => array(
|
'form' => array(
|
||||||
'id' => 'UserSignupForm', 'method' => 'post', 'action' => '/users/signup',
|
'id' => 'UserSignupForm', 'method' => 'post', 'action' => '/users/signup',
|
||||||
|
@ -8588,7 +8597,7 @@ class FormHelperTest extends CakeTestCase {
|
||||||
$result = $this->Form->create(array('url' => array('action' => 'index', 'param')));
|
$result = $this->Form->create(array('url' => array('action' => 'index', 'param')));
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'form' => array(
|
'form' => array(
|
||||||
'id' => 'ContactAddForm', 'method' => 'post', 'action' => '/contacts/index/param',
|
'id' => 'ContactIndexForm', 'method' => 'post', 'action' => '/contacts/index/param',
|
||||||
'accept-charset' => 'utf-8'
|
'accept-charset' => 'utf-8'
|
||||||
),
|
),
|
||||||
'div' => array('style' => 'display:none;'),
|
'div' => array('style' => 'display:none;'),
|
||||||
|
@ -8610,7 +8619,7 @@ class FormHelperTest extends CakeTestCase {
|
||||||
$result = $this->Form->create(array('url' => array('action' => 'index', 'param'), 'default' => false));
|
$result = $this->Form->create(array('url' => array('action' => 'index', 'param'), 'default' => false));
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'form' => array(
|
'form' => array(
|
||||||
'id' => 'ContactAddForm', 'method' => 'post', 'onsubmit' => 'event.returnValue = false; return false;', 'action' => '/contacts/index/param',
|
'id' => 'ContactIndexForm', 'method' => 'post', 'onsubmit' => 'event.returnValue = false; return false;', 'action' => '/contacts/index/param',
|
||||||
'accept-charset' => 'utf-8'
|
'accept-charset' => 'utf-8'
|
||||||
),
|
),
|
||||||
'div' => array('style' => 'display:none;'),
|
'div' => array('style' => 'display:none;'),
|
||||||
|
@ -8630,7 +8639,7 @@ class FormHelperTest extends CakeTestCase {
|
||||||
|
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'form' => array(
|
'form' => array(
|
||||||
'id' => 'ContactAddForm', 'method' => 'post',
|
'id' => 'ContactIndexForm', 'method' => 'post',
|
||||||
'onsubmit' => 'someFunction();event.returnValue = false; return false;',
|
'onsubmit' => 'someFunction();event.returnValue = false; return false;',
|
||||||
'action' => '/contacts/index/param',
|
'action' => '/contacts/index/param',
|
||||||
'accept-charset' => 'utf-8'
|
'accept-charset' => 'utf-8'
|
||||||
|
@ -8688,7 +8697,7 @@ class FormHelperTest extends CakeTestCase {
|
||||||
Router::connect('/login', array('controller' => 'users', 'action' => 'login'));
|
Router::connect('/login', array('controller' => 'users', 'action' => 'login'));
|
||||||
$encoding = strtolower(Configure::read('App.encoding'));
|
$encoding = strtolower(Configure::read('App.encoding'));
|
||||||
|
|
||||||
$result = $this->Form->create('User', array('action' => 'login'));
|
$result = $this->Form->create('User', array('url' => array('action' => 'login')));
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'form' => array(
|
'form' => array(
|
||||||
'id' => 'UserLoginForm', 'method' => 'post', 'action' => '/login',
|
'id' => 'UserLoginForm', 'method' => 'post', 'action' => '/login',
|
||||||
|
@ -8760,7 +8769,7 @@ class FormHelperTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
public function testCreateWithAcceptCharset() {
|
public function testCreateWithAcceptCharset() {
|
||||||
$result = $this->Form->create('UserForm', array(
|
$result = $this->Form->create('UserForm', array(
|
||||||
'type' => 'post', 'action' => 'login', 'encoding' => 'iso-8859-1'
|
'type' => 'post', 'url' => array('action' => 'login'), 'encoding' => 'iso-8859-1'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$expected = array(
|
$expected = array(
|
||||||
|
@ -8793,7 +8802,7 @@ class FormHelperTest extends CakeTestCase {
|
||||||
));
|
));
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'form' => array(
|
'form' => array(
|
||||||
'id' => 'ContactAddForm',
|
'id' => 'ContactActionForm',
|
||||||
'method' => 'post',
|
'method' => 'post',
|
||||||
'action' => '/controller/action?param1=value1&param2=value2',
|
'action' => '/controller/action?param1=value1&param2=value2',
|
||||||
'accept-charset' => $encoding
|
'accept-charset' => $encoding
|
||||||
|
@ -8814,7 +8823,7 @@ class FormHelperTest extends CakeTestCase {
|
||||||
));
|
));
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'form' => array(
|
'form' => array(
|
||||||
'id' => 'ContactAddForm',
|
'id' => 'ContactActionForm',
|
||||||
'method' => 'post',
|
'method' => 'post',
|
||||||
'action' => '/controller/action?param1=value1&param2=value2',
|
'action' => '/controller/action?param1=value1&param2=value2',
|
||||||
'accept-charset' => $encoding
|
'accept-charset' => $encoding
|
||||||
|
@ -8870,7 +8879,7 @@ class FormHelperTest extends CakeTestCase {
|
||||||
));
|
));
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'form' => array(
|
'form' => array(
|
||||||
'id' => 'ContactAddForm',
|
'id' => 'ContactEditForm',
|
||||||
'method' => 'post',
|
'method' => 'post',
|
||||||
'action' => '/contacts/edit/0/myparam',
|
'action' => '/contacts/edit/0/myparam',
|
||||||
'accept-charset' => $encoding
|
'accept-charset' => $encoding
|
||||||
|
|
|
@ -312,19 +312,19 @@ class FormHelper extends AppHelper {
|
||||||
* ### Options:
|
* ### Options:
|
||||||
*
|
*
|
||||||
* - `type` Form method defaults to POST
|
* - `type` Form method defaults to POST
|
||||||
* - `action` The controller action the form submits to, (optional).
|
* - `action` The controller action the form submits to, (optional). Deprecated since 2.8, use `url`.
|
||||||
* - `url` The URL the form submits to. Can be a string or a URL array. If you 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.
|
* you should leave 'action' undefined.
|
||||||
* - `default` Allows for the creation of Ajax forms. Set this to false to prevent the default event handler.
|
* - `default` Allows for the creation of AJAX forms. Set this to false to prevent the default event handler.
|
||||||
* Will create an onsubmit attribute if it doesn't not exist. If it does, default action suppression
|
* Will create an onsubmit attribute if it doesn't not exist. If it does, default action suppression
|
||||||
* will be appended.
|
* will be appended.
|
||||||
* - `onsubmit` Used in conjunction with 'default' to create ajax forms.
|
* - `onsubmit` Used in conjunction with 'default' to create AJAX forms.
|
||||||
* - `inputDefaults` set the default $options for FormHelper::input(). Any options that would
|
* - `inputDefaults` set the default $options for FormHelper::input(). Any options that would
|
||||||
* be set when using FormHelper::input() can be set here. Options set with `inputDefaults`
|
* be set when using FormHelper::input() can be set here. Options set with `inputDefaults`
|
||||||
* can be overridden when calling input()
|
* can be overridden when calling input()
|
||||||
* - `encoding` Set the accept-charset encoding for the form. Defaults to `Configure::read('App.encoding')`
|
* - `encoding` Set the accept-charset encoding for the form. Defaults to `Configure::read('App.encoding')`
|
||||||
*
|
*
|
||||||
* @param mixed $model The model name for which the form is being defined. Should
|
* @param mixed|null $model The model name for which the form is being defined. Should
|
||||||
* include the plugin name for plugin models. e.g. `ContactManager.Contact`.
|
* include the plugin name for plugin models. e.g. `ContactManager.Contact`.
|
||||||
* If an array is passed and $options argument is empty, the array will be used as options.
|
* If an array is passed and $options argument is empty, the array will be used as options.
|
||||||
* If `false` no model is used.
|
* If `false` no model is used.
|
||||||
|
@ -379,6 +379,13 @@ class FormHelper extends AppHelper {
|
||||||
$this->inputDefaults($options['inputDefaults']);
|
$this->inputDefaults($options['inputDefaults']);
|
||||||
unset($options['inputDefaults']);
|
unset($options['inputDefaults']);
|
||||||
|
|
||||||
|
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'];
|
||||||
|
}
|
||||||
|
|
||||||
if (!isset($options['id'])) {
|
if (!isset($options['id'])) {
|
||||||
$domId = isset($options['action']) ? $options['action'] : $this->request['action'];
|
$domId = isset($options['action']) ? $options['action'] : $this->request['action'];
|
||||||
$options['id'] = $this->domId($domId . 'Form');
|
$options['id'] = $this->domId($domId . 'Form');
|
||||||
|
|
Loading…
Reference in a new issue