Fix multisite extension discovery by scanning all sites/*/ directories#956
Merged
mglaman merged 6 commits intomglaman:mainfrom Apr 8, 2026
Merged
Fix multisite extension discovery by scanning all sites/*/ directories#956mglaman merged 6 commits intomglaman:mainfrom
mglaman merged 6 commits intomglaman:mainfrom
Conversation
Contributor
Author
|
@aweingarten just pinging you here b/c you opened #320 (even though it was 6 years ago). Not sure if you have any thoughts on this one... |
There was a problem hiding this comment.
Pull request overview
Fixes multisite Drupal setups where modules placed under non-default sites/<site>/modules directories were not discovered by ExtensionDiscovery, causing false “module is not found” errors during PHPStan analysis.
Changes:
- Add a multisite fixture module under
tests/fixtures/drupal/sites/acme/modules/acme_module. - Add a new rule test case validating
loadInclude()works for a module located in a non-default site directory. - Update
ExtensionDiscoveryto discover and scan allsites/*directories (excludingsites/allandsites/simpletest) asORIGIN_SITE.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/src/Rules/data/multisite-load-include.php | Adds a PHPStan analysis snippet exercising loadInclude() for a multisite module. |
| tests/src/Rules/LoadIncludesRuleTest.php | Adds a test case asserting no errors for the multisite fixture scenario. |
| tests/fixtures/drupal/sites/acme/modules/acme_module/acme_module.module | Adds a site-specific module fixture entrypoint file. |
| tests/fixtures/drupal/sites/acme/modules/acme_module/acme_module.info.yml | Adds the module metadata for the multisite fixture. |
| tests/fixtures/drupal/sites/acme/modules/acme_module/acme_module.inc | Adds an include file so loadInclude('acme_module', 'inc') can resolve successfully. |
| src/Drupal/ExtensionDiscovery.php | Discovers all site directories under sites/* and scans them as site-specific origins. |
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
mglaman
approved these changes
Apr 8, 2026
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ExtensionDiscovery doesn't scan multisite directories, causing false "module is not found" errors
Fixes #320
Problem
ExtensionDiscoveryhardcodes the site path tosites/default:In a Drupal multisite setup, modules can live under other site-specific directories like
sites/acme/modules/. BecauseExtensionDiscovery::scan()only searchessites/defaultfor theORIGIN_SITEweight, modules in any other site directory are never added to theExtensionMap.This causes the
LoadIncludesrule (andModuleLoadInclude) to report false positives:Steps to reproduce
sites/acme/modules/acme_module/loadInclude():Failing test
❌ Failing test evidence for commit 718ef91
Branch
320adds a test demonstrating this bug. The test places a fixture module undertests/fixtures/drupal/sites/acme/modules/and asserts thatloadInclude()resolves it without errors. It currently fails:Proposed fix
Replace the single
$sitePathproperty with discovery of all site directories undersites/*/. Inscan(), iterate through each discovered site path with theORIGIN_SITEweight, skippingsites/all(already handled) andsites/simpletest(irrelevant).This mirrors what Drupal core's own
ExtensionDiscoverydoes when no specific site path is provided — it scans all site directories.Disclaimer: some contents written with help of AI