Skip to content

Commit

Permalink
[CIVIC-1449] Fixed Automated list filters not being hidden. (#1157)
Browse files Browse the repository at this point in the history
  • Loading branch information
mudrasamey authored Dec 7, 2023
1 parent e919da5 commit a1b968c
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
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

0 comments on commit a1b968c

Please sign in to comment.