0

In D7 I have two new node type defined e.g. branch and leaf. The branch is a collection of leaves that I'm referring to using the entity_reference module. In the picture below the leaves are the nodes representing the colors. The leaves could be re-used in several branches.

Here is a picture of my collection enter image description here

I would like to add for each of the referenced leaves, two checkboxes to add some information about that leaf that is referenced in that branch. I have added on the picture manually the checkboxes. This is what I would like to achieve. Then, programmatically when I read the branch and all its leaves, I want to be able to retrieve the checkboxes value as well. Everything is working far, I just need to know how to add the leaves, so that at edit time when I edit a branch I can tick the checkboxes as needed.

How could I do that? If there is no module that exists, which hooks should I use for adding this fields to the referred leaf node in the branch? I do not want to add new fields for the leaf node type, I need the new fields/chekboxes to be added to a branch for each leaf thus at the moment of referring to the leaf and for each leaf.

0

One of the ways to solve it is to use the Paragraphs module.

How to start with Paragraphs for Drupal 7

It's basically entity reference fields with layers.

You create a Paragraph field as a container for each data set, then within paragraph create fields for color and lists (checkboxes).

BTW why not upgrade to D8? D8 supports this type of structure better.

3
  • Thank you very much prkos. – MMT Mar 3 at 20:28
  • I have many books, I will need to migrate them all. I also use the books in several ways, and I would need to change that part as well. It's doable, but it's more work. What I need it's more an extension of the entity_reference, but I do not know which hooks and where to start. In the database eventually this would be one more field in the table dr_field_data_field_ref_wordcard. SQL wise it's quite easy, but I do not know how to do it the correct Drupal way, so that I can enter the data properly via the UI. I'm also interested in the D8 solution. Is what I need available in D8 core? – MMT Mar 3 at 20:38
  • D8 supports "fields for fields" structure although with Paragraphs module available in both maybe it won't be too difficult to upgrade. But if you're building something now you should definitely do it with D8 or even D9 because once you're on that track you won't have do data migration between versions, ever! If you build it in D7 you will have to do one final migration from D7 to D8. It does seem that Paragraphs is the module for you. In D7 there were Field collections. In Paragraphs you create one called Color set, then 3 fields within it, color (your existing one), checkbox1, checkbox2. – prkos Mar 4 at 9:34

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.