Browse Source

Remove param $confirmMessage.

You can set the confirm message using 'confirm' key in options.
ADmad 11 years ago
parent
commit
f97ddb13ce
2 changed files with 21 additions and 18 deletions
  1. 14 14
      src/View/Helper/FormHelper.php
  2. 7 4
      tests/TestCase/View/Helper/FormHelperTest.php

+ 14 - 14
src/View/Helper/FormHelper.php

@@ -1416,41 +1416,41 @@ class FormHelper extends Helper {
 	}
 
 /**
- * Creates an HTML link, but access the URL using the method you specify (defaults to POST).
- * Requires javascript to be enabled in browser.
+ * Creates an HTML link, but access the URL using the method you specify
+ * (defaults to POST). Requires javascript to be enabled in browser.
  *
- * This method creates a `<form>` element. So do not use this method inside an existing form.
- * Instead you should add a submit button using FormHelper::submit()
+ * This method creates a `<form>` element. So do not use this method inside an
+ * existing form. Instead you should add a submit button using FormHelper::submit()
  *
  * ### Options:
  *
  * - `data` - Array with key/value to pass in input hidden
- * - `method` - Request method to use. Set to 'delete' to simulate HTTP/1.1 DELETE request. Defaults to 'post'.
- * - `confirm` - Can be used instead of $confirmMessage.
+ * - `method` - Request method to use. Set to 'delete' to simulate
+ *   HTTP/1.1 DELETE request. Defaults to 'post'.
+ * - `confirm` - Confirm message to show.
  * - `block` - Set to true to append form to view block "postLink" or provide
  *   custom block name.
  * - Other options are the same of HtmlHelper::link() method.
  * - The option `onclick` will be replaced.
  *
  * @param string $title The content to be wrapped by <a> tags.
- * @param string|array $url Cake-relative URL or array of URL parameters, or external URL (starts with http://)
+ * @param string|array $url Cake-relative URL or array of URL parameters, or
+ *   external URL (starts with http://)
  * @param array $options Array of HTML attributes.
- * @param bool|string $confirmMessage JavaScript confirmation message.
  * @return string An `<a />` element.
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#FormHelper::postLink
  */
-	public function postLink($title, $url = null, array $options = array(), $confirmMessage = false) {
-		$options += array('block' => null);
+	public function postLink($title, $url = null, array $options = array()) {
+		$options += array('block' => null, 'confirm' => null);
 
 		$requestMethod = 'POST';
 		if (!empty($options['method'])) {
 			$requestMethod = strtoupper($options['method']);
 			unset($options['method']);
 		}
-		if (!empty($options['confirm'])) {
-			$confirmMessage = $options['confirm'];
-			unset($options['confirm']);
-		}
+
+		$confirmMessage = $options['confirm'];
+		unset($options['confirm']);
 
 		$formName = str_replace('.', '', uniqid('post_', true));
 		$formOptions = array(

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

@@ -5356,7 +5356,7 @@ class FormHelperTest extends TestCase {
 			'/a'
 		));
 
-		$result = $this->Form->postLink('Delete', '/posts/delete/1', array(), 'Confirm?');
+		$result = $this->Form->postLink('Delete', '/posts/delete/1', array('confirm' => 'Confirm?'));
 		$this->assertTags($result, array(
 			'form' => array(
 				'method' => 'post', 'action' => '/posts/delete/1',
@@ -5369,7 +5369,11 @@ class FormHelperTest extends TestCase {
 			'/a'
 		));
 
-		$result = $this->Form->postLink('Delete', '/posts/delete/1', array('escape' => false), '\'Confirm\' this "deletion"?');
+		$result = $this->Form->postLink(
+			'Delete',
+			'/posts/delete/1',
+			array('escape' => false, 'confirm' => '\'Confirm\' this "deletion"?')
+		);
 		$this->assertTags($result, array(
 			'form' => array(
 				'method' => 'post', 'action' => '/posts/delete/1',
@@ -5401,8 +5405,7 @@ class FormHelperTest extends TestCase {
 		$result = $this->Form->postLink(
 			'',
 			array('controller' => 'items', 'action' => 'delete', 10),
-			array('class' => 'btn btn-danger', 'escape' => false),
-			'Confirm thing'
+			array('class' => 'btn btn-danger', 'escape' => false, 'confirm' => 'Confirm thing')
 		);
 		$this->assertTags($result, array(
 			'form' => array(