Voting starts in March for the Drupal Association Board election.
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?
|Reverting node with field collection with link.png||51.98 KB||jummonk|