query_alter addWhere clause not applied to csv

Created on 29 June 2020, over 4 years ago
Updated 28 December 2024, about 1 month ago

Hi there

Have an issue where my view has a query_alter function attached

All it is doing is adding the addWhere clause, the function fires when the csv is being made but the CSV created does not have the filter applied, only the filters set in the view itself. It's as if the query used to create the CSV is the views setup one, not the altered item.

Example of what is not being applied to the csv (but is added to the query if you output the function)

function xxxx_common_views_query_alter(Drupal\views\ViewExecutable $view, Drupal\views\Plugin\views\query\Sql $query) {

if ($view->id() === 'search' && $view->current_display === 'data_export_1') {
    // Get exposed user input.
    $exposedInput = $view->getExposedInput();

    if ($exposedInput['where_role'] == 'All') {
      $group = count($query->where);
      $query->addWhere($group, 'user__field_travel_preferences_value_0.field_travel_preferences_value', 'Remote', '=');
      $query->addWhere($group, 'user__field_travel_preferences_value_0.field_travel_preferences_value', 'Local', '=');
    }
  }

}
🐛 Bug report
Status

Closed: duplicate

Version

1.0

Component

Code

Created by

🇬🇧United Kingdom gsines

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024