Untitled
unknown
plain_text
2 years ago
1.2 kB
10
Indexable
use Drupal\views\Plugin\views\query\QueryPluginBase;
use Drupal\views\ViewExecutable;
/**
* Implements hook_views_query_alter().
*/
function your_module_name_views_query_alter(ViewExecutable $view, QueryPluginBase $query) {
if ($view->id() == 'your_view_id') {
// Get the user-selected values for the Country and City filters.
$country_filter = $view->exposed_raw_input['country_filter'];
$city_filter = $view->exposed_raw_input['city_filter'];
// Create separate conditions for Country and City.
$country_condition = $query->addWhereExpression(0, "node__field_venue_of_mission.field_venue_of_mission_value LIKE :country_filter ESCAPE '\\\\'", [':country_filter' => "%$country_filter%"]);
$city_condition = $query->addWhereExpression(0, "node__field_city.field_city_value LIKE :city_filter ESCAPE '\\\\'", [':city_filter' => "%$city_filter%"]);
// Create an OR condition group for the separate conditions.
$or_group = $query->orConditionGroup();
$or_group->addCondition($country_condition);
$or_group->addCondition($city_condition);
// Add the OR condition group to the query.
$query->addWhereGroup($or_group, 'OR');
}
}
Editor is loading...