Optimally people should be able to run the Drupal migrate update through the UI with field collection installed in both versions and have the fields and data transferred without extra user configuration.
This works fairly well for Drupal core fields, but because of how Drupal's field migrate plugin is structured there currently isn't a way for custom modules to make use of the same API. What's worse, field collection fields will be identified by the core field migrate plugin even though it can't deal with them. Even creating a custom alternative to core's field migration plugin for field collections will not solve the second problem.
See related issues for a potential core patch that could solve these problems.
| Comment | File | Size | Author |
|---|---|---|---|
| #31 | 2757989-patch-migrate-multi-value-field-collection.diff | 3.13 KB | hypertext200 |
| #18 | d7_field.yml | 1.04 KB | geosalameh |
| #12 | field_collection-d7_migration_source-2715397-12.patch | 2.09 KB | generalredneck |
| #6 | FieldCollectionField.txt | 1.29 KB | jmuzz |
Comments
Comment #2
jmuzz commentedComment #3
jmuzz commentedcaxy4 made a migrate destination plugin for field collection item entities. This may be a better approach then trying to import the fields.
Comment #4
jmuzz commentedI looked into importing the config entities for field collections more directly but all the config info for the field collection bundles in D7 is in the field config anyway, so it would pretty much amount to making a field import plugin. I think it's better to use the one in core for that, even if it needs to be hacked.
Comment #5
jmuzz commentedIt may not even be necessary to hack core. I made a basic FieldCollectionField MigrateCckPlugin that doesn't handle anything but I confirmed its processCckFieldValues is getting run and there are messages about each of the field collection fields in watchdog after the migration is run.
Using latest drupal 8.1.x
Comment #6
jmuzz commentedWell the processField function doesn't seem to be getting called for drupal 7 field plugins.
It's still a work in progress and the core migrate modules may need some changes before it can work but this is a start.
Comment #7
jmuzz commentedApplying #2631736-72: Cckfield Plugins must distinguish core versions gets it importing the the field collection fields / bundles, including nested field collection structure, but none of the data, and it's saying the plugin field_collection_view is not found even though it's mapped in getFieldFormatterMap(). getFieldFormatterMap() does not seem to be getting run at all.
Comment #8
jmuzz commentedWith the addition of the patch in #2726803: Field formatters with names different than their field type can not be migrated the field collection display/formatter settings are migrating. That should be everything but the actual content of field collection items.
Comment #9
jmuzz commentedThe widgets for fields inside field collections are all getting set to hidden and still need to be migrated correctly.
Comment #10
jmuzz commentedLooks like the widget settings will be covered by this one.
Comment #11
jmuzz commentedThere currently isn't a supported way to migrate a setup into D8 so that a field's widget is hidden, since hidden widgets weren't in D7 core.
Comment #12
generalredneckWith all that said, here is a start... I needed to do a migration of a field collection to d8 from d7 as a different entity, but this source plugin was handy! I don't know if I should make this a new "feature request" or leave it here.
Comment #13
jmuzz commentedDevelopment is moving to 8.x-3.x.
Thanks for the plugin, it will be helpful to complete this issue.
Comment #14
gerzenstl commentedI'm trying to validate this plugin for a D7 -> D8 migration, but I'm not able to make it work.
Is there any example on how to define the yml file for that plugin?
Comment #15
geosalameh commented@gerzenstl worked for me.
However still getting the below error whenever I run upgrade_d7_field_formatter_settings migration;
The "field_collection_view" plugin does not exist. (C:\wamp\www\dev\drupal\core\lib\Drupal\Component\Plugin\Discovery\DiscoveryTrait.php:52)[error]Comment #16
jmuzz commentedThe formatters may require the patch from #2726803: Field formatters with names different than their field type can not be migrated.
Comment #17
generalredneckPlease keep in mind the plugin in the patch above will not migrate field_collection fields over. It will migrate field collection entities over. Field Collection Fields are much like entity reference fields. Note that the plugin created above is a source plugin, not a process plugin that uses the cck_field classes. That part still needs to be built... or at the very least a migration template... the above is a start that I contributed as I mapped field collection items to paragraphs.
The use of this plugin is simply
And then somewhere in your other migrations use something like
Comment #18
geosalameh commented@jmuzz I've already tried the patch you've mentioned but seems it is not stable enough, since when I've used it I got a higher number of failed field migrations
@generalredneck I am not sure if this is the right way to import field collection fields, but I was able to do so by mapping it in d7_field.yml file (attached)
I will be looking to solving this;
The "field_collection_view" plugin does not exist. (C:\wamp\www\dev\drupal\core\lib\Drupal\Component\Plugin\Discovery\DiscoveryTrait.php:52)I will try the suggested solution to migrate content.
Thank you,
Geo
Comment #19
generalredneckClever. That should work if the d7 configuration and d8 configuration match... that will get you the "Field" itself, but I feel you probably will still have to work on it's content. That's where my solution above comes in.
Comment #20
gerzenstl commented@geosalameh: your approach works fine to migrate the field collections (fields and their instances). Regarding the
field_collection_viewerror, isn't related to the module with the same name? Because I'm don't get that error.@generalredneck: the patch that I was testing (trying to make it work) before, was very similar to the one you shared. But it's not working, I'm still not able to migrate the content for those fields.
Comment #21
geosalameh commented@generalredneck I've tried to create a migration template in modules/field_collection/migration_templates/d7_simple_field_collection.yml with the following content;
But still not showing once I run "drush ms".
Also you've mentioned a second yaml file upgrade_d7_node_blog which usually is auto-generated by "drush migrate-upgrade" or should we create it in this case?
Thank you for you help
Comment #22
geosalameh commented@gerzenstl I am not sure why I am getting this error, in addition to this;
Which is related to #2726803: Field formatters with names different than their field type can not be migrated
Btw, Field Collection Views is not installed on my site.
Comment #23
geosalameh commentedI've written a custom PHP class to migrate Field Collection data from 7 to 8, it does the following:
Notes:
- Run this script once you've completed all migration imports (especially fields, files and nodes...)
- You need to run Clear Cache after running this script, in order for Drupal to update entity cache.
File: migrate_field_collection_data.php
Feel free to modify this script
Comment #24
geosalameh commentedBtw, I've tried to write a module for this but didn't have enough time, so I went with the easiest option ;)
Comment #25
dhruva2 commentedgeosalameh, how to run and where to put your script.
Comment #26
geosalameh commentedHello dhruva2,
php drupal/modules/field_collection/migrate_field_collection_data.php(the full path may be different on your server)Comment #27
geosalameh commentedBtw this script is not taking into consideration multilingual fields, or field collection in another field collection!
Comment #28
dhruva2 commentedHi Geosalameh,
Thanks for updating the article. I will update it with the results.
Thanks and regards
Comment #29
dhruva2 commentedHi,
Do I need to use Drush to run this command.
Thanks and Regards
Comment #30
hypertext200After the patch, use as below
Comment #31
hypertext200Comment #32
dhruva2 commentedHi heshanlk,
About which patch you are talking about? d7field.yml patch?
Comment #33
hypertext200Ho sorry for the confusion, the one attached to the comment #31
Comment #34
dhruva2 commentedHi Heshankl,
So I need to add https://www.drupal.org/files/issues/2757989-patch-migrate-multi-value-fi... to
core/modules/field/migration_templates
and than
where to add this code in which file, sorry for asking lots of questions as I am naive
id: d7_field_collection[MACHINE NAME]
migration_tags:
- 'Drupal 7'
label: 'Field Collection [NAME]'
source:
plugin: d7_field_collection_item
field_name: [FIELD COLLECTION MACHINE NAME]
process:
item_id: item_id
revision_id: revision_id
field_name: field_name
host_type: entity_type
host_entity_id: entity_id
destination:
plugin: 'entity:field_collection_item'
migration_dependencies:
required: { }
Thanks and regards
Comment #35
hypertext200You need to apply the patch, read here https://www.drupal.org/patch/apply. And then you can create a yml files for the migrations of each field collection you have. I know I'm not much help here, you need to read how to create yml files for the migrations etc.
Comment #36
dhruva2 commentedalso, do I need to change machine name for each FC.yml
Comment #37
dhruva2 commentedGuys after databases migration I have the following error. I am unable to understand what is the reason
TypeError: Argument 1 passed to Drupal\Core\Entity\Entity\EntityFormDisplay::buildForm() must implement interface Drupal\Core\Entity\FieldableEntityInterface, null given, called in /home/dhruva/webapps/d82/modules/field_collection/src/Plugin/Field/FieldWidget/FieldCollectionEmbedWidget.php on line 64 in Drupal\Core\Entity\Entity\EntityFormDisplay->buildForm() (line 159 of core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php).
Comment #38
soajetunmobi commentedHi geosalameh,
Thank you for the superb script, it did exactly what you said it will do. I only have one problem though. After clearing cache nothing seem to happen. The parent node is not attached to the field collection. Am I missing something. Is there any chance you can share your node migration script (node.yml). Most especially node to field collection mapping.
Thank you once again.
Comment #39
shailesh.bhosaleHi geosalameh, Your script in #23 was helpful.
Thanks!
Comment #40
t14 commentedHi
Tried the patch in #31 and I got the following error
Any ideas
Comment #41
drone.ah commented#31 worked for me, except I had to change the annotation from
source_providertosource_moduleComment #42
Christopher Riley commentedI had to do the same as #41 to get drush to clear the cache even after I installed the patch.
Comment #43
ram4nd commented