IconFinder does not generate url with base_url

Created on 4 February 2025, 5 days ago

Problem/Motivation

Follow up 🐛 ui_icons does not generate url with base_url Active

In case base_url is not / but /something, generated urls from svg library are expected to be /something/modules/.../image.png.
Currently, it's not.

Steps to reproduce

Configure Drupal to work with "subfolder" so base_url is /something where "something" is the string you want.
Add a library like described in examples modules https://gitlab.com/ui-icons/ui-icons-example.
Add an icon to a content
Display the page with icon, looking url generated for this icon, url is /modules/... and not /something/modules/...

Proposed resolution

Current proposed resolution is to wrap the $this->appRoot in IconFinder::processFoundFiles.

Need to be tested and see if it's the best approach.

Remaining tasks

Commit and test. If needed add/update a PHPUnit test.

User interface changes

None.

API changes

None.

Data model changes

None.

🐛 Bug report
Status

Active

Version

11.1 🔥

Component

theme system

Created by

🇫🇷France mogtofu33

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @mogtofu33
  • 🇳🇿New Zealand quietone

    Changes are made on on 11.x (our main development branch) first, and are then back ported as needed according to the Core change policies .

  • 🇫🇷France goz

    In \Drupal\Core\Theme\Icon\IconFinder::processFoundFiles()

            'source' => $this->fileUrlGenerator->generateString(str_replace($this->appRoot, '', $file_absolute_path)),
    

    does not take care of base_path

    Here is a piece of code to check logic.

    <?php
    // Hardcode base path, i want Drupal root with subfolder, so http://domain.tld/dir is my drupal root base path.
    $GLOBALS['base_path'] = '/dir/';
    
    // Check current code, $this->appRoot does not end by /.
    $appRoot = '/var/www/html';
    echo(\Drupal::service('file_url_generator')->generateString(str_replace($appRoot, '', '/var/www/html/core/modules/system/tests/modules/icon_test/icons')));
    // Result is : /core/modules/system/tests/modules/icon_test/icons
    
    echo ("\n");
    
    // Add / to the end of appRoot.
    echo(\Drupal::service('file_url_generator')->generateString(str_replace("{$appRoot}/", '', '/var/www/html/core/modules/system/tests/modules/icon_test/icons')));
    // Result is : /dir/core/modules/system/tests/modules/icon_test/icons
    
    

    We could check first $this->appRoot does not already end by / before adding it.

Production build 0.71.5 2024