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

merlinofchaos’s picture

Status: Active » Fixed

Because 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.

syoumans’s picture

Thanks 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:

function &views_set_current_view(&$view) {
  static $current_view = NULL;
  if ($view !== NULL) {
    unset($current_view);
    $current_view = &$view;
    unset($GLOBALS['current_view']);
    $GLOBALS['current_view'] = &$view;
  }
  return $current_view;
}

function &views_get_current_view() {
  $dummy = NULL;
  return views_set_current_view($dummy);
}

So, as a grotesque and unsightly workaround, I access $GLOBALS['current_view'] directly and it seems to work for me:

$thisView = $GLOBALS['current_view'];
print my_func($thisView);
jfall’s picture

I'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!

Anonymous’s picture

Status: Fixed » Closed (fixed)

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