我创建了一个自定义实体,并且正在使用 CCK 字段。每个捆绑包都有自己的字段。例如:
function MYMODULE_install() {
// Check if our field is not already created.
if (!field_info_field('field_myField')) {
$field = array(
'field_name' => 'date_field',
'type' => 'list_text',
);
field_create_field($field);
}
//Enable is executed only once.
function bundle_callback_enable() {
// Create the instance on the bundle.
$instance = array(
'field_name' => 'date_field',
'entity_type' => 'payment_method',
'label' => 'Expiration Date',
'bundle' => 'card',
'required' => TRUE,
'settings' => array();
field_create_instance($instance);
}
我的包是从单个模块创建的,所以在每个安装文件中我都创建了相应的字段。
昨天我试图在这些字段中添加验证回调函数,我在表单数组中看到了一些奇怪的东西。type="text" 的字段具有以下路径:
$form[field_name]['und'][0][value] //<! expectable
但 type='list_text' 的字段只有路径:
$form[field_name]['und'] //<! unexpectable
我找不到任何解决方案,我已经解决了这个问题:
function &get_cck_path_value( $field_name, &$form_path) {
$field = null
if ( isset( $form_path[$field_name][LANGUAGE_NONE] ) ) {
$field = &$form_path[$field_name][LANGUAGE_NONE]
}elseif(isset($form_path[$field_name][LANGUAGE_NONE][0])) {
$field = &$form_path[$field_name][LANGUAGE_NONE][0]['value'];
}
return $field;
}
我不喜欢这种方法。太牛逼了。你能告诉我这是一个 cck 功能还是错误?我无法理解它何时决定将值放在哪里(所有过程都通过“field_attach_form(...)”完成)?
你有遇到过这样的问题吗?
提前致谢。
桑登姆。