Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi, I have a nodeformblock that uses a nodereference field,
by using node reference url widget I can pass an argument to the node/add/ page,
but it doesnot seem to work via panels,
any help
regard sduncan
Comment | File | Size | Author |
---|---|---|---|
#7 | nr_empty.png | 15.57 KB | ranavaibhav |
Comments
Comment #1
mikey_p CreditAttribution: mikey_p commentedThere really isn't any way to do this, as blocks don't accept arguments. Perhaps you could use a hook_form_alter to achieve the result you are looking for?
Comment #2
mikey_p CreditAttribution: mikey_p commentedComment #3
pnigro CreditAttribution: pnigro commentedI accomplished populating a node reference using hook_form_alter in a custom module. The tricky part is that cck fields are accessible in after_build as opposed to hook_form_alter. I believe this is because the cck fields are added after the form is built. I created the following module using the following references:
Populate CCK Node Reference Field and hide it - is this the cleanest way
hook_form_alter() and CCK fields
FAPI/CCK Confusion: 'value' vs '#value'
I hope this helps someone.
Comment #4
ryanilg CreditAttribution: ryanilg commentedAnd... you just saved me a bunch of work. I was planning on doing this exact same thing on a project I am currently working on.
Thanks!
Comment #5
pnigro CreditAttribution: pnigro commentedYou're welcome. Glad I could help :-)
Comment #6
ranavaibhavHello Paul,
Thanks for the code. I created a custom module with your code and enabled it. It works however the title is printed just below the Node Reference field instead of inside the filed. Am i doing anything wrong here? Please guide. Thanks.
Comment #7
ranavaibhavsorry, the screenshot for the issue i mentioned in my last comment.
Comment #8
pnigro CreditAttribution: pnigro commentedHello Jackie,
I had the same problem when I was creating the module. I think the problem is that
$form['field_cck_field_name'][0]['nid']['nid']['#value']
or[0]['nid']['nid']['#value']
is not correct for your setup. If you install the Devel module you can find out what this form field should be by typing dsm($form); in the #after_build stage. This will show you the node object in a tree structure. Click the node reference field and look for #value. There may be several so you will have to do some trial and error to find the correct one. Remember that each level you go down you have to add it to the end of$form['field_cck_field_name']
If I were you I would first try$form['field_cck_field_name'][0]['nid']['#value']
I hope this helps.Comment #9
ranavaibhavHello Paul,
Thank you for your quick response.
I found that my setup did not like [0] in the code. I guess it's because i have setup field for single value only.
After changing
$form['field_cck_field_name'][0]['nid']['nid']['#value']
to
$form['field_cck_field_name']['nid']['nid']['#value']
it start working..
Thank you so much for your help. I literally spend so many days figuring out how to generate the field value and came across your post..
Comment #10
pnigro CreditAttribution: pnigro commentedYou are very welcome. I am glad I could contribute to the Drupal Community.
Comment #11
konordo CreditAttribution: konordo commentedThanks for the code, very helpful.
This is what worked for me, for a user reference field. Form is displayed in a tab, in user/* pages:
Comment #12
itserich CreditAttribution: itserich commentedThanks for this.
I have forms in a node panel and want to relate the form to the original node.
Node Reference URL Widget also appears to offer a solution.
http://drupal.org/node/1008212
Comment #13
smartsystems160 CreditAttribution: smartsystems160 commentedFor the benefit of those using Entity Reference module, this module Entity Reference Prepopulate Token will do this for you on panels.
Comment #14
mikey_p CreditAttribution: mikey_p commentedI haven't seen much interest in this issue in awhile, and it's filed against 6.x which is unsupported, so I'm closing this issue for now.