在导入导入后填充节点字段

时间:2016-11-24 18:41:40

标签: drupal drupal-modules drupal-feeds

我遇到的情况是,我在尝试通过Feed导入内容后克隆节点字段。我这样做是因为我对feeds_tamper_string_2Id模块的挑战。我尝试了以下代码,但它没有用

function members_entity_presave($entity, $type)
{
    if($entity->type == 'members') {
       foreach ($entity->field_tags2['und'] as $tags) {
          array_push($entity->field_tags_people['und'], $tags);
       }
    }
}

我想将field_tags2['und']的值复制到field_tag_people['und']

1 个答案:

答案 0 :(得分:0)

如果您的字段是分类标准参考,您可以尝试:

function MYMODULENAME_entity_presave($entity, $type)
{
  if($entity->type == 'members') {
    $items = field_get_items($type, $entity, 'field_tags2');
    if(is_array($items)) {
      foreach ($items as $tags) {
        $entity->field_tags_people[LANGUAGE_NONE][]['tid'] = $tags['tid'];
      }
    }  
  }
}

修改

您可以使用entity_metadata_wrapper:https://www.drupal.org/docs/7/api/entity-api/entity-metadata-wrappers