Adding an edit link to an autocomplete node reference field.

Events happening in the community are now at Drupal community events on www.drupal.org.
jmather's picture

I was hoping someone could point me in the right direction to add an "edit" link to a cck node reference field.

In this case the references are autocomplete fields and I want to add and "edit" link that would point to i.e. http://www.mysite.com/node/4/edit

I will probably use the popup api to make the link open as a popup. What I'm having trouble with is figuring out how to hook into the autocomplete textfield element.

I see it is rendered and can be modified out of nodereference_autocomplete_process and I can add for example a 'suffix' value and that will append the value I'm looking for, so how do I do that and filter down the elments so it is just the ones I want? (sorry if this is slightly out of the scope of cck group)...

I can find the suffix field on most "normal" field types, but the cck node reference elements do not seem to have them....any help would be appreciated (or if someone has already done this if they could point me to somewhere to get more info)

Thx...

JM

Comments

Example in Node Relationships module

markus_petrux's picture

It provides several features for noderefs using the autocomplete widget:

  • Search and reference (single and multiple value selections supported).
  • Create and reference.
  • View referenced node on new window (it appears whenever any of the previous option is enabled).

While the first two features open a modal dialog (based on Modal Frame API), the later opens on a new window, and there you can edit the referenced node.

http://drupal.org/project/noderelationships

If this module does not cover your needs, then you may want to look at how it is done. It's a bit tricky to do it properly because the autocomplete widget in noderefs is not available during hook_form_alter(), so you need to inject an after_build callback which is processed when all form elements are expanded, and there you can scan the form for noderefs using autocomplete widgets (that may be located on several levels in the form) and then modify the form element with stuff that can be used later during the rendering phase of the form.

In Node Relationships module, this is done in function _noderelationships_parent_node_form_alter(), located in file noderelationships.pages.inc. Here I'm adding CSS classes, then the previously mentioned features are implemented via javascript behaviors that look for those classes.

Hope that helps

Thanks...

jmather's picture

That is the info I'm looking for. I will try out the noderelationships and see if that will work for me and also inspect the code. I'm glad you pointed out that the autocomplete widget is not available in the hook_form_alter, that was driving me nuts.

  • JM

Markus, Thanx for the

zilverdistel's picture

Markus,

Thanx for the explanation, I'll try it out. It's a pitty that noderelationships depends on modalframe and jquery ui 1.7, otherwise I'd use it.

Content Construction Kit (CCK)

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: