Hi Markus -

I've successfully done all described in #699104: Using Arguments with search and reference view...as far as I can.

I've successfully altered the urls in Drupal.settings.nodeRelationships, and added the hook as described in #589136: How to customize noderelationships views in real-time, when these views are executed, but it was not working as expected.

So, I added hook_views_pre_view() and several other views hooks, dumping the view to screen at various points to see if the changes in hook_noderelationships_view_alter() were taking effect.

When adding a filter in hook_noderelationships_view_alter, the filter I'm adding shows up, but then info dumped from views hooks show that it's no longer set.

If I move the same $view->display_handler->override_option call into hook_views_pre_view, the changes stick and are not overwritten, so I'm going with that for now...but is there any reason you can think of why this might be happening?

Thanks for your hard work - it's a great set of tools that you've contributed!

Comments

markus_petrux’s picture

hmm... if the Node Relationships module is able to apply changes to the view, your changes should also be able to persist.

...maybe it is the method used to alter the filters of the view? Could you please post the code of your implementation of hook_noderelationships_view_alter()?

Note that N.R. expects you to alter the $view_overrides array. If you are altering the view directly, your changes will be overridden by N.R. when it alters the view with the content of the $view_overrides array after all implementations of hook_noderelationships_view_alter() have been processed.

Maybe there is another module that is altering the $view_overrides array? In this case, you may need to use a higher weight for your module (weight column in {system} table), or maybe it is a bug in that particular module that alters the array destroying existing data.

markus_petrux’s picture

Status: Active » Postponed (maintainer needs more info)
dsayswhat’s picture

Yep. I'm so overconfident in myself that I missed this:

/**
* Implementation of hook_noderelationships_view_alter().
*
* This hook allows you to alter the array of custom overrides that are
* applied to noderelationship views in real-time.
**/

Would a blinking neon sign that warns people like me not to treat this like a normal views hook be appropriate? Probably can't do it, since blink isn't one of the allowed html tags. Maybe a header instead.

Warning

You cannot successfully call $view->display_handler->override_option inside hook_noderelationships_view_alter(). It will silently fail to have any effect on the view.

The function signature for hook_noderelationships_view_alter() is:

hook_noderelationships_view_alter(&$view_overrides, $view, $display_id, $view_args)()

Notice that $view_overrides is passed by reference, $view is not. Any alterations to $view WILL NOT be retained.

Therefore, add your filter or other view overrides to the $view_overrides array, where it will persist and be added to the view by the noderelationships module at the proper time.

Thanks for the clarification, Markus.

PS - does this mean that other view overrides to noderelationships-provided views might also fail, if someone tries to alter the view outside of your hook?

markus_petrux’s picture

Category: bug » support
Status: Postponed (maintainer needs more info) » Fixed

lol, no problem. This kind of things happen. ;)

Re: "PS - does this mean that other view overrides to noderelationships-provided views might also fail, if someone tries to alter the view outside of your hook?"

Well, you can still implement any Views hook, though you should take into account what N.R. does. You may need to play with module weights to resolve conflicts.

PS: Changing issue status, it was not a bug after all.

Status: Fixed » Closed (fixed)

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