@@ -13,6 +13,7 @@ use Drupal\Component\Utility\Html;
1313use Drupal \Core \Cache \Cache ;
1414use Drupal \Core \Form \FormStateInterface ;
1515use Drupal \Core \Template \Attribute ;
16+ use Drupal \views \ViewExecutable ;
1617use Drupal \views \Views ;
1718
1819/**
@@ -162,19 +163,9 @@ function civictheme_preprocess_views_exposed_form(array &$variables): void {
162163 }
163164
164165 if ($ field_count == 1 ) {
165- // Use inline filter on search and auto pages if a single text field exsits.
166- if (in_array ($ view ->id (), ['civictheme_search ' , 'civictheme_automated_list ' ])) {
167- $ keyword_field = reset ($ fields );
168- if ($ keyword_field ['#type ' ] === 'textfield ' ) {
169- $ variables ['inline_filter ' ] = TRUE ;
170- $ keyword_field ['#title_size ' ] = 'extra-large ' ;
171- $ variables ['filter_items ' ] = $ keyword_field ;
172- $ submit_field = $ variables ['form ' ]['actions ' ]['submit ' ] ?? NULL ;
173- if (!empty ($ submit_field )) {
174- $ variables ['submit_text ' ] = $ submit_field ['#value ' ] ?? '' ;
175- }
176- return ;
177- }
166+ // Use inline filter on search and auto pages if a single text field exists.
167+ if (_civictheme_preprocess_views__exposed_form__inline_filter ($ variables , $ view , $ fields )) {
168+ return ;
178169 }
179170
180171 // Use single filter.
@@ -185,6 +176,44 @@ function civictheme_preprocess_views_exposed_form(array &$variables): void {
185176 }
186177}
187178
179+ /**
180+ * Preprocess views exposed form to convert it to the Inline filter.
181+ *
182+ * @param array $variables
183+ * Variables array.
184+ * @param \Drupal\views\ViewExecutable|null $view
185+ * The view object.
186+ * @param array $fields
187+ * Form fields.
188+ *
189+ * @return bool
190+ * TRUE if inline filter was processed, FALSE otherwise.
191+ */
192+ function _civictheme_preprocess_views__exposed_form__inline_filter (array &$ variables , $ view , array $ fields ): bool {
193+ if (!($ view instanceof ViewExecutable)) {
194+ return FALSE ;
195+ }
196+
197+ if (!in_array ($ view ->id (), ['civictheme_search ' , 'civictheme_automated_list ' ])) {
198+ return FALSE ;
199+ }
200+
201+ $ keyword_field = reset ($ fields );
202+ if ($ keyword_field ['#type ' ] !== 'textfield ' ) {
203+ return FALSE ;
204+ }
205+
206+ $ variables ['inline_filter ' ] = TRUE ;
207+ $ keyword_field ['#title_size ' ] = 'extra-large ' ;
208+ $ variables ['filter_items ' ] = $ keyword_field ;
209+ $ submit_field = $ variables ['form ' ]['actions ' ]['submit ' ] ?? NULL ;
210+ if (!empty ($ submit_field )) {
211+ $ variables ['submit_text ' ] = $ submit_field ['#value ' ] ?? '' ;
212+ }
213+
214+ return TRUE ;
215+ }
216+
188217/**
189218 * Preprocess views exposed form to convert it to the Single filter.
190219 */
@@ -282,6 +311,8 @@ function _civictheme_preprocess_views_view__search_page(array &$variables): void
282311
283312/**
284313 * Pre-process results count for views.
314+ *
315+ * @SuppressWarnings(PHPMD.StaticAccess)
285316 */
286317function _civictheme_preprocess_views_view__results_count (array &$ variables ): void {
287318 if (empty ($ variables ['results_count ' ])) {
@@ -294,6 +325,8 @@ function _civictheme_preprocess_views_view__results_count(array &$variables): vo
294325 // Load search fields from theme settings.
295326 $ setting_keyword_fields = civictheme_get_theme_config_manager ()->load ('components.search.keyword_fields ' ) ?? '' ;
296327 if (empty ($ setting_keyword_fields )) {
328+ // Strip the @keywords token because it exists but won't be populated.
329+ $ variables ['results_count ' ] = str_replace ('@keywords ' , '' , $ variables ['results_count ' ]);
297330 return ;
298331 }
299332
0 commit comments