Closed (won't fix)
Project:
Views (for Drupal 7)
Version:
5.x-1.5
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
14 Apr 2007 at 02:04 UTC
Updated:
17 Sep 2008 at 22:28 UTC
In the footer of a view, I have created code that serializes the current view:
global $current_view;
$saved_view = serialize($current_view);
I then save the serialized object in a node. When I retrieve the node, I unserialize the view object:
$retrieved_view = unserialize($saved_view);
If I look at the object(print_r()), it appears to have all the view elements. However, when I try to build the view, I get nothing:
$output = views_build_view('embed', $retrieved_view, array(), false, false);
print $output;
Does the view object need to be initialized as a view object?
The reason I am saving this object is because it contains filters that have been applied by the end user using exposed filters. So, essentially, I'm saving a customized version of the original view (which is why I don't simply use views_get_view to call the original view.
Any suggestions would be appreciated.
Comments
Comment #1
somebodysysop commentedAny help on this? If I execute this code as a footer to a view, it works:
However, this code, placed in a node, does not work. What else do I need to do?:
I compared the views object in both cases -- they are the exact same. But, as I said, in the footer of a view, the views_build_view function works, but in a regular node, it does not -- using the exact same views object.
Can someone please help?
Comment #2
merlinofchaos commentedI'm not ignoring this; however, I don't understand why you're getting the results you do. As far as I can tell, that should basically not happen.
All I can suggest is to trace into views_build_view and see if you can figure out what's going on. Or when I have some time to do so, I can do this, but I warn you it's not as high a priority as a lot of other items right now, so it could be some time before I'm able.
Comment #3
somebodysysop commentedThanks. I understand.
By trace, do you mean use the trace.module? If so, no 5.x version of it is available. If not, what else could I use to trace what's happening in that function?
Again, thanks.
Comment #4
merlinofchaos commentedGenerally I trace either using xdebug (which takes a lot of setup) or by putting dprint statements in the function and seeing what gets printed.
Comment #5
somebodysysop commentedI have devel installed, so I turned on error backtrace. Discovered the problem, but don't know how to fix it.
As I said, the view object is the exact same in the view footer as in the node where I'm trying to extract the view items. Before I call view_build_views, I examine the view object, and it contains the correct filter elements in the array: $unserialized_view->used_filters.
However, when I use the devel module to look at the view array processed by view_build_views, the used_filters array is empty. In fact, that is the only thing different between the view object and what I see in the array returned by view_build_views (using the devel module). Since the view contains an exposed_filter, it goes without saying that that no items are going to appear in the view unless there are used_filters to process.
I tried to troubleshoot this myself, and the only place I see where this problem could potentially occur is here, in views_query.inc, where the used_filters array is specifically blanked out::
Apparently, when my snippet is ran in the view footer, _views_get_filters() gets the used_filters correctly. However, when it is ran in the node, the used_filters are lost, the therefore no view items can be retrieved.
In my mind, it seems like there is some setting in the general environment that is present when code is executed in the footer that is not present when in a node, and the absence of this setting is causing the used_filters to be lost.
Can you give me some suggstions as to how to proceed from here?
Comment #6
sunSorry, this support request is way too specific. Please have a look at the issue queue - Views maintainers are buried already.