Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
Commit ce61ec92 authored by Andreas Hennings's avatar Andreas Hennings Committed by escuriola
Browse files

OEL-1367: Set theme hook suggestions directly in the form builder class.

parent 6480a134
No related branches found
No related tags found
2 merge requests!157OEL-1668: Update epic list pages.,!136OEL-1367: New Look & Feel for search form in search page and remove theming from block config form.
......@@ -49,43 +49,3 @@ function oe_whitelabel_search_preprocess_facets_summary_item_list(array &$variab
}
$variables['items'] = $items;
}
/**
* Implements hook_theme_suggestions_HOOK_alter().
*
* Add suggestions based on the block region where the form is placed.
*/
function oe_whitelabel_search_theme_suggestions_form_alter(array &$suggestions, array $variables): void {
if (!isset($variables['element']['#form_id']) || $variables['element']['#form_id'] !== 'oe_whitelabel_search_form') {
return;
}
$suggestions[] = 'form__' . $variables['element']['#region'];
$suggestions[] = 'form__' . $variables['element']['#region'] . '__' . $variables['element']['#form_id'];
}
/**
* Implements hook_theme_suggestions_HOOK_alter().
*
* Specify a suggestion for the form_element based on the form id.
*/
function oe_whitelabel_search_theme_suggestions_form_element_alter(array &$suggestions, array $variables): void {
if (!isset($variables['element']['#form_id']) || $variables['element']['#form_id'] !== 'oe_whitelabel_search_form') {
return;
}
$suggestions[] = 'form_element__' . $variables['element']['#form_id'];
}
/**
* Implements hook_theme_suggestions_HOOK_alter().
*
* Add region suggestions for the oe_whitelabel_search_form input field.
*/
function oe_whitelabel_search_theme_suggestions_input_alter(array &$suggestions, array $variables): void {
if (!isset($variables['element']['#form_id']) || $variables['element']['#form_id'] !== 'oe_whitelabel_search_form') {
return;
}
$suggestions[] = $variables['theme_hook_original'] . '__' . $variables['element']['#region'];
$suggestions[] = $variables['theme_hook_original'] . '__' . $variables['element']['#region'] . '__' . $variables['element']['#form_id'];
}
......@@ -51,15 +51,18 @@ class SearchForm extends FormBase {
$form_state->set('oe_whitelabel_search_config', $config);
$form['#region'] = $config['form']['region'];
$theme_hook_suffix = $config['form']['region'] . '__' . $this->getFormId();
$form['#theme_wrappers'] = ['form__' . $theme_hook_suffix];
$form['search_input'] = [
/* @see \Drupal\Core\Render\Element\Textfield */
'#type' => 'textfield',
'#theme' => 'input__textfield__' . $theme_hook_suffix,
'#theme_wrappers' => ['form_element__' . $this->getFormId()],
'#title' => $config['input']['label'],
'#title_display' => 'invisible',
'#size' => 20,
'#form_id' => $this->getFormId(),
'#region' => $config['form']['region'],
'#default_value' => $this->getRequest()->get($config['input']['name']),
'#required' => TRUE,
'#attributes' => [
......@@ -68,9 +71,9 @@ class SearchForm extends FormBase {
];
$form['submit'] = [
/* @see \Drupal\Core\Render\Element\Submit */
'#type' => 'submit',
'#form_id' => $this->getFormId(),
'#region' => $config['form']['region'],
'#theme_wrappers' => ['input__submit__' . $theme_hook_suffix],
'#value' => $config['button']['label'],
];
......@@ -78,6 +81,7 @@ class SearchForm extends FormBase {
return $form;
}
/* @see \Drupal\search_api_autocomplete\Element\SearchApiAutocomplete */
$form['search_input']['#type'] = 'search_api_autocomplete';
// The view id.
$form['search_input']['#search_id'] = $config['view_options']['id'];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment