VBO not working on field collection table

Created on 11 February 2024, 4 months ago

Problem/Motivation

We need to update field collections from a views display based on Field collection item

Steps to reproduce

Create a node type with a field collection
Create a couple of nodes
Set a vbo field to modify fc fields
During the modification, the field is simply erased, the host node is not revisioned.

By the way, I never seen any issue related to that usage of field collection, as if the only use case was to visualize nodes that have fCs but never FCs that are incidentally attached to nodes...

Proposed resolution

When looking at what happens in field_collection_field_update(), the arguments submitted from modifying the field collection compared to what comes with modifying from a node is very different, missing some information.
I succeeded at making possible to modify a single field collection by tweaking and saving the host node at the start of the function

if(!isset($host_entity->revision)){
		if(!isset($host_entity->initial)){
			$host_entity->initial = TRUE;
		}
		$host_entity->vid = NULL;
		$host_entity->revision = TRUE;
		node_save($host_entity);
}

However,
1) this created an extra field collection record in the database, and
2) it does messy things when selecting more than one field collection :
- all field collection ids of the saved node are incremented
- if the modification is on the same node, only the first fc is updated, the others stay and have their replacement as additional fcs
- if the modification is on multiple nodes, with only one change per node, it is ok (apart the fc increment).

Thanks for help

πŸ’¬ Support request
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡«πŸ‡·France jvieille

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024