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:

  1. Enable field_collection_uuid.
  2. 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.

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.

Comments

ciss’s picture

Status: Active » Needs review
StatusFileSize
new593 bytes

Edit: Sorry, wrong patch.

ciss’s picture

Issue summary: View changes
ciss’s picture

Issue summary: View changes
ciss’s picture

StatusFileSize
new4.47 KB

Using this patch we were able to export, reimport and update nodes containing nested field collections.

Dependencies

; Date: 2014-07-03
; Contains: field_collection
projects[field_collection][version] = "1.0-beta6+12"
projects[field_collection][download][branch] = "7.x-1.x"
projects[field_collection][download][revision] = "9b507ac"
; field_collection_field_widget_form() should not override default $element properties
; May not be required, but has been added since it is currently used
projects[field_collection][patch][2001682-1] = "https://www.drupal.org/files/field_collection-2001682-1.patch"

; Date: 2014-05-15
; Contains: uuid
projects[uuid][version] = "1.0-alpha5+18"
projects[uuid][download][branch] = "7.x-1.x"
projects[uuid][download][revision] = "4f00a9d"
; Remove contrib implementations
projects[uuid][patch][2074599-2] = "https://www.drupal.org/files/uuid_remove_contrib_support-2074599-2.patch"
; Add hook_uuid_entities_pre_rebuild_alter
projects[uuid][patch][2308983-1] = "https://www.drupal.org/files/issues/uuid-hook_uuid_entities_pre_rebuild_alter-2308983-1.patch"

; Date: 2014-06-15
; Contains: deploy
projects[deploy][version] = "2.0-alpha2+34"
projects[deploy][download][branch] = "7.x-2.x"
projects[deploy][download][revision] = "7dbe4a6"
; Expose the Deploy Iterator in the UI
projects[deploy][patch][2290059-1] = "https://www.drupal.org/files/issues/deploy-2290059-1.patch"

; Date: 2014-06-14
; Contains: entity_dependency
projects[entity_dependency][version] = "1.0-alpha1+15"
projects[entity_dependency][download][branch] = "7.x-1.x"
projects[entity_dependency][download][revision] = "4139d7c"

; Date: 2014-07-09
; Contains: features
projects[features][version] = "2.0+20"
projects[features][download][branch] = "7.x-2.x"
projects[features][download][revision] = "bcb058e"

; Date: 2014-04-08
; Contains: entity
projects[entity][version] = "1.5+2"
projects[entity][download][branch] = "7.x-1.x"
projects[entity][download][revision] = "4d2cc6f"

The last submitted patch, 1: uuid-hook_uuid_entities_pre_rebuild_alter-2308983-1.patch, failed testing.

damok’s picture

I'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?

ciss’s picture

@damok: How are you applying the patch? Are you using the "patch" command or "git apply" (recommended)?

damok’s picture

@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 :)

jmking’s picture

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.

So where does this leave Services support? It's no longer in uuid_services, and it's not in field_collection_uuid.

ciss’s picture

@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:

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.

jmking’s picture

https://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.

ciss’s picture

@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.

paulmartin84’s picture

@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_dependencies as 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.

Arnaud Kali’s picture

This 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.