1

Here is the example:

'Parent' Content Type = Author

  • field1: Name
  • field2: Age
  • field3: Picture
  • field4: Entity Reference to Books (inline entity form widget)

'Child' Content Type = Books

  • field1: Title
  • field2: Description
  • field3: Entity Reference to Author using prepopulate (need help)

Author has entity reference to Books using Inline Entity Form. So when creating an "Author", we can add "Books" they have written inline.

When a user visits an individual "Book" page, I want a field that links back to the "Author" who wrote it. How can I create this link automatically when creating a "Book" inline?

I assume I have to create a Book field3 that is an Entity Reference to Author that uses prepopulate. But I have not been able to configure this correctly to get it working as wanted. Any ideas?

4

1 Answer 1

2

This has been acheived using Rules:

Export of Rule:

{
        "rules_ifs_backlink_populator" : {
        "LABEL" : "IFS backlink populator",
        "PLUGIN" : "reaction rule",
        "ACTIVE" : false,
        "REQUIRES" : [ "rules" ],
        "ON" : [ "node_insert", "node_update" ],
        "IF" : [
          { "node_is_of_type" : {
              "node" : [ "node" ],
              "type" : { "value" : {
                  "auction" : "auction",
                  "estate_sale" : "estate_sale",
                  "garage_sale" : "garage_sale"
                }
              }
            }
          }
        ],
        "DO" : [
          { "LOOP" : {
              "USING" : { "list" : [ "node:field-ifs-add" ] },
              "ITEM" : { "list_item" : "Current list item" },
              "DO" : [
                { "component_rules_create_entity_reference_back_link_" : { "child_param" : [ "list-item" ], "parent_param" : [ "node" ] } }
              ]
            }
          }
        ]
      }
    }

Export of Component:

{ "rules_create_entity_reference_back_link_" : {
    "LABEL" : "create entity reference back link ",
    "PLUGIN" : "rule",
    "REQUIRES" : [ "rules" ],
    "USES VARIABLES" : {
      "child_param" : { "label" : "Child Parameter", "type" : "node" },
      "parent_param" : { "label" : "Parent Parameter", "type" : "node" }
    },
    "IF" : [
      { "AND" : [
          { "node_is_of_type" : { "node" : [ "child-param" ], "type" : { "value" : { "ifs" : "ifs" } } } },
          { "entity_has_field" : { "entity" : [ "child-param" ], "field" : "field_auction_ref" } },
          { "data_is_empty" : { "data" : [ "child-param:field-auction-ref" ] } }
        ]
      }
    ],
    "DO" : [
      { "data_set" : {
          "data" : [ "child-param:field-auction-ref" ],
          "value" : [ "parent-param" ]
        }
      }
    ]
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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