So, I have a need for nodereference in a site I'm working on (http://www.disobey.com/node/1864) and, naturally, there's no node reference module that currently exists for D7, save CCKs. And, honestly, most of the other node reference modules go a little overboard for me, so I'm trying to shoehorn my needs into nodereference for d7, and running up against two problems:

  • node_reference_autocomplete_validate() is too evil. In my particular case, I need to create a node if the typed title doesn't exist. However, as _validate() is written now, there's no way I can do this, even with a form_alter: my user will always get a nasty error message. So, I'm wondering if there's anyway we could get some extra hook at this level, which allows other modules to determine the $reference. Perhaps this already exists: can I somehow detect the query in _node_reference_potential_references_standard(), check to see if there were any results and, if none, quickly create a node and return that as a reference? If that's not an option, some sort of drupal_alter() hook on $reference would be great!
  • The other major problem is the UI - I don't want one input box per reference. In my use case, my nodes are all people: Morbus Iff, John Doe, Jane Doe, etc. I don't want to have to type that in, tab, type another in, tab, type another in, tab, etc., nor do I want the inputs cluttering up the form UI (or forcing me to type, click "Add another field", type again, etc.). Ideally, I'm looking for a taxonomy like field, where one could type in ["Morbus Iff, Jr.", John Doe, "Microsoft, LLC"], have three separate node titles looked for, and/or (per the bullet above) created, then returned.

Any thoughts on how I could accomplish the above?

Comments

morbus iff’s picture

Maybe for the first option, above, I just need to form_alter myself into #validate before NR? Alternatively, it seems if I defined my own widget for nodereference fields, I might be able to define the validation there too? I *really* don't want to duplicate all of noderef code solely for (empty) createable nodes and a slightly different widget.

(Though, this might all be moot cos it doesn't seem to be working in current D7 core HEAD anyways.)

yched’s picture

Note that CCK HEAD now has a working version of noderef field - #533222: node and user reference fields in D7 - maintainer needed, cheers to fgm.

- node_reference_autocomplete_validate(): could this be done through form_alter ?
- sounds very similar to the autocomplete widget implemented by taxo fields. Depending on whether someone submits a patch, this could be a new noderef widget, or live as a custom widget in a separate module.

morbus iff’s picture

(yched: yeah, I had read that issue prior to installing it, and saw that it was working. Grabbed HEAD, added node ref field no problem, the autocomplete added no problem, but it always returned with a validation error, saying that the referenced node didn't exist.)

As for the new noderef widget, what would be an estimate for you to build it, and me to pay for it?

litwol’s picture

subscribing.

johnpitcairn’s picture

Subscribing. I'm looking for a way to override the validation that nodereference does in the hook_field "validate" op, via _nodereference_potential_references_views(), specifically to get rid of the "this post can't be referenced" error.

fgm’s picture

Project: Content Construction Kit (CCK) » References
Version: 7.x-2.x-dev » 7.x-1.x-dev
Component: nodereference.module » Code

nodereference and userreference for Drupal 7.x are now maintained separately in the References module: moving issue over there.

fgm’s picture

Component: Code » Code: node_reference

Categorizing.

danielb’s picture

A solution for the validate issue may be to modify the function _node_reference_potential_references(), and add a drupal_alter() either for the $references variable, or to the whole $result (I'm not sure which is the best way to go).
Not only would this allow a node to be created if it doesn't exist, but could also allow other modules to provide ways to fetch additional nodes that are not handled by this module's standard/views implementations of selecting nodes.

This would also apply to the User reference module.

candelas’s picture

Version: 7.x-1.x-dev » 7.x-2.x-dev

subscribing

alex andrascu’s picture

This looks like quite an old thread but please feel free to submit a patch.