@@ -162,19 +162,9 @@ function civictheme_preprocess_views_exposed_form(array &$variables): void {
162162 }
163163
164164 if ($ field_count == 1 ) {
165- // Use inline filter on search and auto pages if a single text field exsits.
166- if ($ view instanceof \Drupal \views \ViewExecutable && 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- }
165+ // Use inline filter on search and auto pages if a single text field exists.
166+ if (_civictheme_preprocess_views__exposed_form__inline_filter ($ variables , $ view , $ fields )) {
167+ return ;
178168 }
179169
180170 // Use single filter.
@@ -185,6 +175,44 @@ function civictheme_preprocess_views_exposed_form(array &$variables): void {
185175 }
186176}
187177
178+ /**
179+ * Preprocess views exposed form to convert it to the Inline filter.
180+ *
181+ * @param array $variables
182+ * Variables array.
183+ * @param \Drupal\views\ViewExecutable|null $view
184+ * The view object.
185+ * @param array $fields
186+ * Form fields.
187+ *
188+ * @return bool
189+ * TRUE if inline filter was processed, FALSE otherwise.
190+ */
191+ function _civictheme_preprocess_views__exposed_form__inline_filter (array &$ variables , $ view , array $ fields ): bool {
192+ if (!($ view instanceof \Drupal \views \ViewExecutable)) {
193+ return FALSE ;
194+ }
195+
196+ if (!in_array ($ view ->id (), ['civictheme_search ' , 'civictheme_automated_list ' ])) {
197+ return FALSE ;
198+ }
199+
200+ $ keyword_field = reset ($ fields );
201+ if ($ keyword_field ['#type ' ] !== 'textfield ' ) {
202+ return FALSE ;
203+ }
204+
205+ $ variables ['inline_filter ' ] = TRUE ;
206+ $ keyword_field ['#title_size ' ] = 'extra-large ' ;
207+ $ variables ['filter_items ' ] = $ keyword_field ;
208+ $ submit_field = $ variables ['form ' ]['actions ' ]['submit ' ] ?? NULL ;
209+ if (!empty ($ submit_field )) {
210+ $ variables ['submit_text ' ] = $ submit_field ['#value ' ] ?? '' ;
211+ }
212+
213+ return TRUE ;
214+ }
215+
188216/**
189217 * Preprocess views exposed form to convert it to the Single filter.
190218 */
@@ -282,6 +310,8 @@ function _civictheme_preprocess_views_view__search_page(array &$variables): void
282310
283311/**
284312 * Pre-process results count for views.
313+ *
314+ * @SuppressWarnings(PHPMD.StaticAccess)
285315 */
286316function _civictheme_preprocess_views_view__results_count (array &$ variables ): void {
287317 if (empty ($ variables ['results_count ' ])) {
0 commit comments