Drupal 7 使用嵌套的fieldcollection项Drupal 7以编程方式创建节点

Drupal 7 使用嵌套的fieldcollection项Drupal 7以编程方式创建节点,drupal-7,Drupal 7,我需要以编程方式创建一个节点。在我的内容类型中,有一个字段集合,其中有另一个字段集合。现在,如何在内部字段集合中保存字段的值,以便由于此嵌套字段集合结构而无法在此节点中保存字段集合项 下面是我的代码: global $user; $node = entity_create('node', array('type' => 'key_sentence')); // replace entity_type and entity_bundle with your info // Specify t

我需要以编程方式创建一个节点。在我的内容类型中,有一个字段集合,其中有另一个字段集合。现在,如何在内部字段集合中保存字段的值,以便由于此嵌套字段集合结构而无法在此节点中保存字段集合项

下面是我的代码:

global $user;
$node = entity_create('node', array('type' => 'key_sentence')); // replace entity_type and entity_bundle with your info
// Specify the author
$node->uid = $user->uid;
// Create a Entity Wrapper of that new Entity
$entity = entity_metadata_wrapper('node', $node);

// Specify the title
$entity->title = 'Test node';
// Add field data... SO MUCH BETTER!
$entity->field_key_sentence_text = 'Field value text';

$entity->save(); // necessary in order to attach field collections

//Outer field collection
$field_collection_1 = entity_create('field_collection_item', array('field_name' => 'field_ks_sent_to'));
// Set default values as necessary
$field_collection_1->setHostEntity('field_collection_item', $entity); // again, replace entity_type as appropriate
$field_collection_1->save(TRUE);

//Inner field collection
$field_collection_2 = entity_create('field_collection_item', array('field_name' => 'field_ks_in_voice'));
// Set default values as necessary
$field_collection_2->setHostEntity('field_collection_item', $field_collection_1);

//Field in inner field collection
$field_collection_2->field_message_url[LANGUAGE_NONE][0]['value'] = 'http://www.google.com';
$field_collection_2->save(TRUE);

$entity->save();
但我得到了这些错误:

Notice: Undefined index: value in field_collection_field_update() (line 933 of /home/postcinn/public_html/dev/sites/all/modules/field_collection/field_collection.module).
EntityMalformedException: Missing bundle property on entity of type field_collection_item. in entity_extract_ids() (line 7766 of /home/postcinn/public_html/dev/includes/common.inc).

我认为对于初学者,您需要确保第一级字段集合的宿主实体是
节点
类型而不是
字段集合项目

我不明白你在说什么,请让我明白。什么是错误的,我应该怎么做?重复原始问题的代码,并添加一个句子似乎是一个糟糕的答案。为什么不显示代码应该是什么样子呢。
//Outer field collection
$field_collection_1 = entity_create('field_collection_item', array('field_name' => 'field_ks_sent_to'));
// Set default values as necessary
$field_collection_1->setHostEntity('field_collection_item', $entity); // again, replace entity_type as appropriate
$field_collection_1->save(TRUE);