Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Allow the EntityContext to read from the request data.

Reading from the request data is helpful when you are making forms, as
you might need to access data that has not been added to the entities
that compose the context.
  • Loading branch information...
commit 01704a47017086550fc63ba2376bef7bd0b29e93 1 parent 71c26e9
@markstory markstory authored
View
4 src/View/Form/EntityContext.php
@@ -194,6 +194,10 @@ public function isCreate() {
* @return mixed The value of the field or null on a miss.
*/
public function val($field) {
+ $val = $this->_request->data($field);
+ if ($val !== null) {
+ return $val;
+ }
if (empty($this->_context['entity'])) {
return null;
}
View
23 tests/TestCase/View/Form/EntityContextTest.php
@@ -378,6 +378,29 @@ public function testValBasic() {
}
/**
+ * Test that val() reads from the request.
+ *
+ * @return void
+ */
+ public function testValReadsRequest() {
+ $this->request->data = [
+ 'title' => 'New title',
+ 'notInEntity' => 'yes',
+ ];
+ $row = new Entity([
+ 'title' => 'Test entity',
+ 'body' => 'Something new'
+ ]);
+ $context = new EntityContext($this->request, [
+ 'entity' => $row,
+ 'table' => 'Articles',
+ ]);
+ $this->assertEquals('New title', $context->val('title'));
+ $this->assertEquals('yes', $context->val('notInEntity'));
+ $this->assertEquals($row->body, $context->val('body'));
+ }
+
+/**
* Test reading values from associated entities.
*
* @return void
Please sign in to comment.
Something went wrong with that request. Please try again.