Skip to content

If Drupal cannot be detected, fallback to using Composer to detect the installed path #635

Open
@mglaman

Description

@mglaman

Feature request

Various hacks are needed if drupal/core is in the vendor directory. The drupal-finder package doesn't support this (and probably shouldn't.) But we can in the autoloader: https://github.com/mglaman/phpstan-drupal/blob/main/src/Drupal/DrupalAutoloader.php#L60-L69

        $drupalRoot = $finder->getDrupalRoot();
        $drupalVendorRoot = $finder->getVendorDir();
        if (! (bool) $drupalRoot || ! (bool) $drupalVendorRoot) {
            throw new \RuntimeException("Unable to detect Drupal at {$drupalParams['drupal_root']}");
        }

Instead of throwing a runtime exception here, try using Composer's installed paths to find drupal/core:

\Composer\InstalledVersions::getInstallPath('drupal/core')

Then less hacks are needed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions