Philip Norton Explains How to Theme Search API Forms with SVG Buttons in Drupal 11

Drupal 11: Theming The Search API Search Input

Philip Norton, in a recent article published on Hashbangcode, shared a step-by-step method for theming Search API forms in Drupal 11 by replacing the standard input element with a button that supports inline SVG icons.

The tutorial addresses a common theming request: using a magnifying glass icon instead of the default text-based submit button. Since SVGs cannot be injected into input elements, Philip demonstrates how to convert the submit input into a button element using form alter hooks combined with template suggestions.

The process begins with altering the search form using an object-oriented hook_form_alter() to inject attributes such as a custom data-twig-suggestion and ARIA labels for accessibility. Norton highlights the importance of maintaining screen reader compatibility by explicitly setting the aria-label since the visible text is replaced by an icon.

A second hook, theme_suggestions_input_alter(), uses the injected attributes to generate a custom template suggestion. This allows developers to implement a Twig template like input--submit--search-results-submit.html.twig that renders a button with embedded SVG markup.

While the author considered releasing this functionality as a contrib module, he notes the high variability of form structures across Drupal sites. Instead, he advocates for adapting this technique as needed, offering it as a flexible solution for frontend developers seeking control over form UI.

Disclosure: This content is produced with the assistance of AI.

Disclaimer: The opinions expressed in this story do not necessarily represent that of TheDropTimes. We regularly share third-party blog posts that feature Drupal in good faith. TDT recommends Reader's discretion while consuming such content, as the veracity/authenticity of the story depends on the blogger and their motives. 

Note: The vision of this web portal is to help promote news and stories around the Drupal community and promote and celebrate the people and organizations in the community. We strive to create and distribute our content based on these content policy. If you see any omission/variation on this please reach out to us at #thedroptimes channel on Drupal Slack and we will try to address the issue as best we can.

Related Organizations

Related People

Upcoming Events

Latest Opportunities