When I create a node with a field_collection as embedded field, and the field_collection itself has a link field in it I receive a PDOException when I revert a previous version of the node with workbench_moderation. (See attachment)

Apparently the link attributes are being saved unserialized as the field in the previous field_collection item is loaded and then saved again when a new version is created.

I could resolve this with my implementation of hook_field_attach_update() and serializing link attributes there.

But then I stumbled into another problem.

I got warnings whenever I reverted a node with a field collection item which contained a file field (image or file).

In the end I could solve both issues by implementing hook_entity_info_alter and giving field_collection_item my custom 'controller class'. In that controller class I did only one thing: remove the code which initiates a field_attach_update() of the original entity in MyCustomEntityAPIController->save().
This comment explains what happens in the code there:

// Field API always saves as default revision, so if the revision saved
(This is the case for me because I am reverting a previous version of a node.)
// is not default we have to restore the field values of the default
// revision now by invoking field_attach_update() once again.
(Default revision for workbench_moderation is not the same as for core. I suspect here lies the issue.)

IMO, field_attach_update should not happen for field collection items at revert of a previous version. The fields of that version of the field collection item entity are not changed so I don't see a reason to update them. The warning was generated by file_field_update() (in file.field.inc) because the original entity was missing ($entity->original). The original entity is always missing if there was no original entity, as this original entity is the first version of the field collection item.

So basically, I have a support request: why are fields of a field collection item being updated when a node is reverted? (The original field collection item has not been updated at that time.) Or am I missing something?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

nathanjo’s picture

I confirmed the issue. When reverting with a link field it causes some PDO exception http://note.io/10ScFm0.
And for note, not using workbench moderation, so I guess this really the field collection bug.

dealancer’s picture

Any patch or workaround?

Anonymous’s picture

I developed a workaround with a patch to the entity module - see https://drupal.org/node/2283933

jmuzz’s picture

Status: Active » Postponed (maintainer needs more info)

I tried to duplicate this with and without workbench moderation but I was able to revert the node without errors even though it had a field collection item with a link field containing data in it.

Is this still happening? If so can somebody provide more specific steps to reproduce?

jmuzz’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)