在drupal 7 CCK字段“list_text”中以编程方式添加允许值列表

前端之家收集整理的这篇文章主要介绍了在drupal 7 CCK字段“list_text”中以编程方式添加允许值列表前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想知道我是否可以以编程方式创建CCK字段实例并在单个阶段中插入“allowed_values”.所以我试过这个:
field_create_instance(array(
  'field_name' => 'card number','entity_type' => 'payment_method','bundle' => 'debit_card','label' => t('Debit/Credit card'),'description' => t('Add card\'s number '),'widget' => array(
      'type' => 'options_select','weight' => 0,'settings' => array('size' => 50),),'required' => TRUE,));

我尝试了一些案例,即设置’setting’=> array(‘allowed_values’=> array(1,2,3))但没有任何反应.有什么建议?

解决方法

解:
function MY_MODULE_install() {
  field_create_field(array(
    'field_name' => 'months','type' => 'list_text','cardinality' => 1,'settings' => array('allowed_values_function' => 'get_months'),'entity_types' => array('user','node'),));
}

function get_months() {
  $months = array( '01','02','03',...'12');
  return $months;
}

警告:回调函数必须始终位于自定义模块的* .module文件中.

猜你在找的HTML相关文章