This issue is a spin of from #533222: node and user reference fields in D7 - maintainer needed. The bulk of noderef module has already been ported to D7, this issue if for followup tasks.

Comments

yched’s picture

FYI: I just committed an update of the noderef formatters after #652834: Field formatters as render arrays.
Not actually tested :-p.
Additional adjustments will be needed if / when #657828: Make hook_field_formatter() act on all field values lands.

I'd notably welcome anyone testing that the logic to prevent infinite recursion with 'display full node' formatter works fine:
1 references 2,
2 references 3,
3 references 1.

When useref is ported too, we'll need to also ensure 'cross entity types' cycles:
node 1 references user 1,
user 1 references user 2,
user 2 references node 1
Which means 'display actual object' formatters for userref / noderef / entityref fields need to cooperate somehow, probably by sharing the recursion queue. Interesting ;-)

fgm’s picture

Status: Active » Needs review
StatusFileSize
new903 bytes

Slight misuse of DBTNG: fetchField works on a query result, not on the query object.

yched’s picture

Status: Needs review » Active

Right. Committed an update after #657828: Make hook_field_formatter() act on all field values, and that part got heavily refactored anyway ;-).

The 'display as full/teaser node' formatters and the infinite loop protection seem to work OK.

Only problem: the node template doesn't display the node title.
That's a core bug, template_preprocessor_node() does $variables['page'] = (bool)menu_get_object();, that's not specific enough.

yched’s picture

yched’s picture

Core bug in #3 should be fixed now.

morbus iff’s picture

Looks like noderef autocomplete is broken again:

* Autocomplete text widget doesn't work; no widget is displayed. Other widgets work fine.
* Switching to another widget, and saving the node, shows nothing displayed on node view.

fgm’s picture

Yes, it briefly worked after #2 and no longer at #3.

morbus iff’s picture

Status: Active » Reviewed & tested by the community
StatusFileSize
new4.74 KB

Yeah, this was broken by #658364. It's a simple tweak to get the above two things working again. Attached. RTBC.

morbus iff’s picture

There's still something wrong with saving values through taxonomy autocomplete, which I'm trying to debug.

a) Create a node. Make sure it has a double digits for nids (i.e. 31 in my test case).
---(This bug is NOT reproducible if your referenced node is a single digit.)
b) Create a node that node refs this. The autocomplete works properly (shows [nid:31]).
c) Save the node. The value stored in the database is "3", and the #default_value on edits shows " [nid:Array]".

More info:

* If your referenced node is nid 31, then make sure that nid 3 exists. If node 3 doesn't exist, then I can't reproduce the error.
* But, if you make a referenced node to 31, and then try to make ANOTHER node and reference 31 AGAIN, it fails (??).

yched’s picture

Committed #8.

Bug in #9 looks like something wrong in node_reference_autocomplete_value(). That function could probably use a closer look, it doesn't really look like other form_type_*_value() value callbacks in core's form.inc.
No time for this tonight, unfortunately.

morbus iff’s picture

Status: Reviewed & tested by the community » Active
morbus iff’s picture

Regarding #9 and #11, the first thing I noticed is:

$nid = $element['#default_value'];

but comes from node_reference_field_widget_form's $items['delta']. But the value of that is an array('nid' => 123), not just 123. So it seems, here, that $nid would be set to array('nid' => 123) and not 123. Switchiing to $element['#default_value']['nid'] didn't seem to help.

This function also, oddly, seems to prevent me from ever editing a nodereference, since the #default_value from a node's edit form will always be set, so we don't ever return anything but NULL?

dave reid’s picture

Issue tags: +D7 porting

Adding D7 porting tag...

litwol’s picture

sub

yched’s picture

I committed a fix that should let the autocomplete widget work as expected now.
@Morbus iff: can you confirm it works for you (including with 2 digit nids :-p) ?

morbus iff’s picture

Seems to work, yeah - editing an existing noderef works, and it distinguishes between nids 1 and 11.

BenK’s picture

Subscribing...

jherencia’s picture

Subscribing...

pasqualle’s picture

Status: Active » Needs review
StatusFileSize
new2.36 KB

minor code style changes
and nodereference_field_widget_error function name fix

yched’s picture

Status: Needs review » Fixed

Committed #21 (with an additional fix for the new syntax for template suggestions).
Thanks !

Status: Fixed » Closed (fixed)
Issue tags: -D7 porting

Automatically closed -- issue fixed for 2 weeks with no activity.