Hello,

Is it possible to use arguments with the noderef view so I can restrict the results automatically (instead of manually with exposed filters) ?
Right now, when I activate an argument in the view UI the preview works, but I have no results when I use the "search and reference" buttons.

My goal is to use the field values as arguments from the content I'm editing to preselect similar content (from another content type but with the same fields) in the noderef view.

Thank you for any help, this is a great module.

Comments

markus_petrux’s picture

Status: Active » Fixed

You'll have to resolve this particular need using custom code. There are 2 steps:

1) Somehow, you need to alter the links opened in the modal frame adding URL arguments.
See the code in node_form.js. And here you should be able to find your way to alter the links used for each button (see the data structure in Drupal.settings.nodeRelationships), or you could replace the click handlers with your own, so you have 100% control to open the modal frame with the arguments you need.

2) Then you need to parse these arguments server-side and modify the view dynamically.
See: #589136: How to customize noderelationships views in real-time, when these views are executed

ethnovode’s picture

Thank you for taking the time to answer. I'm not sure I'll be able to do this as I am very short on time and my php skills are not as good as I'd like. I still think this is a great module and I'll probably use it on another project.

Status: Fixed » Closed (fixed)

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

tina650’s picture

I believe I may be asking the same thing as ethnovode and so was hesitant to open a new issue.

I too need to limit the search and reference results by adding a noderef argument to the noderelationships_noderef view and Providing a default argument where the Default argument type is the Node ID from URL.

In my real life example, I am asking people to do a search and reference for an existing music venue (like a coffee shop or concert hall) while creating a new music event for a given town (nid is in the url). I would like the search results to be limited to the town and not display all venues in the entire state.

Since I'm a newbie, I'm hoping that I won't have to code as is suggested in http://groups.drupal.org/node/82219 Modify views filters programatically.

Thanks for your consideration!

tina650’s picture

Status: Closed (fixed) » Active

I suppose I should change the status?

markus_petrux’s picture

Status: Active » Postponed (maintainer needs more info)

I'm afraid I do not have enough time for more, you'll have to code to implement your particular use case. Do you have any other particular doubt to get started? The basic idea on how to approach this issue has been described above, or in the thread you've linked to.

tina650’s picture

About getting started, I'm not a developer, which makes this approach a bit intimidating for me right now. But then I wonder if it's not that difficult since there are others that want to do this and may have figured this out pretty easily. For example, someone asked for this in the Q&A part of this session, http://developedbymiche.com/blog/2010/04/18/drupalcon-sf-2010-views-exam....

If you have any helpful tips, I'd appreciate that.

tina650’s picture

As a temporary workaround, I added a relationship to my copy of the noderelationships_noderef view and added the field of the relationship as a filter. It's not elegant nor user-friendly and once there's a lot of data in there, it won't be feasible.

Would you consider adding this as a feature into your next release?

markus_petrux’s picture

fourmi4x’s picture

I also needed this... struggled a few hours... and got it to work!!

1/ Modify the drupal_alter call (inside the function noderelationships_customize_noderef_view) in the noderelationships.inc file:

drupal_alter('noderelationships_view', $view_overrides, $view, $display_id, $view_args);
becomes :
drupal_alter('noderelationships_view', $view_args, $view_overrides, $view, $display_id);
because we need to change $view_args and not $view_overrides.

2/ In a custom module, as described in http://drupal.org/node/589136 (but we are also changing the variables' order of the function to get $view_args returned) :

function c_noderelationships_noderelationships_view_alter(&$view_args, $view_overrides, $view, $display_id) {
  switch ($view->tag) {
    case NODERELATIONSHIPS_BACKREF_VIEW_TAG:
      break;
    case NODERELATIONSHIPS_NODEREF_VIEW_TAG:
	$view_args[2] = $_GET['feat_t']; // we get the desired value via a GET for instance
break;
  }
}
?> 

So we get the new argument via the URL.

3/ You have to create two Global: Null arguments in your noderelationships_noderef view, before the third argument you want to pass (because two arguments are created by the noderelationships module, even if you can't view it on the view UI, hence the [2]). So the value you put in $view_args[2] will match the third argument of your view. With this technique, you can even apply relationships to your argument. This brings even more magic to the module :)

Hope that helps!

NB: I didn't manage to do this without hacking a core module file (noderelationships.inc) - Is there a way to avoid that?

markus_petrux’s picture

You could also try using a hook provided by Views itself. See the file docs.php under the docs subdirectory of the Views package.

fourmi4x’s picture

Thanks for this guideline, I'll dig into the views documentation, a thing I should have done earlier...