Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix template files not being usable with FormHelper::create()

  • Loading branch information...
commit b07ed689a8bc0e74dfd15bf92225837dab38080e 1 parent dbe809b
Mark Story markstory authored
15 src/View/Helper/FormHelper.php
View
@@ -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;
}
7 src/View/StringTemplate.php
View
@@ -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);
}
20 tests/TestCase/View/Helper/FormHelperTest.php
View
@@ -342,7 +342,7 @@ public function testCreateGet() {
*
* @return void
*/
- public function testCreateTemplates() {
+ public function testCreateTemplatesArray() {
$result = $this->Form->create($this->article, [
'templates' => [
'formstart' => '<form class="form-horizontal"{{attrs}}>',
@@ -360,6 +360,24 @@ public function testCreateTemplates() {
}
/**
+ * 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
*
* @dataProvider requestTypeProvider
12 tests/test_app/TestApp/Config/htmlhelper_tags.php
View
@@ -1,9 +1,7 @@
<?php
-$config = array(
- 'tags' => array(
- 'form' => 'start form',
- 'formend' => 'finish form',
- 'hiddenblock' => '<div class="hidden">%s</div>'
- )
-);
+$config = [
+ 'formstart' => 'start form',
+ 'formend' => 'finish form',
+ 'hiddenblock' => '<div class="hidden">{{content}}</div>'
+];
Please sign in to comment.
Something went wrong with that request. Please try again.