PHPackages                             fenetikm/autoload-drupal - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. fenetikm/autoload-drupal

ActiveComposer-plugin[Utility &amp; Helpers](/categories/utility)

fenetikm/autoload-drupal
========================

Autoload Drupal modules into composer autoloader

1.0.1(8mo ago)8272.6k↓24.7%62MITPHP

Since Apr 2Pushed 8mo ago1 watchersCompare

[ Source](https://github.com/fenetikm/autoload-drupal)[ Packagist](https://packagist.org/packages/fenetikm/autoload-drupal)[ RSS](/packages/fenetikm-autoload-drupal/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (1)Dependencies (2)Versions (5)Used By (2)

Drupal 8 Composer Autoloader
============================

[](#drupal-8-composer-autoloader)

A Composer plugin to add Drupal 8 autoloading of modules to the composer autoloader.

Why?
----

[](#why)

Why would you want this? Doesn't Drupal 8 have its own autoloading mechanism?

There are quite a few handy types of tools (e.g. static analysis, intellisense) that rely on being able to load all classes via the composer autoloader. Unfortunately, as Drupal 8 does its own autoloading at boot time, using these tools at best becomes slow (if you try to boot Drupal on the fly) or at worst becomes impossible (because you are running Drupal inside a VM). Some IDEs (e.g. PHPStorm) get around this by implementing their own discovery mechanism but if you are using an IDE or editor that doesn't do this you are out of luck.

This plugin plugs this gap.

How
---

[](#how)

This plugin is heavily based off of the [Composer Merge Plugin](https://github.com/wikimedia/composer-merge-plugin). Essentially this plugin creates a `composer.json` file in memory including in all the specified modules to an `autoload` section and merges it into the root `composer.json` file, also in memory.

Installation
------------

[](#installation)

### Require the plugin in your `composer.json`

[](#require-the-plugin-in-your-composerjson)

Standard stuff:

```
{
    "require": {
        "fenetikm/autoload-drupal": "1.0.0"
    }
}
```

### Configure modules to autoload

[](#configure-modules-to-autoload)

This plugin is configured via the `extra` section in your `composer.json`. Usually you would want the `app/modules/contrib/`, `app/core/modules/` and the `app/modules/custom/` directories included. As Drupal can be configured in many ways, none of this is assumed and so all must be added in.

You can also constrain which modules are added in from a directory by specifying an array that follows the pattern of `[ "directory_to_include", [ "module1", "module2" ] ]`.

For example:

```
    "extra": {
        "autoload-drupal": {
            "modules": [
              "app/modules/contrib/",
              "app/core/modules/",
              [
                  "app/modules/custom/", [ "my_module" ]
              ]
            ]
        }
    }
```

Here, all modules in `app/modules/contrib/` are added in, all modules in `app/core/modules/` are added in and only the `my_module` module is added in from the `app/modules/custom/` directory.

**NOTE:** only modules with `src` directories will be added in (since they conform to PSR for class autoloading).

### Configure classmap

[](#configure-classmap)

Additionally you may also add in classes that are outside of modules. A typical example is adding in the Drupal testing classes. e.g.

```
    "extra": {
        "autoload-drupal": {
            "modules": [
                "app/modules/contrib/",
                "app/core/modules/",
                "app/modules/custom/",
            ],
            "classmap": [
                "app/core/tests/Drupal/Tests"
            ]
        }
    }
```

This will add in all the classes in that directory such as `UnitTestCase`, `AssertHelperTraitTest` etc.

Rebuild the autoloader
----------------------

[](#rebuild-the-autoloader)

The composer autoloader with the Drupal modules will get generated at install and update. To manually force the refresh of it, do:

```
composer dump-autoload
```

Result
------

[](#result)

If you have set it up successfully you will see something like the following in your `vendor/composer/autoload_psr4.php` file:

```
return array(
  'Drupal\\user\\' => array($baseDir . '/app/core/modules/user/src'),
  'Drupal\\my_module\\' => array($baseDir . '/app/modules/custom/my_module/src'),
  'Drupal\\rad-module\\' => array($baseDir . '/app/modules/contrib/rad-module/src'),
  'Drupal\\entity\\' => array($baseDir . '/app/core/modules/entity/src'),
  );
```

###  Health Score

50

—

FairBetter than 95% of packages

Maintenance59

Moderate activity, may be stable

Popularity42

Moderate usage in the ecosystem

Community18

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 62.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~918 days

Total

4

Last Release

260d ago

Major Versions

0.2 → 1.0.02023-01-23

### Community

Maintainers

![](https://www.gravatar.com/avatar/a4a3a604c54c6fe1ae7626d9168eacb021a17538c16b35ed71b7d58374d5b3b2?d=identicon)[michaelwelford](/maintainers/michaelwelford)

---

Top Contributors

[![fenetikm](https://avatars.githubusercontent.com/u/2375203?v=4)](https://github.com/fenetikm "fenetikm (5 commits)")[![kasperg](https://avatars.githubusercontent.com/u/73966?v=4)](https://github.com/kasperg "kasperg (1 commits)")[![opdavies](https://avatars.githubusercontent.com/u/339813?v=4)](https://github.com/opdavies "opdavies (1 commits)")[![prudloff-insite](https://avatars.githubusercontent.com/u/50333926?v=4)](https://github.com/prudloff-insite "prudloff-insite (1 commits)")

### Embed Badge

![Health badge](/badges/fenetikm-autoload-drupal/health.svg)

```
[![Health](https://phpackages.com/badges/fenetikm-autoload-drupal/health.svg)](https://phpackages.com/packages/fenetikm-autoload-drupal)
```

###  Alternatives

[symfony/runtime

Enables decoupling PHP applications from global state

74798.8M1.0k](/packages/symfony-runtime)[drupal/core-composer-scaffold

A flexible Composer project scaffold builder.

5344.1M564](/packages/drupal-core-composer-scaffold)[drupal/core-project-message

Adds a message after Composer installation.

2124.7M203](/packages/drupal-core-project-message)[brianhenryie/strauss

Prefixes dependencies namespaces so they are unique to your plugin

190438.1k36](/packages/brianhenryie-strauss)[sandersander/composer-link

Adds ability to link local packages for development with composer

98457.9k](/packages/sandersander-composer-link)[phpro/grumphp-shim

GrumPHP Phar distribution

294.7M340](/packages/phpro-grumphp-shim)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
