I have a content type book and another content type pages. A page has a entity reference field to book. Now, I want to allow users to create pages on the same page as book. So, I created a page add form using formblock module.

I would like to have the entity reference field auto generated and pointing to the book.

Is it possible? Thanks. :)

  • I am using form block and entity reference prepopulate. But , have not been successful so far. – Nick Dave Sep 10 '12 at 17:27

Node Reference URL Widget can help you :)

  • Didn't work with nodeform block. Looks like, I will have to make form block myself. – Nick Dave Sep 11 '12 at 9:14
  • If you're using Entity Reference (instead of Node Reference) you should use, entity reference prepopulate, drupal.org/project/entityreference_prepopulate – tsega May 13 '14 at 12:50

I have answered this question already on another question. Here is the full answer i provided there:

For the benefit of those who encounter this same problem without a solution, this module: Entity Reference Prepopulate Token will provide a perfect solution. Please make sure you are using the latest dev version of Entity Reference Prepopulate module (as at 2015-Jun-10 or higher).

After enabling the module, go to the content type edit page and scroll down to where you have "Provider" and enter the following comma separated values in the text box provided under "Tokens and panel pane context":

%node:nid, [current-page:url:unaliased:args:value:1]

Just enter the above values in the box and select the optional checkbox for this provider option to activate it, hide the field from the user also if desired, to avoid editing. I've tested it, It works!

According to the module page:

This module supplements Entityreference prepopulate module (dev version is required) by adding prepopulate provider which sets default field values using tokens and replacement patterns of panel pane contexts.

Two kind of patterns can be used for prepopulating entity reference fields:

Tokens, e.g [current-page:url:unaliased:args:value:1] (it returns value "100" for address "node/100", Token module is required). Replacement patterns of panel pane contexts, e.g. %node:nid (it returns node identifier if the form containing entity reference field is placed on node view page created by Page manager). Panels module is required for using these patterns.

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.