Skip to content

Commit

Permalink
Add the ability to read value from an array entity context
Browse files Browse the repository at this point in the history
  • Loading branch information
dakota committed Jul 13, 2015
1 parent d823fad commit d0c778a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/View/Form/EntityContext.php
Expand Up @@ -222,6 +222,8 @@ public function val($field)

if ($entity instanceof EntityInterface) {
return $entity->get(array_pop($parts));
} elseif (is_array($entity)) {
return $entity[array_pop($parts)];
}
return null;
}
Expand Down
6 changes: 6 additions & 0 deletions tests/TestCase/View/Form/EntityContextTest.php
Expand Up @@ -458,6 +458,9 @@ public function testValGetArrayValue()
$row = new Article([
'title' => 'Test entity',
'types' => [1, 2, 3],
'tag' => [
'name' => 'Test tag',
],
'author' => new Entity([
'roles' => ['admin', 'publisher']
])
Expand All @@ -471,6 +474,9 @@ public function testValGetArrayValue()

$result = $context->val('author.roles');
$this->assertEquals($row->author->roles, $result);

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

/**
Expand Down

3 comments on commit d0c778a

@daniouyea
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change brings me this Notice (8): Undefined index: _ids [CORE/src/View/Form/EntityContext.php, line 226] when the belongsToMany relationship is empty.

@markstory
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@daniouyea Could you open an issue with how to reproduce the problem you're having? Commit comments are easily lost/forgotten.

@ricog
Copy link
Contributor

@ricog ricog commented on d0c778a Jul 24, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is resolved in 3.0.10 by #7064

Please sign in to comment.