Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CIVIC-1449] Fixed Automated list filters not being hidden. #1157

Merged
merged 5 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -284,3 +284,42 @@ Feature: Automated list render
And I see field "Title"
And should see an "input[name='title']" element
And should not see an "input[name='title'].required" element

@api
Scenario: Automated list, all filters shown
Given "field_c_n_components" in "civictheme_page" "node" with "title" of "Test page with Automated list content" has "civictheme_automated_list" paragraph:
| field_c_p_title | [TEST] Automated list title |
| field_c_p_list_limit_type | unlimited |
| field_c_p_list_filters_exp | title, topic, type |

When I visit "civictheme_page" "Test page with Automated list content"
Then I should see an ".ct-list__filters" element
And I should see an ".ct-group-filter__filters .ct-form-element--topic" element
And I should see an ".ct-group-filter__filters .ct-form-element--type" element
And I should see an ".ct-group-filter__filters .ct-form-element--title" element

@api
Scenario: Automated list, no filters shown
Given "field_c_n_components" in "civictheme_page" "node" with "title" of "Test page with Automated list content" has "civictheme_automated_list" paragraph:
| field_c_p_title | [TEST] Automated list title |
| field_c_p_list_limit_type | unlimited |
| field_c_p_list_filters_exp | |

When I visit "civictheme_page" "Test page with Automated list content"
Then I should not see an ".ct-list__filters" element
And I should not see an ".ct-group-filter__filters .ct-form-element--topic" element
And I should not see an ".ct-group-filter__filters .ct-form-element--type" element
And I should not see an ".ct-group-filter__filters .ct-form-element--title" element

@api
Scenario: Automated list, some filters shown
Given "field_c_n_components" in "civictheme_page" "node" with "title" of "Test page with Automated list content" has "civictheme_automated_list" paragraph:
| field_c_p_title | [TEST] Automated list title |
| field_c_p_list_limit_type | unlimited |
| field_c_p_list_filters_exp | title, topic |

When I visit "civictheme_page" "Test page with Automated list content"
Then I should see an ".ct-list__filters" element
And I should see an ".ct-group-filter__filters .ct-form-element--topic" element
And I should not see an ".ct-group-filter__filters .ct-form-element--type" element
And I should see an ".ct-group-filter__filters .ct-form-element--title" element
17 changes: 14 additions & 3 deletions web/themes/contrib/civictheme/includes/automated_list.inc
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,20 @@ function _civictheme_automated_list__update_view(ViewExecutable $view): void {
$view->display_handler->setOption('row', $view_mode_options);
}

// @todo Implement hiding of the filters that were not selected.
$show_filters = !empty(array_filter(explode(', ', $settings['filters_exp'])));
if (!$show_filters) {
// Exposed filters.
$exposed_filters = array_filter(explode(', ', $settings['filters_exp'] ?? ''));
$show_filters = !empty($exposed_filters);
if ($show_filters) {
// Disable filters based on the component settings.
$view_filters = $view->display_handler->getOption('filters');
foreach ($view_filters as $view_filter_id => $view_filter) {
if (!empty($view_filter['exposed']) && !in_array($view_filter['expose']['identifier'], $exposed_filters)) {
unset($view_filters[$view_filter_id]);
}
}
$view->display_handler->setOption('filters', $view_filters);
}
else {
$view->display_handler->has_exposed = FALSE;
}

Expand Down
Loading