This project is not covered by Drupal’s security advisory policy.
⇧ …And the idea also is pretty insane and silly anyway…
A PoC module which aim to "replace" PHP classes you define in your module's info.yml file.
Usage
- Add a new key
class_replacementsto the.info.ymlof the module which contains the replacement modules:
name: Migration Manager Replacement type: module class_replacements: # Key: the qualified name of the class which should be replaced. # Value: location of the replacement file, relative to the actual module's root. Drupal\migrate\Plugin\MigrationPluginManager: src/migrate/MigrationPluginManager.php Drupal\migrate_drupal\MigrationPluginManager: src/migrate_d/MigrationPluginManager.php - Make sure that the module depends on
crema; or have a good reason not doing so 🙃 - Create the replacement file at the declared location:
- Its namespace must be the namespace of the original file with the leading
Drupalreplaced byCrema. - The class name must be the same as the replaced class name.
- If you want to extend the original class (I'm pretty sure you want to), then you can do it by adding the proper (aliased) use declaration of the original class.
# File content of <module_root>/src/migrate/MigrationPluginManager.php <?php namespace Crema\migrate\Plugin; use Drupal\migrate\Plugin\MigrationPluginManager as Original; /** * Replaces the default migration plugin manager. */ class MigrationPluginManager extends Original { protected $defaults = [ 'class' => '\Drupal\my_module\Plugin\BetterMigration', ]; public function foo(): string { return 'foo'; } } - Its namespace must be the namespace of the original file with the leading
Limitations
- You cannot replace the same PHP class (or trait or interface) more than once.
- Due to the way how Crema works, you cannot use debugger breakpoint neither in the replacement nor in the replaced
phpfile. - The module only can replace files with
Drupal\*namespace, and not all of them, but most of them. For example you cannot replace Drupal kernels, database driver classes etc. - Crema uses PHP's temporary stream to store the replaced and the replacement files before it loads them. Because of this, (for now) the files must me smaller than 2MB: https://www.php.net/manual/en/wrappers.php.php#wrappers.php.memory
Project information
Minimally maintained
Maintainers monitor issues, but fast responses are not guaranteed.- Project categories: Developer tools
- Created by huzooka on , updated
This project is not covered by the security advisory policy.
Use at your own risk! It may have publicly disclosed vulnerabilities.
Releases
1.0.0-alpha4
released 4 December 2025
Works with Drupal: ^9 || ^10
Install:
Development version: 1.0.x-dev updated 6 Jan 2026 at 12:03 UTC
