Skip to content

Instantly share code, notes, and snippets.

@visabhishek
Last active January 28, 2016 08:40
Show Gist options
  • Save visabhishek/8a61d4e7774db4ec2c53 to your computer and use it in GitHub Desktop.
Save visabhishek/8a61d4e7774db4ec2c53 to your computer and use it in GitHub Desktop.
Copy all field collection data to Paragraph item in node wise
$node_wrapper = entity_metadata_wrapper('node', $nodes);
$raw_collection = $node_wrapper->field_testp->value();
foreach ($node_wrapper->field_test as $key => $field_collection_wrapper) {
$collection = new ParagraphsItemEntity(array('field_name' => 'field_testp', 'bundle' => 'paratest'));
$collection->is_new = TRUE;
$collection->setHostEntity('node', $nodes);
$field_collection = $field_collection_wrapper->value();
if (isset($field_collection->field_test1['und'][0]['value'])) {
$collection->field_ptest1 = $field_collection->field_test1;
}
if (isset($field_collection->field_test2['und'][0]['value'])) {
$collection->field_ptest2 = $field_collection->field_test2;
}
if (isset($field_collection->field_test3['und'][0]['value'])) {
$collection->field_ptest3 = $field_collection->field_test3;
}
if (isset($field_collection->field_test4['und'][0]['value'])) {
$collection->field_ptest4 = $field_collection->field_test4;
}
$collection->save();
}
@visabhishek
Copy link
Author

We can use above to Copy all field collection data to Paragraph item in node wise.

1: Just add rules -> components ->action ruleset
2: pass node as parameter variable name as nodes
3: Add execute PHP in action
4: Copy/Paste above code in that
5: Just update fields name according your requirement

Now you can create a VBO display and copy fileds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment