2012-09-14 23 views
6

私はカスタムウィジェットを作成しようとしていますが、提出すると、Drupalはデータを保存していないようです。 hook_field_attach_submit()を使用して貼り付けたデータを表示すると、nullとしてリストされます。drupalフィールドウィジェットは送信されたデータを保存しません

奇妙なことに、#typeをフィールドセットではなく単一のテキストフィールドに変更すると、入力された文字列の最初の文字のみが保存されます。

これは検証の問題のようですが、どのようにフックするか、問題をデバッグする方法がわかりません。どこから行くことができますか?

<?php 
function guide_field_widget_info(){ 
    dpm("guide_field_widget_info"); 
    return array(
    'guide_text_textfield' => array(
     'label' => t('test Text field'), 
     'field types' => array('text'), 
     'settings' => array('size' => 60), 
     'behaviors' => array(
     'multiple values' => FIELD_BEHAVIOR_CUSTOM, 
     'default value' => FIELD_BEHAVIOR_DEFAULT, 
    ), 
    ) 
); 
} 


function guide_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) { 
    $field_name = $instance['field_name']; 
    $required = $element['#required']; 
    $item =& $items[$delta]; 


    $element += array(
     '#type' => 'fieldset', 
    '#title' => t('helloooooooo'), 
    ); 
    $required = $element['#required']; 
    $item =& $items[$delta]; 

    $element['nametest'] = array(
     '#title' => t('Name'), 
     '#type' => 'textfield', 
     '#required' => $required, 
     // use #default_value to prepopulate the element 
     // with the current saved value 
     '#default_value' => isset($item['nametest']) ? $item['nametest'] : '', 
    ); 

    $element['checkme'] = array(
     '#title' => t('Check this box or dont'), 
     '#type' => 'checkbox', 
     '#default_value' => isset($item['checkme']) ? $item['checkme'] : '', 
    ); 

//When changing the above code to have a single field, $value is no longer null but will display the first character of the string. I've pasted the code I used to test beloe 
/* 
    $element+= array(
    '#title' => t('Name'), 
    '#type' => 'textfield', 
    '#default_value' => isset($item['nametest']) ? $item['nametest'] : '', 
); 
*/ 

    return $element; 
} 


//hooking this here is required given that after submit, the value is a multidimensional array, whereas the expected value of text is, well, text :-) 

function guide_field_attach_submit($entity_type, $entity, $form, &$form_state){ 
    dpm($form,"guide_field_attach_submit data"); //shows $form[field_test_field][und][0] [value] as being null 
} 
+0

を最初の文字がおなじみの問題のように聞こえる保存します。 http://stackoverflow.com/questions/6426362/custom-drupal-7-field-only-saves-the-first-characterの前回の回答が役立つかどうかを確認してください。 – nmc

+0

ダイスはありません。私はコードを提供しようとしたが、私はまだ同じ結果を持っていた。 – devnill

+0

この問題の解決策を見つけましたか? –

答えて

2

hook_field_is_emptyは必須であり、次のように実装する必要があります。

/** 
    * Implements hook_field_is_empty(). 
    */ 

function MODULENAME_field_is_empty($item, $field) { 
    if ($field['type'] == 'FIELDTYPE') { 
    if (empty($item[$field['type']]['YourField'])) { 
     return (TRUE); 
    } 
    } 
    return (FALSE); 
} 
+2

これはFIELDNAME_field_is_emptyではなく、HOOK_field_は空です。ここでHOOKはモジュールの名前です。 – sbrattla

関連する問題