Hi Folks,

I'm trying to figure out how to override a private function in the views module without hacking. The function in question is:

function _views_load_view($arg) {}

So I tried creating a custom module (custom.module) that called:

function _custom_load_view($arg) {}

to override. I assigned the modules weight to be -99 in the db but no luck.

Is this the correct procedure or does this only work for themeable functions?

Comments

gpk’s picture

Generally speaking you can't override any old function at whim. For themeable functions - yes you can, and the various hooks provided by core and contrib modules also let you override and customize default behaviors.

I'm not clear why you'd want to override views_load_view() anyway. Perhaps if you explain what you are trying to do someone will be able to advise, though Views 5.x is pretty unloved these days :P

jmunning’s picture

OK thanks, I was wondering about that. Well, what I am trying to do is add a property to the views object. Specifically, I would like the exposed filters to only show the terms that are highlighted in the "Value" column of the "Fields" section of the view. I have accomplished this by hacking the views module to add the field to the object but want to find a better way to do it.

Here is what I am doing now -- adding a new db query and storing the result in an array called 'selected_values':

 $result = db_query("SELECT * FROM {view_exposed_filter} WHERE vid = $view->vid ORDER BY position ASC");

  $view->exposed_filter = array();
  while ($arg = db_fetch_array($result)) {
    $arg['id'] = $arg['field'];
	$argid = $arg['id'];
	$query = "SELECT value FROM {view_filter} WHERE vid = $view->vid AND field = \"$argid\"";
	$newresult = db_query($query);
	//echo ($query);
	$arg['selected_values'] = mysql_fetch_row($newresult);
	//dsm($arg);
	$view->exposed_filter[] = $arg;
  }

What is the Drupal way to add a field/property to the views object for use in template.php?

gpk’s picture

I think this behavior maybe comes out of the box with 6.x (Views 2). You might not be too worried about hacking Views 5.x (Views 1) since I suspect it won't ever be getting any more updates. In 6.x there is probably a Views hook to manipulate the $view object. I have a feeling that in 5.x you can do this via PHP code for default arguments. Have a look at the docs on this site, you should find something. But for the reason above, I'm not sure it's really worth it.