Since it only uses what content types can be reference, it displays link on every item of the content type instead of just the ones that can be referenced (so since fallback is working, it throws a 404 when someone clicks).

Would be nice if it checks the NID is valid option like the fallback does. ( inside the hook_link around line 60[ might be off since I have some other stuff in there too.])

          if (!empty($field['referenceable_types'][$object->type]) && user_access('create ' . $target_type . ' content')) {
+            $valid_options = optionwidgets_options($instance);
+            if (!isset($valid_options[$object->nid])) continue;

I put if after the initial check cause the optionwidgets_options

Comments

quicksketch’s picture

Thanks, I've been aware of this problem but I wanted to make sure to implement it in a reasonably efficient manner. Considering optionwidget_options() might return a list of thousands and thousands of results, this probably won't be suitable to do when displaying every single piece of content.

hefox’s picture

ah right! :/

Hm, This may be faster:
Add a nid filter for that nid to the view and see if there's a view. haven't checked to see if there's any cache issues

same place as last time

<?

if ($instance['advanced_view']) {
if ($instance['advanced_view_args']){
$view_args = array_map('trim', explode(',', $instance['advanced_view_args']));
} else $view_args = array();
if (!node_reference_url_checknid($instance['advanced_view'],$view_args,$object->nid)) continue;
}
?>
with that new function being (partially copied from http://drupal.org/node/342132.):


function node_reference_url_checknid($viewname, $args = NULL, $nid) {
  $view = views_get_view($viewname);
  if (is_object($view)) {
	$view->add_item('default', 'filter', 'node', 'nid', array('value'=>array('value'=>$nid),'operator' => '='));
    if (is_array($args)) {
      $view->set_arguments($args);
    }
    $view->is_cacheable = FALSE;
    $view->init_display();
    $view->pre_execute();
    $view->execute();
    return !empty($view->result);
  }
}
hefox’s picture

(Since this is basically the advanced views issue and I'm really not certain if this is a bug or not.. but there's an semi amusing issue that one cannot edit a node that has a nodereference_url set to a nid that can no longer be referenced by the advanced view since it's no longer in the option array. [I have a advanced view that only contains nodes that haven't been referenced].
In my verision I added a check on $form['#node']->($field['field_name'])[0]['nid'] and let it pass if set. )

hefox’s picture

StatusFileSize
new8 KB

(Ignore the above, neither does regular node reference support editing that which then has an invalid node references, which is really sorta amusing since combining it with node reference makes the entire node uneditable since can't change the node reference without changing the view *lol*).

Suggestion to create a function with whatever code to check you end up going with into one function (that perhaps take in $field,$node/$nid). Useful later say if say, wanting to add a views field handler in.

(I suggest ignoring the attached patch, it's svn diffed from a already checked in version with the previous mentioned function and several other changes... and includes a basic views create link field. Also, I suspect $target_type is redundant and already in the $fiield array. And i've been rather fruitless in finding a good, free, windows php ide with ftp.. aka tons of tabs instead of spaces. etc.).

quicksketch’s picture

Status: Active » Fixed
StatusFileSize
new1.81 KB

I've committed this patch that adds this functionality. It's not ideal since we call a private function of Node Reference module, _nodereference_potential_references_views, but it allows us to use the exact same mechanism as Node Reference module, and it reduces the need down to one query per node, which is as efficient as I think it's possible to be while avoiding extremely large result sets.

Status: Fixed » Closed (fixed)

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