标签: drupal-field-collection

修改以编程方式缺少hostEntity字段的字段集合

我正在尝试修改已存在的节点中的字段集合,因此我可以在3的数组中的第一个元素上更改图像.问题是,当我执行entity_load或entity_load_single时,未设置hostEntity信息,所以当我做一个:

$field_collection_item->save(true); // with or without the true
// OR
$fc_wrapper->save(true); // with or without the true
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

Exception: Unable to save a field collection item without a valid reference to a host entity. in FieldCollectionItemEntity->save()
Run Code Online (Sandbox Code Playgroud)

当我print_r字段集合实体时,hostEntity:protected字段确实是空的.我的字段集如下设置:

  • field_home_experts
    1. 专家图片<---想要仅更改此数据并保留以下内容
      • field_expert_image
      • 图片
    2. 专家名称
      • field_expert_name
      • 文本
    3. 专家名称
      • field_expert_title
      • 文本

这是我试图用来修改现有节点字段集合的代码:

$node = getNode(1352); // Get the node I want to modify

// There can be up to 3 experts, and I want to modify the image of the first expert
$updateItem = …
Run Code Online (Sandbox Code Playgroud)

drupal drupal-7 drupal-field-collection

0
推荐指数
1
解决办法
9572
查看次数

标签 统计

drupal ×1

drupal-7 ×1

drupal-field-collection ×1