diff --git a/tests/behat/features/paragraph.civictheme_automated_list.render.feature b/tests/behat/features/paragraph.civictheme_automated_list.render.feature index cd863ee52..45fa78c1c 100644 --- a/tests/behat/features/paragraph.civictheme_automated_list.render.feature +++ b/tests/behat/features/paragraph.civictheme_automated_list.render.feature @@ -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 diff --git a/web/themes/contrib/civictheme/includes/automated_list.inc b/web/themes/contrib/civictheme/includes/automated_list.inc index ad9a1f23a..2363e889b 100644 --- a/web/themes/contrib/civictheme/includes/automated_list.inc +++ b/web/themes/contrib/civictheme/includes/automated_list.inc @@ -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; }