Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I need to pass some data -- just the arguments to the view, actually -- to a function in a custom module from the Empty Text portion of a view. I've tried accessing both $view and $args with and without defining them using global first to no avail. For example I've tried:
global $view;
call_my_func($view);
and
//global $view;
call_my_func($view);
Is it possible to access the $view object or $args from the Empty Text area?
Comments
Comment #1
merlinofchaos CreditAttribution: merlinofchaos commentedBecause you're in the default PHP filter you don't have access to any local variables, so $view won't get you much. But you should be able to do $view = views_get_current_view() to achieve what you want.
Comment #2
syoumans CreditAttribution: syoumans commentedThanks for getting back to me so quickly. views_get_current_view() returns NULL when I call it from the view's Empty Text PHP area. I've pasted the code for this function below and as best as I can tell, when views_set_current_view is called by views_get_current_view, $current_view must be NULL.
From views.module lines 453:467:
So, as a grotesque and unsightly workaround, I access $GLOBALS['current_view'] directly and it seems to work for me:
Comment #3
jfall CreditAttribution: jfall commentedI've got the same issue (I think), but in different circumstances...
I'm trying to override the view block "more link" ala http://drupal.org/node/139703, but with different labels for different views (e.g., "View Calendar", "View Gallery", ... that type of thing).
Because theme_views_more($url) does not take the view as an argument, I'm calling
views_get_current_view()
so that I can switch on the view name. However, it returns NULL. Same issue?For the time being I modified views.module to add $view as a parameter to
theme_views_more($url, $view)
- this is a perfect solution for me, but I understand is not a general patch, since it will break existing code that overrides this function :-( Too bad... maybe in Views2?Again, my sincere thanks for this GREAT module - my whole site is views, views, views! Views are awesome!
Comment #4
Anonymous (not verified) CreditAttribution: Anonymous commentedAutomatically closed -- issue fixed for two weeks with no activity.