Summary
There is currently no support for the export and import of field collection entities through UUID + Deploy + Features. The goal of this issue is to provide means to reliably export field_collection entities and reimport them regardless of their level of nesting.
It also may be used as reference to provide full field_collection import through Deploy/Services.
Current state
UUID resolves dependencies by importing required entities first before importing the host entity. This may work well for cases where the referenced entity can be managed independently. It fails completely for field_collection_item entities which require to be saved within their host entity.
Current solutions attempt to work around this via several hacks which include overriding the entity controller and setting a default value for the field_collection_item.revision_id column. At best these workarounds produce duplicate, detached field_collection_item entries. At worst the import fails completely.
Solution
The attached patch takes a different approach. By adding a new hook to UUID we are able to remove field_collection_item entities from the list of entities to be imported.
Once hook_field_uuid_presave() is invoked, we retrieve them again by their UUID, convert them to full FieldCollectionItemEntity instances and add them to the host entity's field_collection_item field. That way FC objects can be handled by field_collection without the need for any hacks.
Patch
The patch uses a modified version of the original patch in #2075325: Provide a Field Collection UUID module to support UUID/Deploy, from which it removes the controller override, the property __uuid_universalized and Services related code.
After patching the following steps are required:
- Enable field_collection_uuid.
- Make sure your deployment plan uses the Deploy Iterator.
Required issues
The patch relies on additional patches from the following issues. A complete list of required project versions and patches should be provided with each patch that gets added to this issue.
- #2074599: Remove all Contrib module functions from uuid.core.inc, plus reference where UUID support is for contrib modules
- #2308983: Add hook_uuid_entities_pre_rebuild_alter()
- #2290059: File deployment doesn't work due to missing DeployIterator plugin.
Disclaimer
There are already several issues tackling support for UUIDs in field collections as well as export and import of nested field collections through Features. Most of these issues are convoluted with different use cases and patches with unclear dependencies.
This issue is meant to serve as a clean starting point. Each provided patch should explicitely mention all required project versions and patches.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | field_collection-uuid-deploy-features-support-2309103-4.patch | 4.47 KB | ciss |
Comments
Comment #1
ciss commentedEdit: Sorry, wrong patch.
Comment #2
ciss commentedComment #3
ciss commentedComment #4
ciss commentedUsing this patch we were able to export, reimport and update nodes containing nested field collections.
Dependencies
Comment #6
damok commentedI'm trying to apply this patch and enable field_collection_uuid but it isn't showing in the module list, can someone confirm the location that field_collection_uuid needs to be installed?
Comment #7
ciss commented@damok: How are you applying the patch? Are you using the "patch" command or "git apply" (recommended)?
Comment #8
damok commented@ciss: I'm using git apply. It appears to work but then there is nothing showing in git diff.
Edit:
I've tested using the patch command instead and it worked :)
Comment #9
jmking commentedSo where does this leave Services support? It's no longer in uuid_services, and it's not in field_collection_uuid.
Comment #10
ciss commented@jmking: To be implemented, as far as I'm aware. This patch only covers the Features use case, but the underlying process should apply to a deployment via Services as well.
To quote from the summary:
Comment #11
jmking commentedhttps://www.drupal.org/sandbox/graber/2141747 (Services field collection)
I came across this in sandbox which might work alongside the above patches.
In the meantime, I've managed to get something to work as a stop-gap here: https://www.drupal.org/node/2075325#comment-9933884. It isn't pretty, but it works.
I imagine it's going to be a while before this approach makes its way into any stable branches as uuid has to coordinate the removal of it's contrib support with the availability of uuid and services implementations for each of the contrib modules that uuid currently supports.
Comment #12
ciss commented@jmking: A good start might be a reroll of the above patch against the current stable releases (or heads, where stable is too old). Two of the three patches mentioned in the summary have been committed, and the third still passes. This may be a the chance to clean up the dependency mess and provide an even better basis.
Comment #13
paulmartin84 commented@ciss Thanks for your effort on this, I have created a submodule for paragraphs based on your work, https://www.drupal.org/node/2471174#comment-9996447 and confirm that it works well with nested paragraph entities and deploy
The only difference was I needed to include
hook_field_entity_dependenciesas paragraphs is not included in the core list. Now that UUID has removed support for field collections it might be a good idea to also remove it from the entity_dependencies module as-well.Comment #14
Arnaud Kali commentedThis patch fom #4 solves a problem on several sites where I've been using FC with features - Features wouldn't import / export any of my features with field collection bundles and field collection wouldn't save upon edits as long as the this patch, together with patches from https://www.drupal.org/node/2074599#comment-7798611 and https://www.drupal.org/node/2308983#comment-8994755 haven't been applied - the patch from #4 completes solving that problem and all normal functionalities of FC now work again without problems, just like import/export functionality.