1

I have 2 content types named Incident and Migrant. Both of them have fields that reference each other. My question is how to prepopulate a field in a reference dialog box while the node is being edited?

enter image description here

How am I going to prepopulate Incident field with Incident 36 nid. When the popup/dialog loads? Assuming that Incident field is a Autocomplete Text Field?

Here's what I tried, I have tried Entity Reference Prepopulate but, I figured that that the Reference Dialog is displayed via iframe so getting the nid from the URL wont work.

I'm very new to drupal and still in the learning curve so if possible answer me in a detailed fashion.

Modules i used

Entityreference prepopulate Reference Dialog

1 Answer 1

0

Yes, you can. What you need for this? 1) references_dialog 2) entityreference_prepopulate 3) your custom_module. For example field that you want to make with prepopulated field in url is entityreference. Here is link to youtube how to use entityreference_prepopulate and URL https://www.youtube.com/watch?v=z9C4Uf6euLY.

After this you should override your "Create ..." link. How to do this? Easy. Just implement hook_references_dialog_widgets_alter in your custom module and change name of function that generate add link

/**
 * Implements hook_references_dialog_widgets()
 */
function mymodule_references_dialog_widgets_alter(&$widgets) {
  $widgets['entityreference_autocomplete']['operations']['add']['function']
    = 'mymodule_references_dialog_entityreference_add_link';
}

And than you can define your add link function:

function mymodule_references_dialog_entityreference_add_link($element, $widget_settings, $field, $instance) {
// blah blah from original function
// Here you can catch field what you need and define url with $_GET parameters for it.
}

That's all. Enjoy reference dialog with get params in url.

Your Answer

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

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