Open donquixote opened 1 year ago
Superficially this could be fixed by adding ?? NULL
after the ['name']
like this:
'name' => $element['#attributes']['name'] ?? NULL,
However, the real solution is to not use the text-input from ecl-twig at all for the toolbar search field.
So, to skip entirely the input--search.html.twig
from oe_theme.
we can do this:
diff --git a/oe_theme.theme b/oe_theme.theme
index e803089a6..a32b03066 100644
--- a/oe_theme.theme
+++ b/oe_theme.theme
@@ -155,6 +155,14 @@ function oe_theme_theme_suggestions_input_alter(array &$suggestions, array $vari
if ($element['#type'] === 'date' && $element['#attributes']['type'] === 'time') {
$suggestions[] = 'input__time';
}
+
+ if (isset($element['#id']) && $element['#id'] === 'admin-toolbar-search-input') {
+ // Don't use the `input--search.html.twig` because it does not work here.
+ $suggestions = array_diff($suggestions, ['input__search']);
+ // Add the base theme hook as a suggestion.
+ // Don't remove other suggestions that might be added by modules.
+ array_unshift($suggestions, 'input');
+ }
}
/**
But now I see another problem: The search field has margin top and bottom which looks wrong in the admin toolbar.
Background
Admin Toolbar has an optional search field in the admin menu. This is themed using the front-end theme, if visible on front-end pages.
I think most projects do not have admin_toolbar installed, but some developers might install it locally, or some projects might choose to use it.
oe_theme has a preprocess function and a template for 'input__search' theme hook variant. The preprocess function targets all search fields without distinction, including the one from admin_toolbar_search.
Problem
The preprocess function and the template are incompatible with the search field in admin toolbar, causing a notice.
Steps to reproduce
Install oe_theme as default theme, and install admin_toolbar and admin_toolbar_search. Enable error logging and/or reporting to the page.
Visit any front-end page as user with access to the toolbar. If you don't see the notice yet, clear the cache and try again.
Technical info, backtrace