Created
May 10, 2022 11:04
-
-
Save bserem/a3c13e2efa07cf0492c0c2a55c29959c to your computer and use it in GitHub Desktop.
Conditional no results text based on exposed filter values (bypass drupal core bug related to https://www.drupal.org/project/drupal/issues/3024467)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Implements hook_views_pre_execute(). | |
*/ | |
function HOOK_views_pre_execute(ViewExecutable $view) { | |
if (empty($view->exposed_raw_input['title']) && ($view->query->getPluginId() === "search_api_query")) { | |
$view->query->abort(); | |
} | |
} | |
/** | |
* Implements hook_views_pre_render(). | |
*/ | |
function HOOK_views_pre_render(ViewExecutable $view) { | |
if (empty($view->exposed_raw_input['title']) && ($view->query->getPluginId() === "search_api_query")) { | |
$view->attachment_after = array('#markup' => t('Select any filter and click on Apply to see results')); | |
} | |
else if (empty($view->result)) { | |
$view->attachment_after = array('#markup' => t('Your search has no results')); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment