Skip to content

feat: add drupal to RectorConfigBuilder::withComposerBased#8041

Merged
TomasVotruba merged 2 commits into
rectorphp:mainfrom
bbrala:feat/composer-based-drupal-set
Jun 17, 2026
Merged

feat: add drupal to RectorConfigBuilder::withComposerBased#8041
TomasVotruba merged 2 commits into
rectorphp:mainfrom
bbrala:feat/composer-based-drupal-set

Conversation

@bbrala

@bbrala bbrala commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

What

Adds a drupal toggle to withComposerBased() and the matching SetGroup::DRUPAL constant, so a Drupal SetProviderInterface can expose composer-triggered sets keyed on drupal/core:

return RectorConfig::configure()
    ->withSetProviders(\DrupalRector\Set\DrupalSetProvider::class)
    ->withComposerBased(drupal: true);

This mirrors the existing ecosystem toggles (twig, symfony, laravel, …) exactly — one extra parameter wired into the same $setMap, plus the group constant. The set provider itself lives in the external palantirnet/drupal-rector package, same as laravel's provider lives in rector-laravel.

Why

Companion to palantirnet/drupal-rector#370, which ships DrupalSetProvider exposing the per-minor Drupal deprecation/breaking configs as ComposerTriggeredSets in the drupal group. Those sets stay dormant until core exposes the drupal: toggle to opt into the group — this PR is that toggle. And ofcourse the original rectorphp/rector#9778

Verification

  • tests/Set/SetManager/SetManagerTest.php green.
  • Confirmed withComposerBased(drupal: true) registers the drupal set group.

@bbrala bbrala marked this pull request as draft June 17, 2026 12:46
@bbrala

bbrala commented Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

Seems straightforward enough. Merged into dev main for drupal-rector.

@bbrala bbrala marked this pull request as ready for review June 17, 2026 12:57
@TomasVotruba

Copy link
Copy Markdown
Member

Looks good, let's give this a go 👍

@TomasVotruba TomasVotruba merged commit 2b27a74 into rectorphp:main Jun 17, 2026
65 checks passed
@bbrala

bbrala commented Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

Clean Drupal 11.3 install with ddev.

With some composer magic.

    "require-dev": {
        "palantirnet/drupal-rector": "dev-main",
        "rector/rector": "dev-main as 2.4.0"
    }

And then a debug run :)

bjorn@drupal-11-web:/var/www/html$ cat rector.php 
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;

return RectorConfig::configure()
  ->withSetProviders(\DrupalRector\Set\DrupalSetProvider::class)
  ->withComposerBased(drupal: true)
  ->withFileExtensions(['php', 'module', 'theme', 'install', 'profile', 'inc', 'engine'])
  ->withImportNames(true, false);


bjorn@drupal-11-web:/var/www/html$ vendor/bin/rector web --dry-run --debug --rules-summary
[info] Sets loaded based on installed packages:
 * /var/www/html/vendor/palantirnet/drupal-rector/config/drupal-11/drupal-11.0-deprecations.php
 * /var/www/html/vendor/palantirnet/drupal-rector/config/drupal-11/drupal-11.1-deprecations.php
 * /var/www/html/vendor/palantirnet/drupal-rector/config/drupal-11/drupal-11.2-deprecations.php
 * /var/www/html/vendor/palantirnet/drupal-rector/config/drupal-11/drupal-11.3-deprecations.php
 * /var/www/html/vendor/palantirnet/drupal-rector/config/drupal-11/drupal-11.1-breaking.php
 * /var/www/html/vendor/palantirnet/drupal-rector/config/drupal-11/drupal-11.2-breaking.php
 * /var/www/html/vendor/palantirnet/drupal-rector/config/drupal-11/drupal-11.3-breaking.php
 * /var/www/html/vendor/palantirnet/drupal-rector/config/drupal-bootstrap.php

[file] /var/www/html/web/autoload.php
[file] /var/www/html/web/core/assets/scaffold/files/default.settings.php
[file] /var/www/html/web/core/assets/scaffold/files/example.settings.local.php
[file] /var/www/html/web/core/assets/scaffold/files/example.sites.php
[file] /var/www/html/web/core/assets/scaffold/files/ht.router.php
[file] /var/www/html/web/core/assets/scaffold/files/index.php
[file] /var/www/html/web/core/assets/scaffold/files/update.php
[file] /var/www/html/web/core/authorize.php
[file] /var/www/html/web/core/core.api.php

That sounds pretty good. :)

@TomasVotruba

Copy link
Copy Markdown
Member

Very nice work! :) Time to try on real projects, if all rules are applied

@bbrala

bbrala commented Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

I'll try later on some of our client projects.

@bbrala

bbrala commented Jun 18, 2026

Copy link
Copy Markdown
Contributor Author

It applies all gucci, tried a few project and got applied rectors. I cant really test all :P But the sets were selected correctly and rectors were applies from the set.

I did notice a small oversight. Originally for normal projects we added:

->singleton(DrupalRectorSettings::class, fn() => (new DrupalRectorSettings())->disableBackwardCompatibility());

And this also makes sense when you use the composer based set. You do not need to support multiple Drupal versions there. This only really makes sense for Drupal modules (packages).

This needs disabling, so this needs to be added to the drupal-bootstrap.php..

palantirnet/drupal-rector#373

@bbrala

bbrala commented Jun 19, 2026

Copy link
Copy Markdown
Contributor Author

I'll move to putting any comments in the issue in rector itself (rectorphp/rector#9778)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants