Before I get into the actual bug report, let me state my assumptions to provide context, because, though I believe otherwise, I'm willing to concede the possibility that A) I may not be doing things the optimal way, and B) the way that I'm doing things may not be the only reasonable way.
I have a boolean value in a custom object in Salesforce (represented by a checkbox widget in the SF UI). On the Drupal side, I have a CCK integer field set to use the "Single on/off checkbox" widget, holding a single value, with "0|off" and "1|on" in the allowed values list. The field is included in the field mapping, which generally seems to work fine.
The issue occurs when editing the object on the Drupal side.
First, the value passes through the export handler for on/off checkboxes in sf_node.module, lines 383-392:
// Assume that a on/off checkbox is a SF boolean, which can never be set to NULL
function _sf_node_export_cck_checkbox($source, $field) {
$data = $source->$field;
if (empty($source->{$field}[0]['value'])) {
return 'false';
}
else {
return 1;
}
}
Assuming a starting value of 0 for $source->$field (the checkbox is in the off position), the export handler will return the string 'false'.
Next, the value is passed through a switch statement inside salesforce_api_fieldmap_export_create() in salesforce_api.module, starting at line 980:
switch ($type) {
case 'boolean':
if (empty($value)) {
$object->$sf_fieldname = 0;
}
else {
$object->$sf_fieldname = 1;
}
break;
...
The relevant bit here is the if condition. Given this particular code path, the "else" will always be executed, because a true input value turns into a 1 which is non-empty, and a false input value turns into the string 'false', which is also non-empty.
So, that was a really long-winded way of saying that I believe the single quotes should be removed from line 387 of sf_node.module, but there are enough assumptions in my reasoning that I'm not sure if doing so would break something elsewhere. That's why you're getting a long bug report, rather than a patch.
| Comment | File | Size | Author |
|---|---|---|---|
| #15 | boolean_value_fix-1195824-15.patch | 879 bytes | rjacobs |
| #10 | boolean_value_fix-1195824-10.patch | 886 bytes | aaronbauman |
| #3 | boolean_value_fix-1195824-0.patch | 483 bytes | mdunn |
Comments
Comment #1
EvanDonovan commentedPost bugs against the -dev release. Seems like you may be right. Aaron/Kosta, any thoughts?
Comment #2
mdunn commentedFor what it's worth, I've made the change I described in my own installation about a week ago, and it seems to be working fine so far.
In addition to removing the quotes from line 387, I changed 390 to be "return true;" for the sake of consistency.
Comment #3
mdunn commentedHere's the patch file.
Comment #4
EvanDonovan commentedTracking for 7.x-2.x.
Comment #5
kostajh commentedComment #6
EvanDonovan commentedI think Drupal standards are FALSE and TRUE. Is that correct?
There are lots of other places in the Salesforce modules where 1 is used for TRUE. It would be a nice cleanup to fix them all someday, but not necessary for this patch.
Comment #7
kostajh commentedYes, FALSE and TRUE should be capitalized.
In general I have been trying to run patches through Coder module before committing them and encourage people submitting patches to do the same.
Comment #8
jcarlson34 commentedJust ran into this problem myself. The fix in #4 worked great.
Comment #9
EvanDonovan commentedShould be re-rolled with FALSE & TRUE prior to commit.
7.x doesn't have a separate import/export handler for this, so it already behaves correctly.
Comment #10
aaronbaumanFrom the instructions for single on/off checkbox:
Therefore, we should actually be checking to see if the value is equal to either of the allowed values, rather than checking against empty().
This patch does that.
* If the source value does not match any allowed value, this patch returns nothing (which should actually do the same thing).
Comment #11
jcarlson34 commentedThe patch is working just fine for me so far. Time for RBTC status?
Comment #12
rjacobs commentedThe patch in #10 uses the following to calculate the on and off keys for a given checkbox field:
However, I think this will break-down if the off key is 0 and the on key is 1, such as:
I think this is because array_shift re-numbers numerical keys. From php.net:
So perhaps next() would be better than array_shift()?
Comment #13
rjacobs commentedAlso, I believe that a similar issue exists for importing checkbox values. I've opened-up a separate issue for that at #1438948: Need (better) import handler for CCK checkboxes.
Comment #14
mtbosworth commentedRemoving the quotes from "false" on line 387 fixed my issue. Drupal 6
Comment #15
rjacobs commentedI was just running some updates on a couple sites and realized this is still pending. Attached is a tweaked version of the patch from #10 that incorporates my point from #12.
Comment #16
aaronbaumanclosing all 6.x issues