Bagaimana Anda mengatur nilai bidang file saat menggunakan entitas_metadata_wrapper?
Saya sudah mencoba melakukan ini dalam kode:
$file = new stdClass();
$file->uid = 1;
$file->uri = $file_path;
$file->filename = basename($file_path);
$file->filemime = file_get_mimetype($file_path);
$file->filesize = filesize($file_path);
$file->status = FILE_STATUS_PERMANENT;
$file->display = '1';
file_save($file); // I also tried: $file = file_save($file);
$node = array(
'type' => 'news_item',
'uid' => 1,
'status' => 1,
'comment' => 0,
'promote' => 0,
'language' => 'en',
);
$entity = entity_create('node', $node);
$ewrapper = entity_metadata_wrapper('node', $entity);
$ewrapper->field_document->set((array) $file); // I also tried: $ewrapper->field_document->set($file);
$ewrapper->save(true);
entity_save('node', $entity);
Tapi saya mendapatkan pengecualian ini:
EntityMetadataWrapperException: Invalid data value given. Be sure it matches the required data type and format. in EntityMetadataWrapper->set() (line 122 of C:\wamp\www\drupal\sites\all\modules\entity\includes\entity.wrapper.inc).
Setiap bantuan sangat dihargai.