Skip to content
Permalink
Browse files

Add templates option to create().

This will make it easier to override templates on a per form basis.
  • Loading branch information...
markstory committed Mar 10, 2014
1 parent e54ffbc commit 31003389b9865525da0b7d362918de30138adbb0
Showing with 34 additions and 1 deletion.
  1. +12 −1 src/View/Helper/FormHelper.php
  2. +22 −0 tests/TestCase/View/Helper/FormHelperTest.php
@@ -256,6 +256,10 @@ protected function _isRequiredField($validationRules) {
* - `url` The URL the form submits to. Can be a string or a URL array. If you use 'url'
* you should leave 'action' undefined.
* - `encoding` Set the accept-charset encoding for the form. Defaults to `Configure::read('App.encoding')`
* - `templates` The templates you want to use for this form. Any templates will be merged on top of
* the already loaded templates. This option can either be a filename in App/Config that contains
* the templates you want to load, or an array of templates to use. You can use
* resetTemplates() to restore the original templates.
* - `context` Additional options for the context class. For example the EntityContext accepts a 'table'
* option that allows you to set the specific Table class the form should be based on.
* - `idPrefix` Prefix for generated ID attributes.
@@ -284,10 +288,17 @@ public function create($model = null, $options = []) {
'action' => null,
'url' => null,
'encoding' => strtolower(Configure::read('App.encoding')),
'idPrefix' => null
'templates' => null,
'idPrefix' => null,
];
$this->_idPrefix = $options['idPrefix'];
if (!empty($options['templates'])) {
$this->templates($options['templates']);
}
unset($options['templates']);
$action = $this->url($this->_formUrl($context, $options));
unset($options['url'], $options['action'], $options['idPrefix']);
@@ -337,6 +337,28 @@ public function testCreateGet() {
$this->assertTags($result, $expected);
}
/**
* Test create() with the templates option.
*
* @return void
*/
public function testCreateTemplates() {
$result = $this->Form->create($this->article, [
'templates' => [
'formstart' => '<form class="form-horizontal"{{attrs}}>',
]
]);
$expected = [
'form' => [
'class' => 'form-horizontal',
'method' => 'post',
'action' => '/articles/add',
'accept-charset' => 'utf-8'
]
];
$this->assertTags($result, $expected);
}
/**
* test the create() method
*

0 comments on commit 3100338

Please sign in to comment.
You can’t perform that action at this time.