Skip to content

Commit

Permalink
merge fields and blacklist
Browse files Browse the repository at this point in the history
rather than have an explicit blacklist - blacklist a field by
specifying it as false in $fields
  • Loading branch information
AD7six committed May 3, 2014
1 parent f332968 commit b7d1b8a
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/View/Helper/FormHelper.php
Expand Up @@ -734,25 +734,24 @@ public function label($fieldName, $text = null, array $options = []) {
* ]);
* }}}
*
* You can exclude fields using the `$blacklist` parameter:
* You can exclude fields by specifying them as false:
*
* {{{
* $this->Form->inputs([], ['title']);
* $this->Form->inputs(['title' => false]);
* }}}
*
* In the above example, no field would be generated for the title field.
*
* @param array $fields An array of customizations for the fields that will be
* generated. This array allows you to set custom types, labels, or other options.
* @param array $blacklist A list of fields to not create inputs for.
* @param array $options Options array. Valid keys are:
* - `fieldset` Set to false to disable the fieldset.
* - `legend` Set to false to disable the legend for the generated input set. Or supply a string
* to customize the legend text.
* @return string Completed form inputs.
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#FormHelper::inputs
*/
public function inputs(array $fields = [], array $blacklist = [], array $options = []) {
public function inputs(array $fields = [], array $options = []) {
$fieldset = $legend = true;
$context = $this->_getContext();

Expand Down Expand Up @@ -782,18 +781,15 @@ public function inputs(array $fields = [], array $blacklist = [], array $options

$out = null;
foreach ($fields as $name => $options) {
if ($options === false) {
continue;
}

if (is_numeric($name) && !is_array($options)) {
$name = $options;
$options = [];
}
$entity = explode('.', $name);
$blacklisted = (
!empty($blacklist) &&
(in_array($name, $blacklist) || in_array(end($entity), $blacklist))
);
if ($blacklisted) {
continue;
}
$out .= $this->input($name, (array)$options);
}

Expand Down

0 comments on commit b7d1b8a

Please sign in to comment.