Skip to content

Commit

Permalink
fix for #4563
Browse files Browse the repository at this point in the history
  • Loading branch information
antograssiot committed Sep 11, 2014
1 parent d87fcbb commit 828efb0
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 19 deletions.
3 changes: 2 additions & 1 deletion src/Datasource/EntityTrait.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -660,11 +660,12 @@ protected function _readError($object, $path = null) {
return $object->errors($path); return $object->errors($path);
} }
if (is_array($object)) { if (is_array($object)) {
return array_map(function($val) { $array = array_map(function($val) {
if ($val instanceof static) { if ($val instanceof static) {
return $val->errors(); return $val->errors();
} }
}, $object); }, $object);
return array_filter($array);
} }
return []; return [];
} }
Expand Down
11 changes: 1 addition & 10 deletions src/View/Form/EntityContext.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -456,16 +456,7 @@ public function attributes($field) {
* @return bool Returns true if the errors for the field are not empty. * @return bool Returns true if the errors for the field are not empty.
*/ */
public function hasError($field) { public function hasError($field) {
$errors = $this->error($field); return $this->error($field) !== [];
if ($errors !== []) {
foreach ($errors as $key => $value) {
if (!is_null($value)) {
return true;
}
}
return false;
}
return false;
} }


/** /**
Expand Down
8 changes: 0 additions & 8 deletions tests/TestCase/View/Form/EntityContextTest.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -794,13 +794,6 @@ public function testHasError() {
'user' => new Entity(['username' => 'Mark']), 'user' => new Entity(['username' => 'Mark']),
]); ]);
$row->errors('title', []); $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('body', 'Gotta have one');
$row->errors('user_id', ['Required field']); $row->errors('user_id', ['Required field']);
$context = new EntityContext($this->request, [ $context = new EntityContext($this->request, [
Expand All @@ -809,7 +802,6 @@ public function testHasError() {
]); ]);


$this->assertFalse($context->hasError('title')); $this->assertFalse($context->hasError('title'));
$this->assertFalse($context->hasError('uploadedFile'));
$this->assertFalse($context->hasError('nope')); $this->assertFalse($context->hasError('nope'));
$this->assertTrue($context->hasError('body')); $this->assertTrue($context->hasError('body'));
$this->assertTrue($context->hasError('user_id')); $this->assertTrue($context->hasError('user_id'));
Expand Down

0 comments on commit 828efb0

Please sign in to comment.