0
我已經創建了一個自定義實體,並使用了CCK字段。每個包都有自己的字段。例如:獲取表單數組中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);
}
我的包是從單獨的模塊創建的,所以在每個安裝文件中我都創建了相應的字段。
昨天我試圖在這些字段中添加驗證回調函數,並且我在窗體數組中看到了一些奇怪的東西。同類型的字段=「文本」有路徑:
$form[field_name]['und'][0][value] //<! expectable
但類型字段=「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(...)」來實現)?
你有沒有遇到過這樣的問題?
在此先感謝。
Thandem。
埃德它不是縮寫形式領域。當我使用dsm函數時,我在類型爲list_text的字段中看到: – thandem
層次結構(http://pastebin.com/YQL32WXF) – thandem