Drupal boolean radio button/check boxes select N/A option

Drupal boolean radio button/check boxes select the N/A option

我正在处理迁移 class,它需要 select 来自布尔检查 boxes/radio 按钮的 N/A 选项。我已将我的字段配置为 1 == True0 == No。但是我想 select N/A 选项,只要源中没有指定任何内容。

我在prepareRow函数中调用的函数是这样的:

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;
  }
}

所以如果来源看起来像这样:

我是否应该像这样 return 一个 NULL 并忽略该字段未 select 在 UI 中编辑或是否存在的事实select N/A 选项的方法?为了 select N/A 选项,我应该 returning 什么值?我尝试 returning -1NULL"N/A" 但没有成功。

或者是否可以使用迁移字段映射将字段的默认值设置为 N/A

注意:如果重要的话,这在使用 Commerce Kickstart 的 Drupal 7 上进行。另请注意,需要在迁移 class.

中设置 with PHP 代码

与此同时,我自己想通了。当您将产品上的字段从 No 更新为 N/A 时。保存并再次编辑,您将看到不再有任何选择。

所以在数据库中这也会导致 empty/deleted field/record。因此无需将其设置为 YesNo 等任何其他值。 N/A 按钮可以删除该值,以防您不再希望该值存在。

感谢所有阅读问题的人,如果早点查看 Drupal 数据库,我本可以早点解决这个问题。我希望这个答案对以后的其他人有用。