I have an install with a lot of references (lists of referenced content), and it is quite slow to load it as it makes an AJAX call for previewing each rererenced node.

So I tried a workaround by modifying the cck widget nodereference_explorer.widget.settings.inc and embedding the previews at that moment and having the "nodereference-explorer-processed" class the first time so that everything is not loaded through AJAX.

But it doesn't work then because it does not refresh when changing through the explorer...

Any idea ? Could be a code in javascript maybe...

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

gnindl’s picture

Ok, fair point. We can increase the performance here significantly.

It seems like the preview is not notified when the autocomplete widget changes. If you have a look at explorer.preview.js you will see on line 31:

$(widget).blur(function(event) {....}

That's the critical part where the preview is notified. I think you just have to separate this event handler from the initial page load, i. e. sourrounding each() function. Additionally you have to make sure that the blur event is only attached once and not multiple times

This should be a fairly easy fix, patches are warmly welcomed.

gnindl’s picture

Status: Active » Needs review
FileSize
5.82 KB

@eme: I think you were pretty close to the solution, except that you have to trigger the JS behaviors. Setting the class "nodereference-explorer-processed" server side prevents the widget blur event to be attached, i. e. no update on change.

I propose the following changes:

1. Extend nodereference_explorer_widget_preview() to load the preview server-side. NOTE: We need an additional $field argument here
2. Don't issue the AHAH request on first load, e. g. remove $(widget).blur(). This is done server-side now.
3. There was additionally a bug CCK links fields, not loading the preview at all.

eme’s picture

Well, it works pretty well for now, even with unlimited (correct loading without ajax of course). Will do some more testing but I think it's fine. Thx.

eme’s picture

Status: Needs review » Needs work

I spotted a bug (did not try for now to dig into it) : if you have an unlimited field and you try to add more than one entry, the preview disappears. I tried previously adding just one, and it works.

[edit] : seems that $element['#default_value']['nid']['nid'] has the strange value [nid:Array]

eme’s picture

With a dsm of $element in nodereference_explorer_widget_preview we do not have any value but this damn [nid:Array]. But we have the correct value of course in ['#post']...

example :

  $field_name = $field['field_name'];
  $weight = $element['#delta'];
  if($element['#post'][$field_name][$weight]['nid'])
	$nid = $element['#post'][$field_name][$weight]['nid'];
  else
	$nid = $element['#default_value']['nid'];

Then it works fine if sending $nid to your handler because we fetch the element in the POST values.

gnindl’s picture

I suppose you click the "Add another item" button?

eme’s picture

Exactly. Once it works, more than once the preview disappears on my install.

gnindl’s picture

Referring to #comment 5:
On my local instance the $element['#post'] array is empty. So I don't think we can rely on these values as other (CCK) modules might alter them. Instead I'd recommend to use the global $_POST array instead.

eme’s picture

Do you get the same behaviour on your install ?

eme’s picture

Status: Needs work » Needs review
FileSize
6.01 KB

Then if using $_POST, we have a patch like the following one...

gnindl’s picture

Finally, it was a bit more difficult than expected because link module support was broken.

I took your patch from comment 10 and modified it a little bit:
- I moved the code snippet from comment 5 of function nodereference_explorer_widget_preview() into the plugin super class nodereference_explorer_plugin_content, so that all plugin retrieve the modified widget values. There's a fall back from $element['#post'] to $_POST array (see code comments)
- Some tweaks in nodereference_explorer_plugin_content_link.inc, function widget_process. Preview support was broken for link module
- Refactoring of a new utility function: nodereference_explorer_util_parse_widget_value()
- Some PHP compatibility fixes, e. g. preg_split() instead of split()

gnindl’s picture

Status: Needs review » Fixed

Patch from #11 has been tested and committed to the repository, @see http://drupalcode.org/project/nodereference_explorer.git/commit/20ef44f

Status: Fixed » Closed (fixed)

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