1

Firstly is it possible to attach a single field collection to multiple nodes (so when you opened each node, you'd see the same field collection. If you altered one, they'd all change.)

And secondly, if the answer to the first question is yes, how would you go about doing this? Has anyone ever tried this before?

I've been looking through the database tables and it seems like there's no reason you couldn't just point multiple nodes to one fc, however I can't find anything on the topic.

Brief Example

A quick use case to clarify Geoff's question:

When I create node b, I have the option to populate a field collection from node a rather than a blank field collection.

Editing the field collection on node a, would then also change the value in b.

  • 1
    do you mean having static data within the field collection (a single field collection whose data is shared across nodes of the same content type)? or sharing a field collection across content types with differing data? the first could be done with a custom module, the second is already built in to Drupal – Geoff Jun 4 '15 at 2:19
  • @Geoff The first. I've added an example use case to question to try and add some more clarity to the question! – Dominic Woodman Jun 4 '15 at 11:43
  • Have you already created this data structure? If not, then you probably shouldn't use a field collection. It sounds like the data should be a separate content type that you then connect to the parent nodes with an Entity Reference. – RoloDMonkey Jun 4 '15 at 14:26
0

You have to write custom module for this and use hook_node_presave($node) to save fieldcollection value of other node into this and save node.

Then check your DB, now single fc attached to other node(s).

0

I would start it this way:

  • install Entity Reference to create a reference in B to A
  • create a reference field in B to let the user choose which node they want to reference, and then use some AJAX to do the initial populate of the field elements based on their selection

This will save B as normal but provide the connection between the two

  • create a hook_form_alter for node B, such that if a reference exists, load the referencing node and populate the fields in node B with the values from node A

This would allow any node to reference any other node (of the same content type) for value mirroring. This approach is passive, in that it requires node B to be viewed before the values are updated - this behaviour could be changed on the node A save to update the field values in all referencing nodes

If you wanted it to go the other way or be more communal, whereby any node could be manually changed and affect all the other nodes (changing node B also changes node A), it would be a little different, but this is the general idea I would use based on your question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.