mooru
mooru

Reputation: 71

Populate node field after feeds import

I have a situation where I am trying to clone a node field after importing content via feeds. I am doing this because of a challenge I have with feeds_tamper_string_2Id module. I have tried the following code but it didn't work

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);
       }
    }
}

I want to copy the values of field_tags2['und'] into field_tag_people['und'].

Upvotes: 0

Views: 73

Answers (1)

Fky
Fky

Reputation: 2173

If your field is a taxonomy reference you can try this :

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'];
      }
    }  
  }
}

EDIT

You can use entity_metadata_wrapper : https://www.drupal.org/docs/7/api/entity-api/entity-metadata-wrappers

Upvotes: 0

Related Questions