Skip to content

Commit

Permalink
Merge pull request #2909 from cakephp/3.0-more-form-input
Browse files Browse the repository at this point in the history
3.0 more form input
  • Loading branch information
markstory committed Feb 28, 2014
2 parents 8ceb359 + 5847166 commit 148fd51
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 591 deletions.
5 changes: 5 additions & 0 deletions src/View/Form/EntityContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,11 @@ protected function _getEntity($path) {
}

$lastProp = $this->_rootName;

if ($path[0] === $this->_rootName) {
$path = array_slice($path, 1);
}

foreach ($path as $prop) {
$next = $this->_getProp($entity, $prop);
if (
Expand Down
5 changes: 3 additions & 2 deletions src/View/Helper/FormHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,7 @@ public function input($fieldName, $options = []) {
unset($options['templates']);

$label = $this->_getLabel($fieldName, $options);

if ($options['type'] !== 'radio') {
unset($options['label']);
}
Expand Down Expand Up @@ -1003,7 +1004,7 @@ protected function _optionsOptions($fieldName, $options) {
protected function _magicOptions($fieldName, $options, $allowOverride) {
$context = $this->_getContext();

if (!isset($options['required'])) {
if (!isset($options['required']) && $options['type'] !== 'hidden') {
$options['required'] = $context->isRequired($fieldName);
}

Expand Down Expand Up @@ -1055,7 +1056,7 @@ protected function _magicOptions($fieldName, $options, $allowOverride) {
* @return boolean|string false or Generated label element
*/
protected function _getLabel($fieldName, $options) {
if ($options['type'] === 'radio') {
if (in_array($options['type'], ['radio', 'hidden'])) {
return false;
}

Expand Down
28 changes: 28 additions & 0 deletions tests/TestCase/View/Form/EntityContextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,34 @@ public function testValOnCollections($collection) {
$this->assertNull($context->val('99.title'));
}

/**
* Test operations on a collection of entities when prefixing with the
* table name
*
* @dataProvider collectionProvider
* @return void
*/
public function testValOnCollectionsWithRootName($collection) {
$context = new EntityContext($this->request, [
'entity' => $collection,
'table' => 'Articles',
]);

$result = $context->val('Articles.0.title');
$this->assertEquals('First post', $result);

$result = $context->val('Articles.0.user.username');
$this->assertEquals('mark', $result);

$result = $context->val('Articles.1.title');
$this->assertEquals('Second post', $result);

$result = $context->val('Articles.1.user.username');
$this->assertEquals('jose', $result);

$this->assertNull($context->val('Articles.99.title'));
}

/**
* Test error operations on a collection of entities.
*
Expand Down
Loading

0 comments on commit 148fd51

Please sign in to comment.