Anthony GRASSIOT 11 years ago
parent
commit
828efb090f

+ 2 - 1
src/Datasource/EntityTrait.php

@@ -660,11 +660,12 @@ trait EntityTrait {
 			return $object->errors($path);
 		}
 		if (is_array($object)) {
-			return array_map(function($val) {
+			$array = array_map(function($val) {
 				if ($val instanceof static) {
 					return $val->errors();
 				}
 			}, $object);
+			return array_filter($array);
 		}
 		return [];
 	}

+ 1 - 10
src/View/Form/EntityContext.php

@@ -456,16 +456,7 @@ class EntityContext implements ContextInterface {
  * @return bool Returns true if the errors for the field are not empty.
  */
 	public function hasError($field) {
-		$errors = $this->error($field);
-		if ($errors !== []) {
-			foreach ($errors as $key => $value) {
-				if (!is_null($value)) {
-					return true;
-				}
-			}
-			return false;
-		}
-		return false;
+		return $this->error($field) !== [];
 	}
 
 /**

+ 0 - 8
tests/TestCase/View/Form/EntityContextTest.php

@@ -794,13 +794,6 @@ class EntityContextTest extends TestCase {
 			'user' => new Entity(['username' => 'Mark']),
 		]);
 		$row->errors('title', []);
-		$row->errors(['uploadedFile' => [
-			'name' => null,
-			'tmp_name' => null,
-			'error' => null,
-			'type' => null,
-			'size' => null
-		]]);
 		$row->errors('body', 'Gotta have one');
 		$row->errors('user_id', ['Required field']);
 		$context = new EntityContext($this->request, [
@@ -809,7 +802,6 @@ class EntityContextTest extends TestCase {
 		]);
 
 		$this->assertFalse($context->hasError('title'));
-		$this->assertFalse($context->hasError('uploadedFile'));
 		$this->assertFalse($context->hasError('nope'));
 		$this->assertTrue($context->hasError('body'));
 		$this->assertTrue($context->hasError('user_id'));