diff --git a/src/View/Helper/FormHelper.php b/src/View/Helper/FormHelper.php index 835d1f28c7e..b2763d33f82 100755 --- a/src/View/Helper/FormHelper.php +++ b/src/View/Helper/FormHelper.php @@ -293,9 +293,12 @@ public function create($model = null, $options = []) { ]; $this->_idPrefix = $options['idPrefix']; + $templater = $this->getTemplater(); - if (!empty($options['templates'])) { - $this->templates($options['templates']); + if (!empty($options['templates']) && is_array($options['templates'])) { + $templater->add($options['templates']); + } elseif (!empty($options['templates']) && is_string($options['templates'])) { + $templater->load($options['templates']); } unset($options['templates']); @@ -337,11 +340,11 @@ public function create($model = null, $options = []) { } if (!empty($append)) { - $append = $this->formatTemplate('hiddenblock', ['content' => $append]); + $append = $templater->format('hiddenblock', ['content' => $append]); } - $actionAttr = $this->_templater->formatAttributes(['action' => $action, 'escape' => false]); - return $this->formatTemplate('formstart', [ - 'attrs' => $this->_templater->formatAttributes($htmlAttributes) . $actionAttr + $actionAttr = $templater->formatAttributes(['action' => $action, 'escape' => false]); + return $templater->format('formstart', [ + 'attrs' => $templater->formatAttributes($htmlAttributes) . $actionAttr ]) . $append; } diff --git a/src/View/StringTemplate.php b/src/View/StringTemplate.php index 8e6e08991e8..ea058ea90c7 100644 --- a/src/View/StringTemplate.php +++ b/src/View/StringTemplate.php @@ -70,12 +70,7 @@ public function __construct(array $templates = null) { * @return void */ public function load($file) { - list($plugin, $file) = pluginSplit($file); - $path = APP . 'Config/'; - if ($plugin !== null) { - $path = Plugin::path($plugin) . 'Config/'; - } - $loader = new PhpConfig($path); + $loader = new PhpConfig(APP . 'Config/'); $templates = $loader->read($file); $this->add($templates); } diff --git a/tests/TestCase/View/Helper/FormHelperTest.php b/tests/TestCase/View/Helper/FormHelperTest.php index 204d9b8ff41..0d30cebbb4e 100755 --- a/tests/TestCase/View/Helper/FormHelperTest.php +++ b/tests/TestCase/View/Helper/FormHelperTest.php @@ -342,7 +342,7 @@ public function testCreateGet() { * * @return void */ - public function testCreateTemplates() { + public function testCreateTemplatesArray() { $result = $this->Form->create($this->article, [ 'templates' => [ 'formstart' => '
', @@ -359,6 +359,24 @@ public function testCreateTemplates() { $this->assertTags($result, $expected); } +/** + * Test create() with the templates option. + * + * @return void + */ + public function testCreateTemplatesFile() { + $result = $this->Form->create($this->article, [ + 'templates' => 'htmlhelper_tags.php', + ]); + $expected = [ + 'start form', + 'div' => ['class' => 'hidden'], + 'input' => ['type' => 'hidden', 'name' => '_method', 'value' => 'POST'], + '/div' + ]; + $this->assertTags($result, $expected); + } + /** * test the create() method * diff --git a/tests/test_app/TestApp/Config/htmlhelper_tags.php b/tests/test_app/TestApp/Config/htmlhelper_tags.php index 850f26d12e7..1276471f33a 100644 --- a/tests/test_app/TestApp/Config/htmlhelper_tags.php +++ b/tests/test_app/TestApp/Config/htmlhelper_tags.php @@ -1,9 +1,7 @@ array( - 'form' => 'start form', - 'formend' => 'finish form', - 'hiddenblock' => '' - ) -); \ No newline at end of file +$config = [ + 'formstart' => 'start form', + 'formend' => 'finish form', + 'hiddenblock' => '' +];