I'm working on a migrate class that needs to select the N/A option from the boolean check boxes/radio buttons. I have configured my fields so 1 == True
and 0 == No
. But I would like to select the N/A
option whenever nothing is specified in the source.
The function I call in the prepareRow
function looks like this:
protected function utcYesNoBoolean($value) {
$upper = strtoupper($value);
switch ($upper){
case "YES":
return 1;
break;
case "NO":
return 0;
break;
//Not filled in so set to NA
default:
return NULL;
break;
}
}
So if the source looks like this:
Should I just do it like this and return a NULL
and ignore the fact that the field is not selected in the UI, or is there a way to select the N/A
option? What value should I be returning in order to select the N/A
option? I tried with returning -1
, NULL
and "N/A"
but no success.
Or is there maybe an option to set the default value of the field to N/A
using the migrate field mapping?
Note: This on Drupal 7 using Commerce Kickstart if that matters. Please also note it is required to set the with PHP code in the migrate class.
In the meantime I figured it out myself. When you update the field on a product from No
to N/A
. Save it and edit it again you will see that there is nothing selected anymore.
So in the database this will also result in an empty/deleted field/record. So there is no need to set it to anything else as Yes
or No
. The N/A
button is there to remove the value in case you don't want the value to be there anymore.
Thanks everyone who read the question, I could have figured this out earlier if checked the Drupal database earlier. I hope this answer is useful for some one else in the future.