-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkifisearch.module
28 lines (21 loc) · 983 Bytes
/
kifisearch.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?php
use Drupal\Core\Form\FormStateInterface;
function kifisearch_form_search_form_alter(array &$form, FormStateInterface $form_state, $form_id) {
// In order to provide theme suggestions, we need to add the search page ID to theme.
if ($form_id == 'search_form') {
$form['#theme'] = ['search_form__' . $form_state->get('search_page_id')];
// Also set the search page ID somewhere so that we can identify forms in other hooks.
$form['#search_id'] = $form_state->get('search_page_id');
}
}
function kifisearch_theme_suggestions_form_alter(array &$suggestions, array $variables) {
// Provide theme suggestions as the core module does not do this by itself.
$form_id = $variables['element']['#form_id'] ?? null;
if ($form_id == 'search_form') {
$theme = reset($variables['element']['#theme']);
$parts = explode('__', $theme);
foreach ($parts as $i => $part) {
$suggestions[] = implode('__', array_slice($parts, 0, $i + 1));
}
}
}