Skip to content

Commit

Permalink
Allow string values for templates option.
Browse files Browse the repository at this point in the history
This allows template files to be used with input(). This makes input()
consistent with create() and allows developers to use config files
better/more easily.

Refs #4015
  • Loading branch information
markstory committed Jul 23, 2014
1 parent 65e633f commit ffc092b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/View/Helper/FormHelper.php
Expand Up @@ -893,7 +893,8 @@ public function input($fieldName, array $options = []) {

if ($newTemplates) {
$templater->push();
$templater->add($options['templates']);
$templateMethod = is_string($options['templates']) ? 'load' : 'add';
$templater->{$templateMethod}($options['templates']);
}
unset($options['templates']);

Expand Down
22 changes: 22 additions & 0 deletions tests/TestCase/View/Helper/FormHelperTest.php
Expand Up @@ -2107,6 +2107,28 @@ public function testInputCustomization() {
$this->assertTags($result, $expected);
}

/**
* Test that input() accepts a template file.
*
* @return void
*/
public function testInputWithTemplateFile() {
$result = $this->Form->input('field', array(
'templates' => 'htmlhelper_tags'
));
$expected = array(
'label' => array('for' => 'field'),
'Field',
'/label',
'input' => array(
'type' => 'text', 'name' => 'field',
'id' => 'field'
),
);
$this->assertTags($result, $expected);

}

/**
* Test id prefix
*
Expand Down
3 changes: 2 additions & 1 deletion tests/test_app/TestApp/Config/htmlhelper_tags.php
Expand Up @@ -3,5 +3,6 @@
$config = [
'formstart' => 'start form',
'formend' => 'finish form',
'hiddenblock' => '<div class="hidden">{{content}}</div>'
'hiddenblock' => '<div class="hidden">{{content}}</div>',
'inputContainer' => '{{content}}'
];

0 comments on commit ffc092b

Please sign in to comment.