Browse Source

Allow string values for templates option.

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
mark_story 11 years ago
parent
commit
ffc092bc39

+ 2 - 1
src/View/Helper/FormHelper.php

@@ -893,7 +893,8 @@ class FormHelper extends Helper {
 
 		if ($newTemplates) {
 			$templater->push();
-			$templater->add($options['templates']);
+			$templateMethod = is_string($options['templates']) ? 'load' : 'add';
+			$templater->{$templateMethod}($options['templates']);
 		}
 		unset($options['templates']);
 

+ 22 - 0
tests/TestCase/View/Helper/FormHelperTest.php

@@ -2108,6 +2108,28 @@ class FormHelperTest extends TestCase {
 	}
 
 /**
+ * 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
  *
  * @return void

+ 2 - 1
tests/test_app/TestApp/Config/htmlhelper_tags.php

@@ -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}}'
 ];