Has ノード $order および field_collectionfile_field
で設定できません:field_collection
field_blueprints
<?php
$entity_type = "field_collection_item";
$blueprint_obj = entity_create($entity_type, array('field_name' => "field_blueprints") );
$blueprint_obj->setHostEntity('node', $order);
$blueprint_entity = entity_metadata_wrapper($entity_type, $blueprint_obj);
date_default_timezone_set("UTC");
$blueprint_entity->field_blueprint_file->file->set((array)$file);
$blueprint_entity->field_blueprint_comment = (string) $file->filename;
$blueprint_obj->save();
node_save($order);
そして、このコードはエラーをスローします:
EntityMetadataWrapperException: 無効なデータ値が指定されました。必要なデータ型と形式に一致していることを確認してください。(
EntityDrupalWrapper->set()
sites//all/modules/entity/includes/entity.wrapper.inc の 736 行目)。
私も試しました:
$blueprint_entity->field_blueprint_file->set((array)$file)
$blueprint_entity->field_blueprint_file->set(array('fid'=>$file->fid))