Library Discovery Parser should not automatically resort to 'theme'

Created on 17 June 2024, 14 days ago

Problem/Motivation

While working on a different issue for a module that requires to know whether a given library exists via the Library Discovery Service, I stumbled upon this piece of code in the buildByExtension() function of LibraryDiscoveryParser.php:

if ($extension === 'core') {
      $path = 'core';
      $extension_type = 'core';
    }
    else {
      if ($this->moduleHandler->moduleExists($extension)) {
        $extension_type = 'module';
      }
      else {
        $extension_type = 'theme';
      }
      $path = $this->extensionPathResolver->getPath($extension_type, $extension);
    }

I don't think that the extension should just default to 'theme' if the extension is not 'core' and the module does not exist as this throws lots of User warning: The following theme is missing from the file system: errors that a custom module should not have to work its way around when simply trying to search for libraries and not for themes.

Steps to reproduce

Use the getLibraryByName() function of the Library Discovery service with a library extension that is invalid, and instead of getting the false that we hoped for, receive theme-related errors.

Proposed resolution

The best way to solve this in my opinion would just be to have a check whether the theme exists and if it does not, return false should be the last resort instead of defaulting to theme search and throwing errors. This would work since the function returns false anyway if the given library is not found, e.g. in core.
Otherwise, #2231385: Verify that the library files exist β†’ looks like a promising step towards a clean solution, so we could integrate the isLibraryValid() function from that later?

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

πŸ› Bug report
Status

Active

Version

11.0 πŸ”₯

Component
Asset libraryΒ  β†’

Last updated 3 days ago

No maintainer
Created by

πŸ‡©πŸ‡ͺGermany LRWebks Porta Westfalica

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

Comments & Activities

Production build 0.69.0 2024