diff --git a/tests/behat/features/paragraph.civictheme_automated_list.render.feature b/tests/behat/features/paragraph.civictheme_automated_list.render.feature index cd863ee52..f23177da9 100644 --- a/tests/behat/features/paragraph.civictheme_automated_list.render.feature +++ b/tests/behat/features/paragraph.civictheme_automated_list.render.feature @@ -284,3 +284,57 @@ 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 @testmode + Scenario: Automated list, All filters selected + Given "civictheme_page" content: + | title | created | status | + | [TEST] Page 18 | [relative:-5 days] | 1 | + | [TEST] Page 19 | [relative:-5 days] | 1 | + + And "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 @testmode + Scenario: Automated list, No filters selected + Given "civictheme_page" content: + | title | created | status | + | [TEST] Page 20 | [relative:-5 days] | 1 | + | [TEST] Page 21 | [relative:-5 days] | 1 | + + And "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 @testmode + Scenario: Automated list, Some filters selected + Given "civictheme_page" content: + | title | created | status | + | [TEST] Page 22 | [relative:-5 days] | 1 | + | [TEST] Page 23 | [relative:-5 days] | 1 | + + And "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 e4f931715..27395507c 100644 --- a/web/themes/contrib/civictheme/includes/automated_list.inc +++ b/web/themes/contrib/civictheme/includes/automated_list.inc @@ -194,17 +194,15 @@ function _civictheme_automated_list__update_view(ViewExecutable $view): void { } // Exposed filters. - $exposed_filter = explode(', ', $settings['filters_exp']); - $show_filters = !empty(array_filter($exposed_filter)); + $exposed_filters = explode(', ', $settings['filters_exp']); + $show_filters = count($exposed_filters) > 0; if ($show_filters) { // Disable filters based on the component settings. $view_filters = $view->display_handler->getOption('filters'); - foreach ($view_filters as $key => $filter) { - if (isset($filter['exposed']) && - $filter['exposed'] && - !in_array($filter['expose']['identifier'], $exposed_filter)) { - unset($view_filters[$key]); + foreach ($view_filters as $filter_identifier => $filter) { + if (!empty($filter['exposed']) && !in_array($filter['expose']['identifier'], $exposed_filters)) { + unset($view_filters[$filter_identifier]); } } $view->display_handler->setOption('filters', $view_filters);