Skip to content

Commit

Permalink
Fix notice error when reading array values.
Browse files Browse the repository at this point in the history
We cannot assume that array keys will exist.

Refs #7061
  • Loading branch information
markstory committed Jul 20, 2015
1 parent d5b2551 commit ca109d9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/View/Form/EntityContext.php
Expand Up @@ -223,7 +223,8 @@ public function val($field)
if ($entity instanceof EntityInterface) {
return $entity->get(array_pop($parts));
} elseif (is_array($entity)) {
return $entity[array_pop($parts)];
$key = array_pop($parts);
return isset($entity[$key]) ? $entity[$key] : null;
}
return null;
}
Expand Down
6 changes: 6 additions & 0 deletions tests/TestCase/View/Form/EntityContextTest.php
Expand Up @@ -477,6 +477,12 @@ public function testValGetArrayValue()

$result = $context->val('tag.name');
$this->assertEquals($row->tag['name'], $result);

$result = $context->val('tag.nope');
$this->assertNull($result);

$result = $context->val('author.roles.3');
$this->assertNull($result);
}

/**
Expand Down

0 comments on commit ca109d9

Please sign in to comment.