フォームを使用してノード(コンテンツタイプ:ソング)を作成しようとしています。私は、タイル/説明を設定することができますが、それはファイルをアップロードするために来るとき、私はこのエラーを取得する:フォームを使用してノードにファイルを追加する
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048
Column 'field_file1_display' cannot be null: INSERT INTO
{field_data_field_file1} (entity_type, entity_id, revision_id, bundle,
delta, language, field_file1_fid, field_file1_display,
field_file1_description) VALUES (:db_insert_placeholder_0,
:db_insert_placeholder_1, :db_insert_placeholder_2,
:db_insert_placeholder_3, :db_insert_placeholder_4,
:db_insert_placeholder_5, :db_insert_placeholder_6,
:db_insert_placeholder_7, :db_insert_placeholder_8); Array (
[:db_insert_placeholder_0] => node [:db_insert_placeholder_1] => 67
[:db_insert_placeholder_2] => 67 [:db_insert_placeholder_3] => song
[:db_insert_placeholder_4] => 0 [:db_insert_placeholder_5] => und
[:db_insert_placeholder_6] => 55 [:db_insert_placeholder_7] =>
[:db_insert_placeholder_8] =>) in
field_sql_storage_field_storage_write() (line 448 of
/Users/blabla/_server/drupal/modules/field/modules/field_sql_storage/field_sql_storage.module).
これは私が書いたコードです。
function insertnode_form_submit($form, &$form_state) {
$node = new StdClass();
$node->type = 'song';
$node->status = 1;
$node->language = LANGUAGE_NONE;
$node->title = $form['name']['#value'];
$node->field_song_description[$node->language][0]['value'] = $form['description']['#value'];
$file_path = drupal_realpath($form['file1']['#file']->uri);
$file = (object) array(
'uid' => 1,
'uri' => $file_path,
'filemime' => file_get_mimetype($file_path),
'status' => 1,
);
$file = file_copy($file, 'public://');
$node->field_file1[$node->language][0] = (array)$file;
//$node->field_file1[$node->language][0] = (array)$form['file1']['#file'];//also tried this but nothing
node_save($node);
}