Created on 3 April 2025, 7 days ago

Hello everyone.
Maybe someone had this problem. After adding a language in the new Drupal CMS, the language is added to the path.

<span class="pb-project__maintenance-icon"><button class="pb-project__status-icon-btn" title="This project is actively maintained by maintainers."><img src="https://www.example.com/en/modules/contrib/project_browser/images/green-maintained-wrench-icon.svg" class="pb-icon pb-icon--false pb-icon--maintained false" alt="Well maintained"></button></span>

Result in the photo: incorrect display of icons.
When I delete languages, everything is fine.
Question: How can I fix this?

πŸ› Bug report
Status

Needs review

Version

2.0

Component

Contrib changes

Created by

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

Comments & Activities

  • Issue created by @Andrii_500
  • πŸ‡ΊπŸ‡ΈUnited States chrisfromredfin Portland, Maine

    In sveltejs/constants.js, we use "export const FULL_MODULE_PATH = `${BASE_URL}${drupalSettings.project_browser.module_path}`;" and FULL_MODULE_PATH is then used to get the path to the image.

    BASE_URL uses "export const BASE_URL = `${window.location.protocol}//${window.location.host}${drupalSettings.path.baseUrl + drupalSettings.path.pathPrefix}`;"

    ...does drupalSettings.path.pathPrefix include a language prefix?

    Or, does the core moduleHandler do it?
    `'module_path' => $this->moduleHandler->getModule('project_browser')->getPath(),`

    ...I'm pretty sure it's probably drupalSettings.path.pathPrefix, which is meant for the "Drupal is installed in a subfolder" scenario; however, if it's a language prefix, that should NOT be included.

    Does anyone know how core handles this kind of scenario, where it needs a path to the module without the language prefix?

    This will need a test.

  • πŸ‡ΊπŸ‡ΈUnited States tim.plunkett Philadelphia
  • Thank you very much for helping.

  • πŸ‡ͺπŸ‡ΈSpain penyaskito Seville πŸ’ƒ, Spain πŸ‡ͺπŸ‡Έ, UTC+2 πŸ‡ͺπŸ‡Ί

    In this page, using Spanish and no installing on the root, drupalSettings.path contains

    baseUrl	'/'
    pathPrefix	'es/'
    currentPath	'admin/modules/browse/drupalorg_jsonapi'
    currentPathIsAdmin	true
    isFront	false
    currentLanguage	'es'
    

    I'm pretty sure we want

    export const BASE_URL = `${window.location.protocol}//${window.location.host}${drupalSettings.path.baseUrl}`;
    

    because that's the BASE_URL. The prefix might or not be there.

    Usually in core you can use Drupal.url('/admin/content'), and that resolves the proper base url and prefix to use.
    I think we should replace most if not all usage of BASE_URL in the svelte app with that.

    For the issue at hand should be enough to ensure FULL_MODULE_PATH doesn't have the prefix.

  • πŸ‡ͺπŸ‡ΈSpain penyaskito Seville πŸ’ƒ, Spain πŸ‡ͺπŸ‡Έ, UTC+2 πŸ‡ͺπŸ‡Ί
  • @penyaskito opened merge request.
  • πŸ‡ͺπŸ‡ΈSpain penyaskito Seville πŸ’ƒ, Spain πŸ‡ͺπŸ‡Έ, UTC+2 πŸ‡ͺπŸ‡Ί
  • πŸ‡ͺπŸ‡ΈSpain penyaskito Seville πŸ’ƒ, Spain πŸ‡ͺπŸ‡Έ, UTC+2 πŸ‡ͺπŸ‡Ί

    Tests are green. Phpstan issues are not introduced here.

  • πŸ‡ΊπŸ‡ΈUnited States chrisfromredfin Portland, Maine

    This does fix the problem so I'm going to merge it now. But I think if we can rely on native Drupal api's like Drupal.url() we need to do that, so I'll open that as a follow-up.

  • πŸ‡ͺπŸ‡ΈSpain penyaskito Seville πŸ’ƒ, Spain πŸ‡ͺπŸ‡Έ, UTC+2 πŸ‡ͺπŸ‡Ί

    I already did and have something in progress :-)

    πŸ“Œ Delete BASE_URL constant Active

Production build 0.71.5 2024