Problem/Motivation
The current implementation of the EU ECL Icon component, as defined in the eu_europa_component_lib.icons.yml and icons component, works in Drupal 11, but is unreliable in Drupal 10, especially in contexts like Layout Builder, where the icon function may not be available, resulting in rendering failures.
Proposed resolution
To resolve this, I propose embedding the icon rendering logic directly into the component’s Twig template. This approach makes the component self-contained and more robust across different Drupal environments.
Implementation Plan
- 1. Create a Twig extension to define a custom function (e.g.,
get_sprite_path()) that dynamically retrieves the SVG sprite path using Drupal’s module path services. - 2. Modify the icon component’s Twig template to directly incorporate the rendering logic, using the new
get_sprite_path()function for the<use>element’shrefattribute. - Eliminate the
iconFunction Dependency: Refactor the component to remove calls to the icon function, ensuring all logic is handled within the template itself. - The Twig extension must be registered in the module’s services configuration to ensure proper loading.
API changes
The get_sprite_path() function should leverage Drupal’s APIs (e.g., Drupal::service('extension.list.module')) to construct the sprite path dynamically.
Comments
Comment #2
raluelrusuComment #11
raluelrusuComment #12
raluelrusu