Browse Source

Fix BC breaking change from 3.3 to 3.4.

mscherer 8 years ago
parent
commit
64c7a5fde5

+ 14 - 9
src/Model/Behavior/PasswordableBehavior.php

@@ -222,18 +222,23 @@ class PasswordableBehavior extends Behavior {
 		$formFieldRepeat = $this->_config['formFieldRepeat'];
 		$formFieldCurrent = $this->_config['formFieldCurrent'];
 
-		if (!isset($options['fieldList']) && $this->_config['forceFieldList']) {
-			$options['fieldList'] = array_keys((array)$data);
+		// For CakePHP < 3.4
+		if (!isset($options['fields']) && isset($options['fieldList'])) {
+			$options['fields'] = $options['fieldList'];
 		}
-		if (isset($options['fieldList'])) {
-			if (!in_array($formField, $options['fieldList'])) {
-				$options['fieldList'][] = $formField;
+
+		if (!isset($options['fields']) && $this->_config['forceFieldList']) {
+			$options['fields'] = array_keys((array)$data);
+		}
+		if (isset($options['fields'])) {
+			if (!in_array($formField, $options['fields'])) {
+				$options['fields'][] = $formField;
 			}
-			if (!in_array($formFieldRepeat, $options['fieldList'])) {
-				$options['fieldList'][] = $formFieldRepeat;
+			if (!in_array($formFieldRepeat, $options['fields'])) {
+				$options['fields'][] = $formFieldRepeat;
 			}
-			if (!in_array($formFieldCurrent, $options['fieldList'])) {
-				$options['fieldList'][] = $formFieldCurrent;
+			if (!in_array($formFieldCurrent, $options['fields'])) {
+				$options['fields'][] = $formFieldCurrent;
 			}
 		}
 

+ 3 - 3
tests/TestCase/Model/Behavior/PasswordableBehaviorTest.php

@@ -400,7 +400,7 @@ class PasswordableBehaviorTest extends TestCase {
 		];
 		$user->accessible('*', false); // Mark all properties as protected
 		$user->accessible(['id'], true); // Allow id to be accessible by default
-		$user = $this->Users->patchEntity($user, $data, ['fieldList' => ['id']]);
+		$user = $this->Users->patchEntity($user, $data, ['fields' => ['id']]);
 
 		$this->assertNotSame($is['password'], $user['password']);
 		$this->assertTrue($user->dirty('pwd'));
@@ -426,7 +426,7 @@ class PasswordableBehaviorTest extends TestCase {
 		];
 		$user->accessible('*', false); // Mark all properties as protected
 		$user->accessible(['id', 'name'], true);
-		$this->Users->patchEntity($user, $data, ['fieldList' => ['id', 'name']]);
+		$this->Users->patchEntity($user, $data, ['fields' => ['id', 'name']]);
 		// Test whitelist setting - only "password" gets auto-added, pwd, pwd_repeat etc need to be added manually
 		// NOTE that I had to remove the code for adding those fields from the behavior (as it was not functional)
 		// So of course, this won't work now as expected. But feel free to try to add them in the behavior. Results will be the same.
@@ -455,7 +455,7 @@ class PasswordableBehaviorTest extends TestCase {
 		];
 		$user->accessible('*', false); // Mark all properties as protected
 		$user->accessible(['id'], true);
-		$this->Users->patchEntity($user, $data, ['fieldList' => ['id']]);
+		$this->Users->patchEntity($user, $data, ['fields' => ['id']]);
 		$result = $this->Users->save($user);
 		$this->assertTrue((bool)$result);
 	}