I have a profile2 profile with several boolean fields using a checkbox to set them. Unchecked values are never causing pcp to be considered incomplete. This is because the field values returned are:
[field_antiharassment] => Array
(
[und] => Array
(
[0] => Array
(
[value] =>
)
)
)in pcp_get_user_profile_values the following is being done:
foreach ($fields as $field_name => $field_values) {
if (isset($profile->$field_name) && $field = $profile->$field_name) {
$fiid = $field_values['id'];
$user_fields[$field_name] = $field['und'][0];
}
}since $field['und'][0] is set, we add the field to user_fields.
I worked around this by extending the check to see if $field['und'][0] has any values as follows:
foreach ($fields as $field_name => $field_values) {
if (isset($profile->$field_name) && $field = $profile->$field_name) {
foreach ($field['und'][0] as $value) {
if (!is_null($value)) {
$fiid = $field_values['id'];
$user_fields[$field_name] = $field['und'][0];
break;
}
}
}
}I've attached a patch for your consideration.
| Comment | File | Size | Author |
|---|---|---|---|
| pcp.module.checkboxes.patch | 1 KB | bkat |
Comments
Comment #1
StevenWill commentedI posted a patch in comment 1 by mistake. Please delete this patch.
Comment #2
perennial.sky commentedduplicate issue https://www.drupal.org/node/1271194
Comment #3
bkat commentedThe issue you marked it a duplicate of is for Drupal 6 and this one and the patch is for Drupal 7.
Comment #4
bkat commentedComment #5
BarisW commentedThanks bkat for the fix. I've committed it.
Comment #6
BarisW commented