This is a biggie. I'd like to be able to prepopulate node EDIT forms as well. For example, I'm currently making a sort of curated gallery node that contains entity references to entities of type "gallery_item." I'd like to be able to do this:
- A user is looking at a "gallery_item" entity
- She clicks a link from that entity that takes her to a page that says "Which gallery would you like to add this item to?" with a list of existing gallery nodes.
- She clicks one of the links, and it takes her to the node edit form of that gallery, with the gallery_item's entity ID in the URL, prepopulating the multi-value entity reference field in the edit form. (Important: this should not cause problems with existing entity references! i.e., the node's existing entity references should appear in the edit form, and the entities passed in via the URL should be ADDED to them if the entity reference field is multi-value.)
What happens now is that the entity ID's passed in via the URL are completely ignored in an edit form.
Thanks!
Comments
Comment #1
rogical commentedNeeds the same!
Comment #2
rbruhn commentedI am needing this same functionality too. In looking at the code, it appears this module adds a default_value_function to the instance of the field on which you want this behavior. The default_value_function is called within field.form.inc function field_default_form():
At this point, a node being edited might already have values for $items and the $id. So the default_value_function will never be called.
It seems like adding url values to a entity reference field would need to be handled in a form alter function inside a module. I've been playing around with it most of the day, but damn it's a bit difficult. It would be nice to intercept the data for the form build, check for the existing url values, and add them to the data before the form is built and displayed. If anyone has ideas on how to do that, I'd be interested in hearing them.
Comment #3
rbruhn commentedFor others who may look here, I ended up simply using hook_node_load() to add what I needed.
This simply adds the url values to the entity reference field before the form is displayed so everything is taken care of. Of course, if you are using hook_node_load() for other things, your code would exit differently.
Comment #4
johankasperi commentedThanks rbruhn! Really needed that code of yours :) But I also need something similar for User edit, and I don't have the skillset to write it on my own. Can you help? Thanks in advance!
Comment #5
rbruhn commented@Kasberry
Just came back to look at this. It depends on what you are trying to do in the User edit. If you can explain, perhaps I can lend a hand.
Comment #6
johankasperi commented@rbruhn The request I posted a few days ago is no longer needed since we found an other solution to our problem. Thanks anyhow!
Comment #7
jan-e commentedI came here looking for a way to change an existing entity reference, not to add one to an existing multi-value entity reference field. If I skip the multi, I ended up using the prepopulate module in stead of the entity reference prepopulate module. My my_entity_reference_field was in a select list and I used this to populate it with the desired value:
/node/xxx/edit?edit[my_entity_reference_field][und]=my_entity_id
I found the solution here: http://drupal.org/node/1772148
For the multi case something like this might be worth a try:
/node/xxx/edit?edit[my_entity_reference_field][und][]=my_entity_id
Comment #8
windmaomao commentedneed this one as well, pump
Comment #9
nwom commentedThis functionality exists in the current dev version of the module (not sure about the stable). The only exception, is when using this in combination with the Entity Reference Prepopulate Token module. That would have to be patched in the Entity Reference Prepopulate Token module though.
Comment #10
lunk rat commentedOn the latest dev, visiting
/node/1/edit?field_foo=2does not prepopulate the entity reference field_fooIs there any other config I should be aware of?
Comment #11
ludwig.rubio commented#3 works perfectly!, thanks!