0

In which hook_ of the views.api can i hide the results if no exposed inputfilter is selected.

I tried:

hook_views_query_alter($view, $query) {

if($view->getExposedInput() ...) {
 // Do not show any results, make clear no results should be shown..
}

Or

hook_views_pre_render($view) {
    if($view->getExposedInput() ...) {
      $view->result = array();
      // But pager still shown and $view->getPager()->destroy() gives error.
      // Also feels wrong, query should not be executed.
    }
}

Any suggestions, solutions, .... Thx!

1

Solved it by adding condition which yields no result.

hook_views_query_alter($view, $query) {
    // Don't show any result if exposed filter empty.
    $exposed_input = $view->getExposedInput();
    if(!isset($exposed_input['field_partner_address_country_code']) || $exposed_input['field_partner_address_country_code'] == 'All') {
      $query->addWhere(NULL, 'node_field_data.nid', 0);
    }
}
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.