Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
    
if your the person who wrote this issues, drupal.org/node/1891588 then i think i'd look for a hook in the module to find the parent ... –  tenken Jan 17 '13 at 23:33
    
have you looked at the drupal.org/project/relation module –  Mohammed Shameem Jan 18 '13 at 6:04
    
No, I have not. But I would like to stick with references. Bojans provided this code here drupal.org/node/1891572 but I cannot get it to work. –  hoff331 Jan 22 '13 at 22:59
    
thought it would work using project/ref_field, but doesn't... drupal.org/project/ref_field –  Frank Pfabigan Apr 19 '13 at 15:21

1 Answer 1

up vote 2 down vote accepted

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" ]
        }
      }
    ]
  }
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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