사용자 정의 위젯을 만들려고하지만 제출할 때 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
}
첫 번째 문자가 익숙한 문제 같은 소리 저장. http://stackoverflow.com/questions/6426362/custom-drupal-7-field-only-saves-the-first-character에 대한 이전 답변이 도움이되는지 확인하십시오. – nmc
주사위가 없습니다. 내가 제공 한 코드를 시도하고 나는 여전히 같은 결과가있었습니다. – devnill
이 문제에 대한 해결책을 찾았습니까? –