Skip to content

Instantly share code, notes, and snippets.

@rafinskipg
Created November 5, 2012 11:51
Show Gist options
  • Save rafinskipg/4016842 to your computer and use it in GitHub Desktop.
Save rafinskipg/4016842 to your computer and use it in GitHub Desktop.
Look if a view has exposed filters
$name = 'my_view';
$display = 'page_1';
$exposed = array('title', 'type', 'created');
public function hasExposed($name, $display, $exposed){
$view = views_get_view($name);
$view->set_display($display);
$view->preview=TRUE;
$view->is_cacheable = FALSE;
//Si no están sobreescritos tiramos contra los default
if($view->display_handler->options['defaults']['filters'] == true){
$filters = $view->display_handler->get_option('filters');
}else{
//Si están sobreescritos miramos contra los del display //CREO QUE CON LA OPCION DE ARRIBA SIRVE
$filters = $view->display[$display]->display_options['filters'];
}
$exposed_actuales = array();
foreach($filters as $key => $filter){
if(isset($filter['exposed'])){
if($filter['exposed'] == TRUE){
$exposed_actuales[] = $key;
}
}
}
//OBtenemos los sort exposed:
if($view->display_handler->options['defaults']['sorts'] == true){
$sorts = $view->display_handler->get_option('sorts');
}else{
//Si están sobreescritos miramos contra los del display //CREO QUE CON LA OPCION DE ARRIBA SIRVE
$sorts = $view->display[$display]->display_options['sorts'];
}
foreach($sorts as $key => $sort){
if(isset($sort['exposed'])){
if($sort['exposed'] == TRUE){
$exposed_actuales[] = $key;
}
}
}
if(isset($exposed)){
foreach($exposed as $key){
if(!in_array($key, $exposed_actuales)){
debug('Filtro '. $key .' no presente en la vista');
return false;
}
debug('Todos los filtros están en la vista');
}
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment