Skip to content
Permalink
Browse files

Fix derpness of `fieldset` and `legend` options being mashed inside $…

…fields param array.
  • Loading branch information...
ADmad committed Nov 12, 2012
1 parent a7f192c commit f7e66da6fc18baeebefd60bd0d678304eeda9854
Showing with 47 additions and 21 deletions.
  1. +18 −0 lib/Cake/Test/Case/View/Helper/FormHelperTest.php
  2. +29 −21 lib/Cake/View/Helper/FormHelper.php
@@ -2845,6 +2845,12 @@ public function testFormInputs() {
);
$this->assertTags($result, $expected);
$result = $this->Form->inputs(null, null, array('legend' => 'Field of Dreams', 'fieldset' => 'classy-stuff'));
$this->assertTags($result, $expected);
$result = $this->Form->inputs('Field of Dreams', null, array('fieldset' => 'classy-stuff'));
$this->assertTags($result, $expected);
$this->Form->create('Contact');
$this->Form->request['prefix'] = 'admin';
$this->Form->request['action'] = 'admin_edit';
@@ -2908,6 +2914,10 @@ public function testFormInputs() {
);
$this->assertTags($result, $expected);
$this->Form->create('Contact');
$result = $this->Form->inputs(null, null, array('fieldset' => false));
$this->assertTags($result, $expected);
$this->Form->create('Contact');
$result = $this->Form->inputs(array('fieldset' => true, 'legend' => false));
$expected = array(
@@ -2960,6 +2970,10 @@ public function testFormInputs() {
);
$this->assertTags($result, $expected);
$this->Form->create('Contact');
$result = $this->Form->inputs(null, null, array('fieldset' => false, 'legend' => 'Hello'));
$this->assertTags($result, $expected);
$this->Form->create('Contact');
$result = $this->Form->inputs('Hello');
$expected = array(
@@ -3019,6 +3033,10 @@ public function testFormInputs() {
'/fieldset'
);
$this->assertTags($result, $expected);
$this->Form->create('Contact');
$result = $this->Form->inputs(null, null, array('legend' => 'Hello'));
$this->assertTags($result, $expected);
}
/**
@@ -805,42 +805,43 @@ public function label($fieldName = null, $text = null, $options = array()) {
}
/**
* Generate a set of inputs for `$fields`. If $fields is null the current model
* Generate a set of inputs for `$fields`. If $fields is null the fields of current model
* will be used.
*
* In addition to controller fields output, `$fields` can be used to control legend
* and fieldset rendering with the `fieldset` and `legend` keys.
* `$form->inputs(array('legend' => 'My legend'));` Would generate an input set with
* a custom legend. You can customize individual inputs through `$fields` as well.
*
* You can customize individual inputs through `$fields`.
* {{{
* $form->inputs(array(
* $this->Form->inputs(array(
* 'name' => array('label' => 'custom label')
* ));
* }}}
*
* In addition to fields control, inputs() allows you to use a few additional options.
* In addition to controller fields output, `$fields` can be used to control legend
* and fieldset rendering.
* `$this->Form->inputs('My legend');` Would generate an input set with a custom legend.
* Passing `fieldset` and `legend` key in `$fields` array has been deprecated since 2.3,
* for more fine grained control use the `fieldset` and `legend` keys in `$options` param.
*
* @param array $fields An array of fields to generate inputs for, or null.
* @param array $blacklist A simple array of fields to not create inputs for.
* @param array $options Options array. Valid keys are:
* - `fieldset` Set to false to disable the fieldset. If a string is supplied it will be used as
* the classname for the fieldset element.
* - `legend` Set to false to disable the legend for the generated input set. Or supply a string
* to customize the legend text.
*
* @param array $fields An array of fields to generate inputs for, or null.
* @param array $blacklist a simple array of fields to not create inputs for.
* @return string Completed form inputs.
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#FormHelper::inputs
*/
public function inputs($fields = null, $blacklist = null) {
public function inputs($fields = null, $blacklist = null, $options = array()) {
$fieldset = $legend = true;
$model = $this->model();
$modelFields = array_keys($this->_introspectModel($model, 'fields'));
if (is_array($fields)) {
if (array_key_exists('legend', $fields)) {
if (array_key_exists('legend', $fields) && !in_array('legend', $modelFields)) {
$legend = $fields['legend'];
unset($fields['legend']);
}
if (isset($fields['fieldset'])) {
if (isset($fields['fieldset']) && !in_array('fieldset', $modelFields)) {
$fieldset = $fields['fieldset'];
unset($fields['fieldset']);
}
@@ -852,8 +853,15 @@ public function inputs($fields = null, $blacklist = null) {
$fields = array();
}
if (isset($options['legend'])) {
$legend = $options['legend'];
}
if (isset($options['fieldset'])) {
$fieldset = $options['fieldset'];
}
if (empty($fields)) {
$fields = array_keys($this->_introspectModel($model, 'fields'));
$fields = $modelFields;
}
if ($legend === true) {
@@ -892,13 +900,13 @@ public function inputs($fields = null, $blacklist = null) {
$fieldsetClass = '';
}
if ($fieldset && $legend) {
return $this->Html->useTag('fieldset', $fieldsetClass, $this->Html->useTag('legend', $legend) . $out);
} elseif ($fieldset) {
return $this->Html->useTag('fieldset', $fieldsetClass, $out);
} else {
return $out;
if ($fieldset) {
if ($legend) {
$out = $this->Html->useTag('legend', $legend) . $out;
}
$out = $this->Html->useTag('fieldset', $fieldsetClass, $out);
}
return $out;
}
/**

0 comments on commit f7e66da

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