Skip to content

Conversation

@febdao
Copy link
Collaborator

@febdao febdao commented Mar 14, 2025

Ticket:

Checklist before requesting a review

  • I have formatted the subject to include ticket number as Issue #123456 by drupal_org_username: Issue title
  • I have added a link to the issue tracker
  • I have provided information in Changed section about WHY something was done if this was not a normal implementation
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added tests that prove my fix is effective or that my feature works
  • I have run new and existing relevant tests locally with my changes, and they passed
  • I have provided screenshots, where applicable

Changed

  1. Implemented selected filters in to views

Screenshots

3510578

Note:

Summary by CodeRabbit

  • New Features
    • Added display of selected filters in Drupal Views, allowing users to see and manage active filters based on current selections.
    • Introduced a "Clear all" link to quickly remove all active filters.
  • Chores
    • Updated the UI kit dependency to use the latest feature branch for enhanced filter display support.

@febdao febdao added the State: Needs review Pull requests needs a review from assigned developers label Mar 14, 2025
@febdao febdao self-assigned this Mar 14, 2025
@febdao febdao changed the title [CIVIC-2105] Selected filters. [#3510578] Selected filters. Mar 14, 2025
@github-actions github-actions bot added State: CONFLICT and removed State: Needs review Pull requests needs a review from assigned developers labels Mar 18, 2025
@richardgaunt richardgaunt added this to the 1.11 milestone Mar 19, 2025
@richardgaunt richardgaunt removed the 1.11 label Mar 19, 2025
@febdao febdao marked this pull request as draft March 20, 2025 02:34
@febdao febdao changed the title [#3510578] Selected filters. Issue #3510578: Group filter: integrate the selected filters feature into automated list Mar 20, 2025
@alan-cole alan-cole force-pushed the feature/CIVIC-2105 branch from 9a6a019 to 44b35d7 Compare May 14, 2025 03:53
@alan-cole alan-cole self-requested a review May 14, 2025 03:59
@alan-cole alan-cole marked this pull request as ready for review May 14, 2025 04:21
@alan-cole alan-cole dismissed their stale review May 14, 2025 04:23

Have implemented some of the fixes I had requested.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Nitpick comments (1)
web/themes/contrib/civictheme/includes/views.inc (1)

306-334: Minor performance tidy-up – avoid repeated request/URL work

Within the loop we invoke \Drupal::request() and getUriForPath() for every item. The path never changes, so compute once:

-foreach ($current_values as $key => $value) {
+$base_url = \Drupal::request()->getUriForPath(\Drupal::request()->getPathInfo());
+foreach ($current_values as $key => $value) {-  'url' => \Drupal::request()->getUriForPath(\Drupal::request()->getPathInfo()) . '?' . http_build_query($new_query_params),
+  'url' => $base_url . ($new_query_params ? '?' . http_build_query($new_query_params) : ''),

A micro-optimisation, but it trims repeated service lookups and string concatenations.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2026f06 and 66dc10c.

⛔ Files ignored due to path filters (1)
  • web/themes/contrib/civictheme/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (2)
  • web/themes/contrib/civictheme/includes/views.inc (4 hunks)
  • web/themes/contrib/civictheme/package.json (1 hunks)
🔇 Additional comments (1)
web/themes/contrib/civictheme/includes/views.inc (1)

26-27: Pre-process function added – double-check template caching

Adding _civictheme_preprocess_views_view__selected_filters() is 👍, but it introduces runtime URL construction with \Drupal::request() on every render.
Confirm that:

  1. The variables added (selected_filters, selected_filters_clear_link) are cache-context aware (e.g. url.query_args).
  2. The view display’s cache metadata is amended accordingly (contexts/tags) so fragment caching does not serve stale filter links.

Comment on lines 290 to 336
function _civictheme_preprocess_views_view__selected_filters_list(ViewExecutable $view): array {
$filter_types = _civictheme_preprocess_views_view__selected_filters_get_filter_types($view);
$query_params = \Drupal::request()->query->all();
$current_values = array_filter($query_params, function ($value) {
return !empty($value);
});

// Prevent other query params from being used in the selected filters.
$permitted_keys = [
'type',
'topic',
'title',
'items_per_page',
];
$selected_filters = [];

foreach ($current_values as $key => $value) {
if (!in_array($key, $permitted_keys)) {
continue;
}
$new_query_params = $query_params;
if (is_string($value)) {
unset($new_query_params[$key]);
$selected_filters[$key] = [
'url' => \Drupal::request()->getUriForPath(\Drupal::request()->getPathInfo()) . '?' . http_build_query($new_query_params),
'text' => _civictheme_preprocess_views_view__selected_filters_list__create_filter_label($key, $value, $filter_types),
];
continue;
}
if (is_array($value)) {
foreach ($value as $value_key => $item) {
if (!empty($item)) {
$temp_query_params = $query_params;
unset($temp_query_params[$key][$value_key]);
if (empty($temp_query_params[$key])) {
unset($temp_query_params[$key]);
}
$selected_filters[$key . '_' . $item . '_' . $value_key] = [
'url' => \Drupal::request()->getUriForPath(\Drupal::request()->getPathInfo()) . '?' . http_build_query($temp_query_params),
'text' => _civictheme_preprocess_views_view__selected_filters_list__create_filter_label($key, $item, $filter_types),
];
}
}
}
}
return $selected_filters;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Undefined-index notices when filter is not exposed

$permitted_keys permits title and items_per_page, yet these keys are not present in $filter_types.
When such parameters are present in the query string, the call to _create_filter_label() triggers:

Notice: Undefined index: title in _civictheme_preprocess_views_view__selected_filters_list__create_filter_label()

Suggested fix:

-      $selected_filters[$key] = [
-        'url' => …,
-        'text' => _civictheme_preprocess_views_view__selected_filters_list__create_filter_label($key, $value, $filter_types),
-      ];
+      if (isset($filter_types[$key])) {
+        $label = _civictheme_preprocess_views_view__selected_filters_list__create_filter_label($key, $value, $filter_types);
+      }
+      else {
+        // Fallback to a generic human-readable label.
+        $label = ucfirst(str_replace('_', ' ', $key)) . ': ' . $value;
+      }
+      $selected_filters[$key] = [
+        'url' => …,
+        'text' => $label,
+      ];

Replicate the same guard inside the array-value branch.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function _civictheme_preprocess_views_view__selected_filters_list(ViewExecutable $view): array {
$filter_types = _civictheme_preprocess_views_view__selected_filters_get_filter_types($view);
$query_params = \Drupal::request()->query->all();
$current_values = array_filter($query_params, function ($value) {
return !empty($value);
});
// Prevent other query params from being used in the selected filters.
$permitted_keys = [
'type',
'topic',
'title',
'items_per_page',
];
$selected_filters = [];
foreach ($current_values as $key => $value) {
if (!in_array($key, $permitted_keys)) {
continue;
}
$new_query_params = $query_params;
if (is_string($value)) {
unset($new_query_params[$key]);
$selected_filters[$key] = [
'url' => \Drupal::request()->getUriForPath(\Drupal::request()->getPathInfo()) . '?' . http_build_query($new_query_params),
'text' => _civictheme_preprocess_views_view__selected_filters_list__create_filter_label($key, $value, $filter_types),
];
continue;
}
if (is_array($value)) {
foreach ($value as $value_key => $item) {
if (!empty($item)) {
$temp_query_params = $query_params;
unset($temp_query_params[$key][$value_key]);
if (empty($temp_query_params[$key])) {
unset($temp_query_params[$key]);
}
$selected_filters[$key . '_' . $item . '_' . $value_key] = [
'url' => \Drupal::request()->getUriForPath(\Drupal::request()->getPathInfo()) . '?' . http_build_query($temp_query_params),
'text' => _civictheme_preprocess_views_view__selected_filters_list__create_filter_label($key, $item, $filter_types),
];
}
}
}
}
return $selected_filters;
}
function _civictheme_preprocess_views_view__selected_filters_list(ViewExecutable $view): array {
$filter_types = _civictheme_preprocess_views_view__selected_filters_get_filter_types($view);
$query_params = \Drupal::request()->query->all();
$current_values = array_filter($query_params, function ($value) {
return !empty($value);
});
// Prevent other query params from being used in the selected filters.
$permitted_keys = [
'type',
'topic',
'title',
'items_per_page',
];
$selected_filters = [];
foreach ($current_values as $key => $value) {
if (!in_array($key, $permitted_keys)) {
continue;
}
$new_query_params = $query_params;
// String-valued filter.
if (is_string($value)) {
unset($new_query_params[$key]);
if (isset($filter_types[$key])) {
$label = _civictheme_preprocess_views_view__selected_filters_list__create_filter_label($key, $value, $filter_types);
}
else {
// Fallback to a generic human-readable label.
$label = ucfirst(str_replace('_', ' ', $key)) . ': ' . $value;
}
$selected_filters[$key] = [
'url' => \Drupal::request()->getUriForPath(\Drupal::request()->getPathInfo()) . '?' . http_build_query($new_query_params),
'text' => $label,
];
continue;
}
// Array-valued filter.
if (is_array($value)) {
foreach ($value as $value_key => $item) {
if (empty($item)) {
continue;
}
$temp_query_params = $query_params;
unset($temp_query_params[$key][$value_key]);
if (empty($temp_query_params[$key])) {
unset($temp_query_params[$key]);
}
if (isset($filter_types[$key])) {
$label = _civictheme_preprocess_views_view__selected_filters_list__create_filter_label($key, $item, $filter_types);
}
else {
// Fallback to a generic human-readable label.
$label = ucfirst(str_replace('_', ' ', $key)) . ': ' . $item;
}
$selected_filters["{$key}_{$item}_{$value_key}"] = [
'url' => \Drupal::request()->getUriForPath(\Drupal::request()->getPathInfo()) . '?' . http_build_query($temp_query_params),
'text' => $label,
];
}
}
}
return $selected_filters;
}

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (3)
web/themes/contrib/civictheme/includes/views.inc (3)

293-295: Consider renaming this function for consistency.

Other functions in this file use the naming pattern civictheme_preprocess_views_view or _civictheme_preprocess_views_view__[feature]. Consider changing this to _civictheme_preprocess_views_view__selected_filters_list for consistency.


296-337: ⚠️ Potential issue

Add error handling for filter keys not in filter_types.

The function processes filter keys but doesn't check if these keys exist in filter_types before passing them to _civictheme_preprocess_views_view__selected_filters_list__create_filter_label(). This will generate undefined index notices when a key is permitted but not present in filter_types.

When handling string values:

-      $selected_filters[$key] = [
-        'url' => \Drupal::request()->getUriForPath(\Drupal::request()->getPathInfo()) . '?' . http_build_query($new_query_params),
-        'text' => _civictheme_preprocess_views_view__selected_filters_list__create_filter_label($key, $value, $filter_types),
-      ];
+      $text = isset($filter_types[$key]) 
+        ? _civictheme_preprocess_views_view__selected_filters_list__create_filter_label($key, $value, $filter_types)
+        : ucfirst(str_replace('_', ' ', $key)) . ': ' . $value;
+      $selected_filters[$key] = [
+        'url' => \Drupal::request()->getUriForPath(\Drupal::request()->getPathInfo()) . '?' . http_build_query($new_query_params),
+        'text' => $text,
+      ];

Apply a similar fix for the array value branch as well.


381-397: 🛠️ Refactor suggestion

Optimize entity loading for performance and add error handling.

The current implementation loads entities individually for each selected filter value, which can be inefficient with multiple selections. Also, there's no guard against missing filter metadata.

function _civictheme_preprocess_views_view__selected_filters_list__create_filter_label(string $key, string|int $value, array $filter_types): string {
+  // Guard against missing filter metadata.
+  if (!isset($filter_types[$key])) {
+    return ucfirst(str_replace('_', ' ', $key)) . ': ' . $value;
+  }

+  static $nodeTypes = [];
+  static $taxonomyTerms = [];
+  $value_label = $value;

  switch ($filter_types[$key]['type']) {
    case 'bundle':
-      $node_type = \Drupal::entityTypeManager()->getStorage('node_type')->load($value);
-      $value_label = $node_type ? $node_type->label() : $value;
+      if (!isset($nodeTypes[$value])) {
+        $nodeTypes[$value] = \Drupal::entityTypeManager()->getStorage('node_type')->load($value);
+      }
+      $value_label = $nodeTypes[$value] ? $nodeTypes[$value]->label() : $value;
      break;

    case 'taxonomy_index_tid':
-      $taxonomy_term = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->load($value);
-      $value_label = $taxonomy_term ? $taxonomy_term->label() : $value;
+      if (!isset($taxonomyTerms[$value])) {
+        $taxonomyTerms[$value] = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->load($value);
+      }
+      $value_label = $taxonomyTerms[$value] ? $taxonomyTerms[$value]->label() : $value;
      break;

    default:
      $value_label = $value;
  }
  return $filter_types[$key]['name'] . ': ' . $value_label;
}

This implementation caches loaded entities in static variables to prevent repeated database queries for the same entities.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 66dc10c and 20a86b9.

📒 Files selected for processing (1)
  • web/themes/contrib/civictheme/includes/views.inc (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: commit
🔇 Additional comments (3)
web/themes/contrib/civictheme/includes/views.inc (3)

26-26: Function integration looks good.

This integrates the new selected filters functionality into the main preprocessing workflow.


351-366: Good implementation of filter types extraction.

This function correctly extracts metadata about exposed filters from the view, providing necessary information for creating human-readable labels.


304-305:

❌ Incorrect review comment

Unexpected behavior with non-filter query parameters.

The code includes title and items_per_page in $permitted_keys but these aren't filter types, leading to potential undefined index errors.

Consider modifying the logic to only process keys that exist in filter_types:

- $permitted_keys = array_keys($filter_types);
+ $permitted_keys = array_merge(['title', 'items_per_page'], array_keys($filter_types));

  foreach ($current_values as $key => $value) {
    if (!in_array($key, $permitted_keys)) {
      continue;
    }
+   // Only process with filter_types for actual filters
+   if (!isset($filter_types[$key])) {
+     // Handle non-filter query params differently or skip
+     continue;
+   }

🏁 Script executed:

#!/bin/bash
# Verify what filter types are actually available
echo "Checking available filter types in views..."
rg -A 5 "getPluginId\(\)" web/themes/contrib/civictheme/includes/

# Check how permitted_keys are being used
echo "Checking how permitted_keys are defined and used..."
rg -A 2 "permitted_keys" web/themes/contrib/civictheme/includes/

Length of output: 2889


🏁 Script executed:

#!/bin/bash
# Locate the definition(s) of $filter_types in views.inc
rg -n '\$filter_types' web/themes/contrib/civictheme/includes/views.inc

# Show the block where $filter_types is built to understand its keys
sed -n '250,350p' web/themes/contrib/civictheme/includes/views.inc

Length of output: 4223


No changes needed: non-filter params are already excluded
The logic uses array_keys($filter_types) for $permitted_keys, so parameters like title and items_per_page (which aren’t in $filter_types) are never processed. There’s no risk of undefined‐index errors and no modifications are required.

Likely an incorrect or invalid review comment.

@civictheme civictheme deleted a comment from coderabbitai bot May 14, 2025
@coderabbitai
Copy link

coderabbitai bot commented May 14, 2025

Walkthrough

This update introduces a preprocessing feature in the CivicTheme Drupal theme to display and manage "selected filters" in Views, based on current URL query parameters. It adds several internal helper functions for extracting, labeling, and generating URLs for selected filters, and updates the UI Kit dependency in the package configuration to a feature branch.

Changes

File(s) Change Summary
web/themes/contrib/civictheme/includes/views.inc Added preprocessing for selected filters in Views, including new helper functions for extracting, labeling, and generating URLs for filters, plus "Clear all" link support.
web/themes/contrib/civictheme/package.json Updated @civictheme/uikit dependency from version tag to a feature branch reference.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant View (Drupal)
    participant Theme Preprocessor
    participant UI

    User->>View (Drupal): Loads a page with exposed filters
    View (Drupal)->>Theme Preprocessor: Renders view with query parameters
    Theme Preprocessor->>Theme Preprocessor: Extracts selected filters from query
    Theme Preprocessor->>Theme Preprocessor: Builds labels and "Clear all" link
    Theme Preprocessor->>UI: Passes selected_filters variable
    UI->>User: Displays selected filters and clear options
Loading

Poem

In the theme where filters play,
Rabbits sort them, clear the way.
With labels neat and links anew,
Each hop reveals a clearer view.
A branch of features, fresh and bright—
CivicTheme leaps to new delight!
🐇✨

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between e82077e and f106a3b.

📒 Files selected for processing (1)
  • web/themes/contrib/civictheme/includes/views.inc (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • web/themes/contrib/civictheme/includes/views.inc
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: commit

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

♻️ Duplicate comments (2)
web/themes/contrib/civictheme/package.json (1)

41-41: Dependency still tracks a moving GitHub branch

Line 41 again points @civictheme/uikit at github:civictheme/uikit#feature/497-Selected-filters.
Because a branch tip moves, CI builds and npm ci on the same commit may resolve different UI Kit code, breaking reproducibility and auditability.

The previous review raised the same concern and suggested pinning to a commit SHA or a released tag; that advice still stands.
Please lock the dependency before merging.

web/themes/contrib/civictheme/includes/views.inc (1)

380-395: 🛠️ Refactor suggestion

N × entity loads – cache or batch-load to avoid DB explosions

_create_filter_label() loads one node type or taxonomy term per selected value.
With many filters this causes multiple database queries and defeats render caching.

-static $nodeTypes = [];
-if (!isset($nodeTypes[$value])) {
-  $nodeTypes[$value] = \Drupal::entityTypeManager()->getStorage('node_type')->load($value);
-}
-$value_label = $nodeTypes[$value] ? $nodeTypes[$value]->label() : $value;
+static $nodeTypes = [];
+if (!isset($nodeTypes)) {
+  $nodeTypes = \Drupal::entityTypeManager()->getStorage('node_type')->loadMultiple();
+}
+$value_label = $nodeTypes[$value]->label() ?? $value;

Apply the same memoisation for taxonomy terms, or pre-load all IDs via loadMultiple(array_unique($values)) in the caller to keep render times predictable.

🧹 Nitpick comments (1)
web/themes/contrib/civictheme/includes/views.inc (1)

257-278: Missing unit / kernel tests for new Selected Filters feature

The preprocessing logic is non-trivial (query parsing, label resolution, URL generation). A failing edge-case could silently break the UI.

Recommend adding at least one Kernel test that:

  1. Builds a view with exposed filters.
  2. Makes a request with multiple query params (string + multi-value array).
  3. Asserts the rendered template contains the expected selected_filters variables and URLs without trailing “?”.

Would you like help scaffolding such a test?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2026f06 and e82077e.

⛔ Files ignored due to path filters (1)
  • web/themes/contrib/civictheme/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (2)
  • web/themes/contrib/civictheme/includes/views.inc (4 hunks)
  • web/themes/contrib/civictheme/package.json (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: commit

Comment on lines +299 to +302
$current_values = array_filter($query_params, function ($value) {
return !empty($value);
});

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

array_filter() drops legitimate “falsy” filter values

array_filter($query_params, fn($v) => !empty($v)) removes numeric 0, string '0', or boolean false, even though these can be valid filter inputs (e.g. a taxonomy term with ID 0 or a boolean flag).
Use a stricter check to keep anything that is not NULL and not an empty string:

-  $current_values = array_filter($query_params, function ($value) {
-    return !empty($value);
-  });
+  $current_values = array_filter(
+    $query_params,
+    fn($v) => !(is_string($v) && $v === '') && $v !== NULL
+  );
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
$current_values = array_filter($query_params, function ($value) {
return !empty($value);
});
$current_values = array_filter(
$query_params,
fn($v) => !(is_string($v) && $v === '') && $v !== NULL
);

@alan-cole alan-cole added State: Needs review Pull requests needs a review from assigned developers and removed State: Tests failing labels May 15, 2025
@github-actions github-actions bot added State: CONFLICT and removed State: Needs review Pull requests needs a review from assigned developers labels May 19, 2025

if (!empty($variables['selected_filters'])) {
$variables['selected_filters_clear_link'] = [
'url' => Url::fromRoute('<current>')->toString(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this does not preserve filters that are not a part of the selected_filters

$value_label = $node_type ? $node_type->label() : $value;
break;

case 'taxonomy_index_tid':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this does not support search-API plugins

default:
$value_label = $value;
}
return $filter_types[$key]['name'] . ': ' . $value_label;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function should return only a label and the formatting of this label should take place outside of this function

// Only process keys for available filters.
$permitted_keys = array_keys($filter_types);
$selected_filters = [];
$base_url = Url::fromRoute('<current>')->toString();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should go into _civictheme_preprocess_views_view__selected_filters_list_create_filter_url() function

@joshua-salsadigital joshua-salsadigital added the State: Needs review Pull requests needs a review from assigned developers label Oct 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies State: Needs review Pull requests needs a review from assigned developers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants