I have some views of display page which I do not want to show to public if there would not be any result when accessed without any exposed filters set. I have a custom views access plugin and a custom access checking class which can handle the access granting.
My idea so far is that I would like to run the view a first time during access checking without exposed filters. In this way I could find out if the view would ever deliver any results. I tried it in the following way:
$view = Views::getView($view_id); $view->setDisplay($display_id); $view->setArguments(($politician_id)); $view->execute(); $result = $view->total_rows;
The problem is: as soon as an user comes to this page with query parameters in the url set by exposed filters these exposed filters are used for this view query as well. I did not find any way to tell the class in $view to execute without exposed filters. I even tried to set these exposed filters data in the following ways but even then the filter data in the query parameters is still used to filter the result set:
$view = Views::getView($view_id); $view->setDisplay($display_id); $view->setArguments(($politician_id)); $view->initDisplay(); $view->initHandlers(); $view->setExposedInput(()); $view->exposed_data = (); $view->exposed_raw_input = (); $view->execute(); $result = $view->total_rows;
I want to achieve that in this way because I want to use this logic for several views. It would be so smart to simply re-use the arguments and filters set in the views instead of hardcoding a new custom database query as the settings in the views might change. I hope someone can help me.