Skip to content

Commit

Permalink
CIVIC-1449: Fixed automated list filter issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
Amey Mudras committed Dec 5, 2023
1 parent 3e5c21e commit 407cafc
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 5 additions & 7 deletions web/themes/contrib/civictheme/includes/automated_list.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 407cafc

Please sign in to comment.